mirror of
https://github.com/darkwire/darkwire.io.git
synced 2025-07-18 10:49:02 +00:00
* 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>
42 lines
863 B
JavaScript
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 |