Concise notes for the impatient learner

Uncategorized

Getting Started with Memcached

Objective

Run Memcached in a Docker container, connect to the server with telnet, and test simple set/get commands.

Steps

Download the Docker image from Docker Hub

docker pull memcached

Start the server

docker run --name my-memcache -p 11211:11211 -d memcached

Connect to the server using telnet

telnet localhost 11211

Type the following command to set a key-value pair

set mykey 0 100 5
myval

Arguments of the set command

  • mykey: name of the key
  • 0: flag (can be used by the application to store additional information)
  • 100: expiration time in seconds
  • 5: number of bytes in the value
  • myval: value associated to the key

Memcached will respond with STORED or ERROR.

To retrieve the value, use the command

get mykey

Memcached will respond with

VALUE mykey 0 5
myval

Useful Links

Memcached official site

Memcached on Tutorials Point

Recommended Reading

Getting Started with Memcached (ISBN: 1782163220)
Quick introduction to Memcached and client libraries in different languages.

Leave a Reply