Support of Memcached for Java

CAST supports Memcached via its com.castsoftware.nosqljava extension. Details about the support provided for Java source code is discussed below.

Supported Libraries

Library Version Supported
spymemcached Up to: 2.7.1 (tick)

Supported Operations

Operations Method Supported
Insert

net.spy.memcached.MemcachedClient.set

net.spy.memcached.MemcachedClient.add

Update

net.spy.memcached.MemcachedClient.incr

net.spy.memcached.MemcachedClient.asyncIncr

net.spy.memcached.MemcachedClient.decr

net.spy.memcached.MemcachedClient.asyncDecr

net.spy.memcached.MemcachedClient.replace

net.spy.memcached.MemcachedClient.append

net.spy.memcached.MemcachedClient.prepend 

net.spy.memcached.MemcachedClient.getAndLock

net.spy.memcached.MemcachedClient.getAndTouch

net.spy.memcached.MemcachedClient.asyncGetAndTouch

net.spy.memcached.MemcachedClient.asyncGetAndLock

Select

net.spy.memcached.MemcachedClient.get

net.spy.memcached.MemcachedClient.asyncGet

net.spy.memcached.MemcachedClient.getBulk

net.spy.memcached.MemcachedClient.asyncGetBulk

Delete

net.spy.memcached.MemcachedClient.delete

Objects

Icon Description

Java Memcached Connection

Java Memcached Data

Java Unknown Memcached Connection

Java Unknown Memcached Data

Links are created for transaction and function point needs:

Link type Source and destination of link  Methods Supported
belongsTo From Memcached data object to Memcached connection object -
useInsertLink Between the java Method objects and Memcached data object

Insert

useUpdateLink Between the java Method objects and Memcached data object

Increment

Decrement

Append

Prepend 

CAS

asyncCAS

getAndLock

getAndTouch

asyncGetAndTouch

asyncGetAndLock

useSelectLink Between the java Method objects and Memcached data object

Get

GetAsync

getBulk

asyncGetBulk

CAS

asyncCAS

getAndLock

getAndTouch

asyncGetAndTouch

asyncGetAndLock

useDeleteLink Between the java Method objects and Memcached data object

Remove

What results can you expect?

Some example scenarios are shown below:

Memcached Connection

IP address

In the Memcached class file, when we add the server information by parsing the IP address and provide the port Number:

public class Connection {
    
    public static void main(String[] args) throws IOException {
         

          MemcachedClient mcc = new MemcachedClient(new InetSocketAddress("127.0.0.1", 11211));
          
    }
}

Hostname

In the Memcached class file, when we add the set of server information by parsing the server address and provide the port Number over the binary connection protocol:

public class Connection {
    
    public static void main(String[] args) throws IOException {

            MemcachedClient mcc1 = new MemcachedClient(new BinaryConnectionFactory(), AddrUtil.getAddresses
                                ("server1"));
    }
}

Unknown Connection Object

In the Memcached class file, when we pass the server information as a parameter but if passed parameter are unresolved:

  public class Connection {
    
        public static void main(String[] args) throws IOException {

            InetSocketAddress inet2 = new InetSocketAddress(Connection1.var, 11211);
  
             MemcachedClient mcc = new MemcachedClient(inet2);
        }
}

Insert Operation

set command

mcc.set("tp", 900, "memcached").isDone()

add command

mcc.add("data3", 900, "redis").isDone()

Select Operation

get command

mcc.get("data2")

asyncGet command

mcc.asyncGet("data2")

getBulk and asyncGetBulk command

m = mcc1.getBulk(keySet);
vals = mcc1.asyncGetBulk(keySet);

Delete Operation

delete command

mcc.delete("data1").isDone()

Update Operation

replace command

mcc.replace("tp", 900, "redis").isDone()

append and prepend commands

mcc.append(900, "tp", "redis").isDone();
mcc.prepend(900, "tp", "redis").isDone();

Increment command

// incrementing the numeric value of existing key   
mcc.incr("tp", 2));
mcc.asyncIncr("tp", 2);

Decrement command

//decrementing the numeric value of existing key 
mcc.decr("tp", 1));
mcc.asyncDecr("tp", 1);

Known Limitations

  • If the Data name is not resolved in the CRUD API, then the link will be created with an unknown Memcached data object