简介
Memcached是一个自由开源的,高性能,分布式内存对象缓存系统。
安装
yum install memcached
连接
telnet HOST PORT
telnet 127.0.0.1 11211
存储命令
Memcached set 命令
Memcached add
Memcached replace
Memcached append
Memcached prepend
Memcached CAS
查找命令
Memcached get
Memcached gets
Memcached delete
Memcached incr/decr
统计命令
Memcached stats
Memcached stats items
Memcached stats slabs
Memcached stats sizes
Memcached flush_all
java连接
import java.net.InetSocketAddress;
import java.util.concurrent.Future; import net.spy.memcached.MemcachedClient; public class MemcachedJava {
public static void main(String[] args) { try{
// 连接本地的 Memcached 服务
MemcachedClient mcc = new MemcachedClient(new InetSocketAddress("127.0.0.1", 11211));
System.out.println("Connection to server sucessful."); // 存储数据
Future fo = mcc.set("runoob", 900, "Free Education"); // 查看存储状态
System.out.println("set status:" + fo.get()); // 输出值
System.out.println("runoob value in cache - " + mcc.get("runoob")); // 关闭连接
mcc.shutdown(); }catch(Exception ex){
System.out.println( ex.getMessage() );
}
}
}