redis2go v1.0.2
Redis2Go
This is a implementation of a subset of Redis commands. In particular:
- SET key value
- SET key value EX seconds (need not implement other SET options)
- GET key
- DEL key
- DBSIZE
- INCR key
- ZADD key score member
- ZCARD key
- ZRANK key member
- ZRANGE key start stop
Lightweight Architecture Decision Records
We use ADRs, so major decisions are justified and put on context for future consideration.
Installation in your Project
You'll need Node v6.10.3 and npm. This packaged it's published on NPM, so
you can add it to your JS projects.
npm install redis2go --saveUsage Example
const Redis2Go = require('./redis2go')
const client = new Redis2Go()
client.set(100).then(result => console.log(result)) // 'OK'
client.get('my_key').then(result => console.log(result)) // '100'
JS API of Available Commands
For behavior of each command, check the Command Reference.
GET
get(key) -> PromiseSET
set(key, value, expiration_time) -> PromiseDEL
del(...args) -> PromiseINCR
incr(key) -> PromiseDBSIZE
dbsize() -> PromiseZADD
zadd(key, [... order, value]) -> PromiseZCARD
zcard(key) -> PromiseZRANK
zrank(key, value) -> PromiseZRANGE
zrange(key, start, end) -> PromiseServer
To start a server instance:
npm run startYou can specify which port to run by setting the environment variable PORT, by default it
will run in the port 3000.
Command Mode
You can run raw commands with query parameters:
curl localhost:8080/?cmd=SET%20mykey%20cool-value
OK
curl localhost:8080/?cmd=GET%20mykey
cool-value
curl localhost:8080/?cmd=DEL%20mykey
OK
curl localhost:8080/?cmd=GET%20mykey
(nil)HTTP API
For a more idiomatic way of communicating with Redis2go, we have a Full Rest API.
Make sure to add Content-Type: text/plain as it is the data type that the API will consume.
ADD
method: 'PUT',
path: '/{key}',GET
method: 'GET',
path: '/{key}',DELETE
method: 'DELETE',
path: '/{key}',DBSIZE
method: 'GET',
path: '/dbSize',INCR
method: 'PUT',
path: '/{key}/incr',ZADD
method: 'PUT',
path: '/{key}/zadd',ZCARD
method: 'GET',
path: '/{key}/zcard',ZRANK
method: 'GET',
path: '/{key}/zrank/{value}'ZRANGE
method: 'GET',
path: '/{key}/zrange/{start}/{end}',Example
curl -X POST -H "Content-Type: text/plain" --data "cool-value" -X PUT localhost:3000/mykeyTests
To run unit tests, clone this repo and run the following:
npm install
npm run testTo run integration tests:
npm install
npm run start
#different terminal, run the tests
npm run integration-tests