Memcached 简明教程
Memcached - Get Data
Memcached get 命令用于获取存储在密钥上的值。如果密钥不存在于 Memcached 中,则它不会返回任何内容。
Memcached get command is used to get the value stored at key. If the key does not exist in Memcached, then it returns nothing.
Syntax
Memcached get 命令的基本语法如下所示 −
The basic syntax of Memcached get command is as shown below −
get key
Example
在以下示例中,我们使用 tutorialspoint 作为密钥,并在其中存储 memcached,其过期时间为 900 秒。
In the following example, we use tutorialspoint as the key and store memcached in it with an expiration time of 900 seconds.
set tutorialspoint 0 900 9
memcached
STORED
get tutorialspoint
VALUE tutorialspoint 0 9
memcached
END
Get Data Using Java Application
要从 Memcached 服务器获取数据,你需要使用 Memcached get 方法。
To get data from a Memcached server, you need to use the Memcached get method.
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.get("tutorialspoint"));
}
}