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