本文概述
Memcached gets命令用于获取CAS数据的值。这是用于CAS数据的替代get命令。该命令返回带有项的CAS标识符(唯一的64位数字)。如果该密钥在Memcached中不存在, 则不返回任何内容。
句法
gets key
这里,
key:它是从Memcached存储和检索的密钥数据。
Ubuntu中的示例
让我们看一个” gets”命令的例子。在这里, 我们将使用”城市”作为关键字, 并在900秒的时间到期后将”班加罗尔”存储在其中。
set city 0 900 9
bangalore
STORED
gets city
VALUE city 0 9 1
bangalore
END
Windows中的示例
让我们看一个” gets”命令的例子。在这里, 我们将使用”城市”作为密钥, 并在900秒的时间到期后将”班加罗尔”存储在其中。
set city 0 900 9
bangalore
STORED
gets city
VALUE city 0 9 1
bangalore
END
Memcached服务器
Memcached客户端
使用Java应用程序的CAS
考虑Memcached服务器在主机127.0.0.1和端口11211上运行。在这里, 我们将使用gets()方法从Memcached服务器获取CAS数据。
例子
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("city", 900, "bangalore").done);
// Get value from cache
System.out.println("Get from Cache:"+mcc.gets("city"));
}
}
输出
Connection to server successfully
set status: true
Get from Cache:{CasValue 2/bangalore}
评论前必须登录!
注册