English 中文(简体)
Memcached - Get Data
  • 时间:2024-11-03

Memcached - Get Data


Previous Page Next Page  

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

The basic syntax of Memcached get command is as shown below −

get key

Example

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 Apppcation

To get data from a Memcached server, you need to use the Memcached get method.

Example

import net.spy.memcached.MemcachedCpent;
pubpc class MemcachedJava {
   pubpc static void main(String[] args) {
      // Connecting to Memcached server on localhost
      MemcachedCpent mcc = new MemcachedCpent(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"));
   }
}

Output

On compipng and executing the program, you get to see the following output −

Connection to server successfully
set status:true
Get from Cache:memcached
Advertisements