- Memcached Basics
- Memcached - Home
- Memcached - Overview
- Memcached - Environment
- Memcached - Connection
- Memcached Storage Commands
- Memcached - Set Data
- Memcached - Add Data
- Memcached - Replace Data
- Memcached - Append Data
- Memcached - Prepend Data
- Memcached - CAS
- Memcached Retrieval Commands
- Memcached - Get Data
- Memcached - Get CAS Data
- Memcached - Delete Key
- Memcached - Delete Data
- Memcached - Incr/Decr
- Memcached Statistics Commands
- Memcached - Stats
- Memcached - Stats Items
- Memcached - Stats Slabs
- Memcached - Stats sizes
- Memcached - Clear Data
- Memcached Useful Resources
- Memcached - Quick Guide
- Memcached - Useful Resources
- Memcached - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Memcached - Get CAS Data
Memcached gets command is used to get the value with CAS token. If the key does not exist in Memcached, then it returns nothing.
Syntax
The basic syntax of Memcached gets command is as shown below −
get key
Example
set tutorialspoint 0 900 9 memcached STORED gets tutorialspoint VALUE tutorialspoint 0 9 1 memcached END
In this example, we use tutorialspoint as the key and store memcached in it with an expiration time of 900 seconds.
Get CAS Data Using Java Application
To get CAS data from a Memcached server, you need to use the Memcached gets 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.gets("tutorialspoint")); } }
Output
On compiling and executing the program, you get to see the following output −
Connection to server successfully set status:true Get from Cache:{CasValue 2/memcached}
Advertisements