In-Memory Cache REST API on Redis Database.
This REST API functionality was implemented on top of Node.js -- a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. As datastore it uses Redis -- an open source, BSD licensed, advanced key-value cache and store.
Configuring Redis connection is, basically, the only thing to be done in order to run redis-imc, in server.js you will find a line 27 where you can set your server address/hostname:
var dbHost = 'localhost';
API designed to return you two types of server replies, for the result reply looks the following way:
{
"type": "result",
"result": ...
}
Where faulty replies are having type field set to error and result filed contains fault description:
{
"type": "error",
"result": ...
}
GET /_projects
Content-Type: application/json
Returns array of projects
{
"type": "result",
"result":
[
"project1",
"project2",
...
]
}
PUT /_projects
Content-Type: application/json
Request body:
{"name": "PROJECT_NAME"}
DELETE /PROJECT_NAME
Content-Type: application/json
Returns true if project was deleted or false if failed to delete
{
"type": "result",
"result": true|false
}
GET /{project}/_details
Content-Type: application/json
Returns number of caches within a project
{
"type": "result",
"result":
{
"caches": 123456
}
}
Returns number of caches in selected project
GET /{project}/_caches
Content-Type: application/json
PUT /{project}/_caches
Content-Type: application/json
Request body:
{"name": "CACHE_NAME"}
DELETE /{project}/{cache}
Content-Type: application/json
Returns true if cache was deleted or false if failed to delete
{
"type": "result",
"result": true|false
}
GET /{project}/{cache}/_details
Content-Type: application/json
Returns number of items registered within a cache
{
"type": "result",
"result":
{
"items": number_of_items
}
}
GET /{project}/{cache}/{item}
Content-Type: application/json
Returns content of the requested item
{
"type": "result",
"result": "value"
}
PUT /{project}/{cache}/_items
Content-Type: application/json
You need to pass JSON object with name of the item, its value and specify overwrite to set a new value to the existing item, so it will overwrite it, otherwise, if overwrite set to false or not present, it will fire an error that item already exists.
Request body:
{
"name": "ITEM_NAME",
"value": "VALUE"|VALUE
"overwrite": true|false
}
Returns true if item was created or false if creation failed
{
"result": true|false
}
DELETE /{project}/{cache}/{item}
Content-Type: application/json
Returns true if item was deleted or false if deletion failed or item was not found
{
"result": true|false
}
POST /{project}/{cache}/{item}
Content-Type: application/json
Request body:
{"increment": 1}
Returns new value of the item
{
"result": old_value +increment
}