Memcached 简明教程
Memcached - Get CAS Data
Memcached gets 命令用于获取带有 CAS 令牌的值。如果 Memcached 中不存在该密钥,则它将不返回任何内容。
Example
set tutorialspoint 0 900 9
memcached
STORED
gets tutorialspoint
VALUE tutorialspoint 0 9 1
memcached
END
在此示例中,我们使用 tutorialspoint 作为密钥,并将 memcached 存储在其中,其到期时间为 900 秒。
Get CAS Data Using Java Application
若要从 Memcached 服务器获取 CAS 数据,您需要使用 Memcached gets 方法。
Example
import net.spy.memcached.MemcachedClient;
public class MemcachedJava {
public static void main(String[] args) {
// Connecting to Memcached server on localhost
MemcachedClient mcc = new MemcachedClient(new
InetSocketAddress("127.0.0.1", 11211));
System.out.println("Connection to server sucessfully");
System.out.println("set status:"+mcc.set("tutorialspoint", 900, "memcached").done);
// Get value from cache
System.out.println("Get from Cache:"+mcc.gets("tutorialspoint"));
}
}