A fast Key-Value store
Introduction
Speedy comes with a KV store right out of the box, with features that is desired out of KV store. A key and value can be placed/retrieved easily with /kv
endpoint. A simple put
on /kv
will place the key on the kv
store. post
to replace the key, a HTTP get
on/kv/<key>
will retrieve the value from KV store, and finally delete
method to delete the KV from the store.
Few words on the type of keys that can be stored with KV store. KV store offers three types of storage strategies for key
and value
storage. First, sticky
type, these are stored permanently with KV store, unless deleted explicitly. Second, tenured
type, these expire after the given number of minutes. Third, temporary
type, they expire by default after the number of minutes mentioned with the setting REST_CACHE_ENTRY_TENURE
, if not altered, this value is set to 30 minutes by default.
Supported Keywords
The following are the set of keywords to be used with definition creation.
key - Access key for KV pair
value - Value associated with the Key
type - Optional; type 1 = sticky (aka permanent), 2 = tenured
ttl - Optional; time to live in minutes, used with type = 2
Creating a Key-Value
Consider the following example below which will create a key light
with the associated value Speed is 3,00,000 km/s
, this KV will be held in KV store for 30 minutes as desired with expiry
set to 30
.
curl -X POST 'localhost:3023/kv/' \
-H 'Content-Type: text/plain' \
-d '{
"key" : "light",
"value" : "Speed is 3,00,0000 km/s",
"type" : 2,
"expiry" : 30
}'
Now, let’s get the key and associated value out of the KV store. Following is the curl command to do so.
curl -X GET 'localhost:3023/kv/light'
Update and Delete a Key-Value
Updating the value for a key
is simple with a post
method. Below is an example using curl
and postman
.
curl -X PUT 'localhost:3023/kv/' \
-H 'Content-Type: text/plain' \
-d '{
"key" : "light",
"value" : "Speed is 1,80,000 mi/s",
"type" : 2,
"expiry" : 30
}'
Finally, deleting a KV from the store is quite simple. Following are the curl
and postman
grabs to accomplish the same.
curl -X DELETE 'localhost:3023/kv/light'
Creating a “sticky” Key-Value record
Consider the previous example of ‘speed of light’, to make it a ‘Stikcy’ aka permanent key on Speedy, the type need to be changed to one (1).
curl -X POST 'localhost:3023/kv/' \
-H 'Content-Type: text/plain' \
-d '{
"key" : "light",
"value" : "Speed is 3,00,0000 km/s",
"type" : 1
}'
This key will stay on Speedy until it is deleted explicitly.
Creating a “temporary” Key-Value record
Consider the previous example of ‘speed of light’, to make it a ‘temporary’ key on Speedy. All that needs to be done is, not to mention any ‘type’ in the request.
curl -X POST 'localhost:3023/kv/' \
-H 'Content-Type: text/plain' \
-d '{
"key" : "light",
"value" : "Speed is 3,00,0000 km/s"
}'
This key will stay on Speedy for the next 30 minutes, post to which it will be removed automatically.