=======================Introduction========================== xmemcached XMemcached is a high performance, easy to use blocking multithreaded memcached client in java. It's nio based and was carefully tuned to get top performance.
homepage: http://code.google.com/p/xmemcached/ downloads; http://code.google.com/p/xmemcached/downloads/list wiki : http://code.google.com/p/xmemcached/w/list author : dennis zhuang(killme2008@gmail.com)
============================================================= FAQ 1.How to build project by maven?
Type command "mvn -Dtest -DfailIfNoTests=false assembly:assembly" to build the project.Maven will download the dependencies automacly and build project.
2.How to run unit tests?
The test.properties file under the src/test/resources folder is used for setting memcached test server. Please set test.memcached.servers property,Then run the AllTests class with jvm option "-ea".
3.Is Xmemcached compatible with jdk5? Yes,since 1.2.0-RC1,Xmemcached is compatible with jdk5.
======================Example==================================
XMemcachedClientBuilder builder = new XMemcachedClientBuilder( AddrUtil.getAddresses("localhost:11211")); XMemcachedClient client=builder.build();
XMemcachedClientBuilder builder = new XMemcachedClientBuilder( AddrUtil.getAddresses("localhost:11211")); builder.setCommandFactory(new BinaryCommandFactory()); XMemcachedClient client=builder.build();
XMemcachedClientBuilder builder = new XMemcachedClientBuilder( AddrUtil.getAddresses("localhost:11211")); builder.setCommandFactory(new KestrelCommandFactory()); XMemcachedClient client=builder.build();
client.setPrimitiveAsString(true);
client.addServer("localhost:12001 localhost:12002"); client.removeServer("localhost:12001 localhost:12002");
String name =client.get("test");
client.add("hello", 0, "dennis"); client.replace("hello", 0, "dennis"); client.append("hello", 0, " good"); client.prepend("hello", 0, "hello "); GetsResponse response=client.gets("hello"); long cas=response.getCas(); Obejct value=response.getValue();
client.set("a",0,"1"); client.incr("a",4); client.deccr("a",4);
client.cas("a", 0, new CASOperation() { @Override public int getMaxTries() { return 1; //max try times } @Override public Object getNewValue(long currentCAS, Object currentValue) { System.out.println("current value " + currentValue); return 3; }
});
client.flushAll();
Map<InetSocketAddress,Map<String,String>> result=client.getStats();
Map<InetSocketAddress,String> version=memcached.getVersions();
List
java -Dxmemcached.jmx.enable=true [YourApp]
Access MBean through service:jmx:rmi:///jndi/rmi://[host]:7077/xmemcachedServer
<bean name="memcachedClient" class="net.rubyeye.xmemcached.utils.XMemcachedClientFactoryBean">
//set weight to 2 client.addServer("localhost",12000,2);
//or through XMemcachedClientBuilder,pass a weight array to XMemcachedClientBuilder constructor MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil.getAddresses("localhost:12000 localhost:12001"),new int[]{1,3}); builder.setSessionLocator(new KetamaMemcachedSessionLocator()); MemcachedClient memcachedClient=builder.build();
More information see wiki pages please.