ubuntu下memcached安装
[*]sudo apt-get install libevent-dev
[*]./configure
[*]make && make test
[*]sudo make install
测试是否安装成功
[*]启动memcached 输入 memcached -d -l 192.168.1.150
[*]下载java客户端xmemcached,运行
MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil.getAddresses("192.168.1.150:11211"));MemcachedClient memcachedClient = null;try {memcachedClient = builder.build();} catch (IOException e1) {e1.printStackTrace();}try {memcachedClient.set("hello", 0, "Hello,xmemcached");String value = memcachedClient.get("hello");System.out.println("hello=" + value);memcachedClient.delete("hello");value = memcachedClient.get("hello");System.out.println("hello=" + value);} catch (MemcachedException e) {System.err.println("MemcachedClient operation fail");e.printStackTrace();} catch (TimeoutException e) {System.err.println("MemcachedClient operation timeout");e.printStackTrace();} catch (InterruptedException e) {// ignore}try {// close memcached clientmemcachedClient.shutdown();} catch (IOException e) {System.err.println("Shutdown MemcachedClient fail");e.printStackTrace();} 运行结果:
hello=Hello,xmemcached
hello=null
页:
[1]