简介
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() ); } } }
原文地址:https://www.cnblogs.com/fast-walking/p/9051614.html
时间: 2024-11-10 14:54:23