Memcached is an open source, high-performance, distributed memory object caching system. For more information check out the official memcached github repository.
The server runs in the 11211 port by default
-
Download zip file
-
Unzip
-
Set environment variables using an .env file (see the Environment variables section)
-
Open terminal
-
Go to project location
-
Run the following commands:
npm install node index.js
-
Open terminal
-
Run the following command:
telnet localhost 1337
-
Open terminal
-
Go to project location
-
Run the following command:
npm test
-
Open terminal
-
Go to project location
-
Run the following command:
npm run coverage
- set
- add
- replace
- append
- prepend
- cas
- get
- gets
The sytntax goes like this:
<command> <key> <flags> <exptime> <bytes> [noreply]\r\n
where:
-
<command>
is one of the following:set
,add
,replace
,append
orprepend
. -
<key>
is a string that will uniquely identify the element. -
<flags>
is a 32-bit integer that will be stored alongside the value. -
<exptime>
is the expiration time in seconds. -
<bytes>
is the length of the data sent in bytes. -
[noreply]
is an optional string that removes the reply from the server.
Note: the cas command is equal to the previously mentioned but with an extra parameter <unique_cas_key>
which is a unique 64-bit integer.
After the previous has been sent, the server will be expecting data in the following fashion:
<data>\r\n
where <data>
must have a length of <bytes>
.
The server can respond with:
STORED\r\n
in case of success.
and one of the following in case of failure:
-
NOT_STORED\r\n
-
NOT_FOUND\r\n
-
EXISTS\r\n
-
ERROR\r\n
-
CLIENT_ERROR bad data chunk\r\nERROR\r\n
-
CLIENT_ERROR bad command line format\r\n
set key 0 1200 2
333
CLIENT_ERROR bad data chunk
ERROR
add key 0 1200 2
23
STORED
replace key 0 30 3 noreply
333
append other_key 0 1200 5
hello
NOT_STORED
prepend other_key 0 1200 11 noreply
helloworld!
cas key 0 1200 9 1
memcached
STORED
For the retrieval commands the sytntax is shorter:
<command> <key_1> <key2> <key_3>...<key_n>\r\n
where:
-
<command>
is one of the following:get
orgets
. -
<key_x>
is a string that will uniquely identify the element.
The server can respond with:
VALUE <key> <flags> <bytes>\r\n<value>\r\nEND\r\n
in case the key in the get commands exists.
and the following in case of a successful gets request:
VALUE <key> <flags> <bytes> <cas>\r\n<value>\r\nEND\r\n
in case the key in the gets commands exists.
or in case the key doesn't exist:
END\r\n
and one of the following in case of failure:
-
ERROR\r\n
-
CLIENT_ERROR bad data chunk\r\nERROR\r\n
get key
VALUE key 0 2
25
END
gets key
VALUE key 0 2 1
25
END
The server uses 3 environment variables:
<PORT>
, <IP>
and <MAX_CONNECTIONS>
If not provided, the default values are 1337
, 0.0.0.0
and 5
respectively.