📅  最后修改于: 2020-11-27 05:44:32             🧑  作者: Mango
Memcached gets命令用于通过CAS令牌获取值。如果该密钥在Memcached中不存在,则不返回任何内容。
Memcached gets命令的基本语法如下所示-
get key
set tutorialspoint 0 900 9
memcached
STORED
gets tutorialspoint
VALUE tutorialspoint 0 9 1
memcached
END
在此示例中,我们使用tutorialspoint作为密钥,并将内存缓存存储在其中,有效时间为900秒。
要从Memcached服务器获取CAS数据,您需要使用Memcached gets方法。
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"));
}
}
在编译和执行程序时,您将看到以下输出-
Connection to server successfully
set status:true
Get from Cache:{CasValue 2/memcached}