Google News
logo
Memcached - Interview Questions
Can you explain Memcached's protocol and commands?
Memcached uses a simple text-based protocol for communication between clients and servers. The protocol is designed to be lightweight and efficient, focusing on basic commands for storing, retrieving, and deleting data. Here's an overview of Memcached's protocol and some of its key commands:

SET : The SET command is used to store data in the cache. It takes the following form:
SET <key> <flags> <exptime> <bytes> [noreply]\r\n
<data>\r\n?

<key> : The unique key under which the data will be stored.
<flags> : Optional flags that provide additional information about the data (e.g., data format).
<exptime> : Optional expiration time for the data, in seconds.
<bytes> : The number of bytes in the data block.
[noreply] : An optional parameter that instructs the server not to send a response to the client.


GET : The GET command is used to retrieve data from the cache. It takes the following form:
GET <key>\r\n
<key>: The key of the data to retrieve.?

DELETE : The DELETE command is used to remove data from the cache. It takes the following form:
DELETE <key> [noreply]\r\n?

<key> : The key of the data to delete.
[noreply] : An optional parameter that instructs the server not to send a response to the client.

INCREMENT/DECREMENT : The INCR and DECR commands are used to increment or decrement numeric values stored in the cache. They take the following form:
INCR <key> <value> [noreply]\r\n
DECR <key> <value> [noreply]\r\n?

<key> : The key of the numeric value to modify.
<value> : The amount by which to increment or decrement the value.
[noreply] : An optional parameter that instructs the server not to send a response to the client.


STATS : The STATS command is used to retrieve statistics about the Memcached server. It takes the following form:
STATS\r\n?

FLUSH_ALL : The FLUSH_ALL command is used to clear all data from the cache. It takes the following form:
FLUSH_ALL [delay]\r\n?

[delay] : An optional delay (in seconds) before flushing the cache.
Advertisement