This application imitates an in memory key value store with help of golang. It accepts multiple commands such as SET, GET, QPUSH ,QPOP , BQPOP to perform various operations on the store
This application can be run locally in 2 ways
- Using Golang Compiler
- Using Docker
- Golang How to install Golang ?
- Docker How to install Docker ?
- Clone the repository and open the root folder.
- Run
go build -o main
- To start the application run
./main
- The server is up and running on port 8080.
- Clone the repository and open the root folder.
- Run
docker build -t inmemorystore .
to build the docker image. - To start the application run
docker run -it -p 8080:8080 --rm --name inmemstore inmemorystore
. - The server is up and running on port 8080.
SET <key> <value> <expiry time>? <condition>?
-
<key>
:
The key under which the given value will be stored. -
<value>
:
The value to be stored. -
<expiry time>
:
Specifies the expiry time of the key in seconds.
Must contain the prefixEX
.
This is an optional field.
The field must be an integer value. -
<condition>
:
Specifies the decision to take if the key already exists.
Accepts eitherNX
orXX
.NX
-- Only set the key if it does not already exist.XX
-- Only set the key if it already exists.
This is an optional field.
The default behavior will be to upsert the value of the key.
-
SET key_a 2
:
Sets the value 2 inkey_a
and does not expire. -
SET key_b 3 EX 60
:
Sets the value 3 inkey_b
and expires in 60 seconds. -
SET key_c 4 EX 60 NX
:
Sets the value 4 inkey_c
, expires in 60 seconds, and only sets the value if the key does not already exist. -
SET key_d 5 XX
:
Sets the value 5 inkey_d
, does not expire, and only sets the value if the key already exists.
GET <key>
- Examples:
GET key_a
:
Returns the value stored using the specified key.
QPUSH <key> <value...>
-
<key>
:
Name of the queue to write to. -
<value...>
:
Variadic input that receives multiple values separated by space. -
Examples:
QPUSH list_a 1
:
Adds value1
to the queue namedlist_a
.QPUSH list_a 2 3 4
:
Adds values2
,3
, and4
to the queue namedlist_a
.
QPOP <key>
-
<Key>
:
Name of the queue. -
Examples:
QPUSH list_a 1
:
Returns OK.QPOP list_a
:
Returns1
.QPUSH list_a 1 2
:
Returns OK.QPOP list_a
:
Returns1
.QPOP list_a
:
Returns2
.QPOP list_x
:
Returnsnull
.
BQPOP <key> <timeout>
-
<key>
:
Name of the queue to read from. -
<timeout>
:
The duration in seconds to wait until a value is read from the queue.
The argument must be interpreted as a double value.
A value of0
immediately returns a value from the queue without blocking. -
Example:
-
Scenario 1:
QPUSH list_1 a
:
Returns OK.BQPOP list_1 0
:
Returnsa
.
-
Scenario 2:
BQPOP list_1 0
:
Returnsnull
.
-
Scenario 3:
BQPOP list_1 10
:
Blocks the request as the queue is empty.
Returnsnull
after 10 seconds.
-