java memcached 压缩_基于java nio的memcached客户端——xmemcached

packagenet.rubyeye.xmemcached.test;importjava.util.ArrayList;importjava.util.List;importjava.util.Map;importjava.io.Serializable;importnet.rubyeye.xmemcached.XMemcachedClient;classNameimplementsSerializable {

String firstName;

String lastName;intage;intmoney;publicName(String firstName, String lastName,intage,intmoney) {super();this.firstName=firstName;this.lastName=lastName;this.age=age;this.money=money;

}publicString toString() {return"["+firstName+""+lastName+",age="+age+",money="+money+"]";

}

}publicclassExample {publicstaticvoidmain(String[] args) {try{

String ip="192.168.222.100";intport=11211;

XMemcachedClient client=newXMemcachedClient(ip, port);//存储操作if(!client.set("hello",0,"dennis")) {

System.err.println("set error");

}

client.add("hello",0,"dennis");

client.replace("hello",0,"dennis");//get操作String name=(String) client.get("hello");

System.out.println(name);//批量获取Listkeys=newArrayList();

keys.add("hello");

keys.add("test");

Mapmap=client.get(keys);

System.out.println("map size:"+map.size());//delete操作if(!client.delete("hello",1000)) {

System.err.println("delete error");

}//incr,decrclient.incr("a",4);

client.decr("a",4);//versionString version=client.version();

System.out.println(version);//增删改查自定义对象Name dennis=newName("dennis","zhuang",26,-1);

System.out.println("dennis:"+dennis);

client.set("dennis",0, dennis);

Name cachedPerson=(Name) client.get("dennis");

System.out.println("cachedPerson:"+cachedPerson);

cachedPerson.money=-10000;

client.replace("dennis",0, cachedPerson);

Name cachedPerson2=(Name) client.get("dennis");

System.out.println("cachedPerson2:"+cachedPerson2);//deleteclient.delete("dennis");

System.out.println("after delete:"+client.get("dennis"));

client.shutdown();

}catch(Exception e) {

e.printStackTrace();

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值