Jérémie Pardou-Piquemal 2a8d3281db
Allow to launch server without Redis (#119)
* Add nvmrc file for nvm use

* Add help to run redis store with docker

* Add Redis and memory store

* Rename dist files

* Allow to launch server without Redis

* Slit stores in their own files

* Update readme.md

Co-authored-by: Alan Friedman <d.alan.friedman@gmail.com>

* Mimic Redis API

* Move store logic in is own file

Co-authored-by: Alan Friedman <d.alan.friedman@gmail.com>
2020-05-05 08:56:14 -04:00

42 lines
863 B
JavaScript

import Redis from 'redis';
import bluebird from 'bluebird';
import socketRedis from 'socket.io-redis';
/**
* Redis store.
*/
export class RedisStore {
constructor(redisUrl) {
bluebird.promisifyAll(Redis.RedisClient.prototype);
bluebird.promisifyAll(Redis.Multi.prototype);
this.redisUrl = redisUrl;
this.redis = Redis.createClient(redisUrl);
this.hasSocketAdapter = true;
}
get(key, field) {
return this.redis.hgetAsync(key, field);
}
getAll(key) {
return this.redis.hgetallAsync(key);
}
set(key, field, value) {
return this.redis.hsetAsync(key, field, value);
}
del(key, field) {
return this.hdelAsync(key, field);
}
inc(key, field, inc = 1) {
return this.redis.incrbyAsync(key, field, inc);
}
getSocketAdapter() {
return socketRedis(this.redisUrl);
}
}
export default RedisStore