Memcached Storage Commands
- Memcached - CAS
- Memcached - Prepend Data
- Memcached - Append Data
- Memcached - Replace Data
- Memcached - Add Data
- Memcached - Set Data
Memcached Retrieval Commands
- Memcached - Incr/Decr
- Memcached - Delete Data
- Memcached - Delete Key
- Memcached - Get CAS Data
- Memcached - Get Data
Memcached Statistics Commands
- Memcached - Clear Data
- Memcached - Stats sizes
- Memcached - Stats Slabs
- Memcached - Stats Items
- Memcached - Stats
Memcached Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Memcached - Connection
To connect to a Memcached server, you need to use the telnet command on HOST and PORT names.
Syntax
The basic syntax of Memcached telnet command is as shown below −
$telnet HOST PORT
Here, HOST and PORT are machine IP and port number respectively, on which the Memcached server is executing.
Example
The following example shows how to connect to a Memcached server and execute a simple set and get command. Assume that the Memcached server is running on host 127.0.0.1 and port 11211.
$telnet 127.0.0.1 11211 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is ^] . // now store some data and get it from memcached server set tutorialspoint 0 900 9 memcached STORED get tutorialspoint VALUE tutorialspoint 0 9 memcached END
Connection from Java Apppcation
To connect the Memcached server from your java program, you need to add the Memcached jar into your classpath as shown in the previous chapter. Assume that the Memcached server is running on host 127.0.0.1 and port 11211. −
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"); //not set data into memcached server 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.
The terminal may show few informational messages too, those can be ignored.
Advertisements