Questions? Feedback? powered by Olark live chat software

Elastic Memcached

Hazelcast has been used in production as an alternative to Memcached as well as a plug-in enhancement.

If you’re already using Memcached, you can write a Hazelcast cluster by simply using our Memcached client using any language. No additional configuration is required. Here is an example:

Let’s say your cluster’s members are:

    Members [5] {
    Member []
    Member []
    Member []
    Member []
    Member []

And you have a PHP application that uses PHP Memcache client to cache things in Hazelcast. All you need to do is have your PHP memcache client connect to one of these members. It doesn’t matter which member the client connects to because Hazelcast a cluster looks like one giant machine (Single System Image). PHP client code sample:

    <?php $memcache = new Memcache;
    $memcache->connect('', 5701) or die ("Could not connect");
    $get_result = $memcache->get('key1'); //retrieve your data
    var_dump($get_result); //show it

Notice that memcache client is connecting to and using port5701. Java client code sample with SpyMemcached client:

MemcachedClient client = new MemcachedClient(AddrUtil.getAddresses(""));
client.set("key1", 3600, "value1");

An entry written with a memcache client can be read by another memcache client written in another language.

You may also elect to use Hazelcast instead of Memcached, some advantages of doing so include:

  • Elastic Clustering: Add 5 more nodes without touching your clients at all!
  • Elastic Clustering: Increase or decrease cluster capacity on demand.
  • Embeddable with your Application Tier. You don’t have to run separate cache servers and remotely connect to them.
  • Flexibility for developers: Write smarter apps by using listeners, locks and more. Hazelcast APIs are very similar to JDK’s, which makes it easier for developers to easily understand the technology and develop robust and scalable applications with minimal code changes and development efforts.
  • More than just cache: Hazelcast is a complete IMDG solution that, along with distributed caching, provides features for In-Memory Distributed Computing and Messaging also. Hazelcast provides ueue, Topic, Distributed ExecutorService, EntryProcessor, Distributed RingBuffer, ReliableTopic, In-Memory Map/Reduce etc.
  • All in-one: Easier to maintain.
  • Backups: Memcached has only one copy of each object at one node whereas Hazelcast allows you to have a maximum of 6 copies for each entry. Also, replication in a Memcache cluster relies on using external libraries and deployment for replication (Repcached).
  • Easy Configuration: In Hazelcast, no need to explicitly configure IPs of all the server nodes and maintain order of configuring IPs in all configurations on all nodes.
  • Smart Clients: Client nodes (application nodes) connect with all the server members to send/receive requests/response as opposed to Memcache where all the requests from a client are routed through a particular server member. This makes server member a bottleneck in cases of large concurrent transactions.
  • Reliable HA: Data is never lost in a Hazelcast cluster, whether a node leaves or joins the cluster or the cluster runs into Split Brain. A Memcache cluster is likely to lose data when a node leaves the cluster for a short while and come back in (all the updates are lost during this time).
  • Easy Deploy: Java only product in one single jar. Simply drop it in. No installation, no fuss. Its for a Java-only project we need this.

We don’t want you to get the wrong impression, we think Memcached is a good product. We feel that it’s possible for you to extend your use of Memcached and possibly go further with Hazelcast. Don’t just take our word for it, try it out for yourself.