UNPKG

hemera-redis-store

Version:
1,068 lines (983 loc) 18.4 kB
'use strict' const hp = require('hemera-plugin') module.exports = hp((hemera, opts, done) => { Object.prototype.toString = function () { try{ return JSON.stringify(this) }catch{ } }; const topic = 'redis-store' const client = hemera.redis.client //stirng类型相关操作 //set hemera.add( { topic, cmd: 'set', schema: { request: 'RequestSet#' } }, function (req, cb) { client.set(req.key, req.value, cb) } ) //setex hemera.add( { topic, cmd: 'setex', schema: { request: 'RequestKeyValueModeTime#' } }, function (req, cb) { client.set(req.key, req.value, req.mode, req.delaytime, cb) } ) //get hemera.add( { topic, cmd: 'get', schema: { request: 'RequestKey#' } }, function (req, cb) { client.get(req.key, cb) } ) //del hemera.add( { topic, cmd: 'del', schema: { request: 'RequestKey#' } }, function (req, cb) { client.del(req.key, cb) } ) //andsub hemera.add({ topic, cmd: 'andsub', schema: { request: 'RequestAddSub#' } }, function (req, cb) { switch (req.method) { case 'incr': client.incr(req.key, cb) break case 'decr': client.decr(req.key, cb) break case 'incrby': client.incrby(req.key, req.number, cb) break case 'decrby': client.decrby(req.key, req.number, cb) break } }) //incrbyfloat hemera.add({ topic, cmd: 'incrbyfloat', schema: { request: 'RequestIncrbyFloat#' } }, function (req, cb) { client.incrbyfloat(req.key, req.number, cb) }) //append hemera.add({ topic, cmd: 'append', schema: { request: 'RequestAppend#' } }, function (req, cb) { client.append(req.key, req.value, cb) }) //getrange hemera.add({ topic, cmd: 'getrange', schema: { request: 'RequestStartEnd#' } }, function (req, cb) { client.getrange(req.key, req.start, req.end, cb) }) //setrange hemera.add({ topic, cmd: 'setrange', schema: { request: 'RequestSetrange#' } }, function (req, cb) { client.setrange(req.key, req.offset, req.value, cb) }) //list操作 //lpush hemera.add( { topic, cmd: 'lpush', schema: { request: 'RequestRpushxLpush#' } }, function (req, cb) { client.send_command('lpush', [req.key, req.value], cb) } ) //lpushx hemera.add( { topic, cmd: 'lpushx', schema: { request: 'RequestRpushxLpush#' } }, function (req, cb) { client.lpushx(req.key, req.value, cb) } ) //rpush hemera.add( { topic, cmd: 'rpush', schema: { request: 'RequestRpushxLpush#' } }, function (req, cb) { client.send_command('rpush', [req.key, req.value], cb) } ) //rpushx hemera.add( { topic, cmd: 'rpushx', schema: { request: 'RequestRpushxLpush#' } }, function (req, cb) { client.rpushx(req.key, req.value, cb) } ) //lset hemera.add( { topic, cmd: 'lset', schema: { request: 'RequestLset#' } }, function (req, cb) { client.send_command('lset', [req.key, req.index, req.value], cb) } ) //lsetx hemera.add( { topic, cmd: 'lsetx', schema: { request: 'RequestLset#' } }, function (req, cb) { client.lset(req.key, req.index, req.value, cb) } ) //lrange hemera.add( { topic, cmd: 'lrange', schema: { request: 'RequestLrange#' } }, function (req, cb) { client.lrange(req.key, req.start, req.stop, cb) } ) //lindex hemera.add( { topic, cmd: 'lindex', schema: { request: 'RequestLindex#' } }, function (req, cb) { client.lindex(req.key, req.index, cb) } ) //lpop hemera.add( { topic, cmd: 'lpop', schema: { request: 'RequestKey#' } }, function (req, cb) { client.lpop(req.key, cb) } ) //rpop hemera.add( { topic, cmd: 'rpop', schema: { request: 'RequestKey#' } }, function (req, cb) { client.rpop(req.key, cb) } ) //ltrim hemera.add( { topic, cmd: 'ltrim', schema: { request: 'RequestLrange#' } }, function (req, cb) { client.ltrim(req.key, req.start, req.stop, cb) } ) //lrem hemera.add( { topic, cmd: 'lrem', schema: { request: 'RequestLrem#' } }, function (req, cb) { client.lrem(req.key, req.count, req.value, cb) } ) //llen hemera.add( { topic, cmd: 'llen', schema: { request: 'RequestKey#' } }, function (req, cb) { client.llen(req.key, cb) } ) //linsert hemera.add( { topic, cmd: 'linsert', schema: { request: 'RequestLinsert#' } }, function (req, cb) { client.linsert(req.key, req.dir, req.pivot, req.value, cb) } ) //set相关操作 //sadd hemera.add( { topic, cmd: 'sadd', schema: { request: 'RequestSadd#' } }, function (req, cb) { client.sadd(req.key, req.value, cb) } ) //smembers hemera.add( { topic, cmd: 'smembers', schema: { request: 'RequestKey#' } }, function (req, cb) { client.smembers(req.key, cb) } ) //sismember hemera.add( { topic, cmd: 'sismember', schema: { request: 'RequestSismemberSrem#' } }, function (req, cb) { client.sismember(req.key, req.value, cb) } ) //srem hemera.add( { topic, cmd: 'srem', schema: { request: 'RequestSismemberSrem#' } }, function (req, cb) { client.srem(req.key, req.value, cb) } ) //scard hemera.add( { topic, cmd: 'scard', schema: { request: 'RequestKey#' } }, function (req, cb) { client.scard(req.key, cb) } ) //spop hemera.add( { topic, cmd: 'spop', schema: { request: 'RequestKey#' } }, function (req, cb) { client.spop(req.key, cb) } ) //smove hemera.add( { topic, cmd: 'smove', schema: { request: 'RequestSmove#' } }, function (req, cb) { client.smove(req.source_key, req.dest_key, req.item, cb) } ) //sdiff hemera.add( { topic, cmd: 'sdiff', schema: { request: 'RequestSdiffSinterSunion#' } }, function (req, cb) { client.sdiff(req.key, req.keys, cb) } ) //sdiffstore hemera.add( { topic, cmd: 'sdiffstore', schema: { request: 'RequestSdiffstoreSinterstoreSunionstore#' } }, function (req, cb) { client.sdiffstore(req.dest_key, req.key, req.keys, cb) } ) //sinter hemera.add( { topic, cmd: 'sinter', schema: { request: 'RequestSdiffSinterSunion#' } }, function (req, cb) { client.sinter(req.key, req.keys, cb) } ) //sinterstore hemera.add( { topic, cmd: 'sinterstore', schema: { request: 'RequestSdiffstoreSinterstoreSunionstore#' } }, function (req, cb) { client.sinterstore(req.dest_key, req.key, req.keys, cb) } ) //sunion hemera.add( { topic, cmd: 'sunion', schema: { request: 'RequestSdiffSinterSunion#' } }, function (req, cb) { client.sunion(req.key, req.keys, cb) } ) //sunionstore hemera.add( { topic, cmd: 'sunionstore', schema: { request: 'RequestSdiffstoreSinterstoreSunionstore#' } }, function (req, cb) { client.sunionstore(req.dest_key, req.key, req.keys, cb) } ) //hash相关操作 //hset hemera.add( { topic, cmd: 'hset', schema: { request: 'RequestHset#' } }, function (req, cb) { client.hset(req.hash_key, req.sub_key, req.value, cb) } ) //hget hemera.add( { topic, cmd: 'hget', schema: { request: 'RequestHgetHdelHexists#' } }, function (req, cb) { client.hget(req.hash_key, req.sub_key, cb) } ) //hgetall hemera.add( { topic, cmd: 'hgetall', schema: { request: 'RequestHgetallHlenHkeysHvals#' } }, function (req, cb) { client.hgetall(req.hash_key, cb) } ) //hdel hemera.add( { topic, cmd: 'hdel', schema: { request: 'RequestHgetHdelHexists#' } }, function (req, cb) { client.hdel(req.hash_key, req.sub_key, cb) } ) //hmset hemera.add( { topic, cmd: 'hmset', schema: { request: 'RequestHmset#' } }, function (req, cb) { client.hmset(req.hash_key, req.obj, cb) } ) //hmget hemera.add( { topic, cmd: 'hmget', schema: { request: 'RequestHmget#' } }, function (req, cb) { client.hmget(req.hash_key, req.array, cb) } ) //hlen hemera.add( { topic, cmd: 'hlen', schema: { request: 'RequestHgetallHlenHkeysHvals#' } }, function (req, cb) { client.hlen(req.hash_key, cb) } ) //hexists hemera.add( { topic, cmd: 'hexists', schema: { request: 'RequestHgetHdelHexists#' } }, function (req, cb) { client.hexists(req.hash_key, req.sub_key, cb) } ) //hkeys hemera.add( { topic, cmd: 'hkeys', schema: { request: 'RequestHgetallHlenHkeysHvals#' } }, function (req, cb) { client.hkeys(req.hash_key, cb) } ) //hvals hemera.add( { topic, cmd: 'hvals', schema: { request: 'RequestHgetallHlenHkeysHvals#' } }, function (req, cb) { client.hvals(req.hash_key, cb) } ) //hincrby hemera.add( { topic, cmd: 'hincrby', schema: { request: 'RequestHincrby#' } }, function (req, cb) { client.hincrby(req.hash_key, req.sub_key, req.number, cb) } ) //hincrbyfloat hemera.add( { topic, cmd: 'hincrbyfloat', schema: { request: 'RequestHincrbyfloat#' } }, function (req, cb) { client.hincrbyfloat(req.hash_key, req.sub_key, req.number, cb) } ) //zset相关操作 //zadd hemera.add( { topic, cmd: 'zadd', schema: { request: 'RequestZadd#' } }, function (req, cb) { client.zadd(req.key, req.score, req.member, cb) } ) //zrange hemera.add( { topic, cmd: 'zrange', schema: { request: 'RequestZrange#' } }, function (req, cb) { if (req.withscores == undefined) { client.zrange(req.key, req.start, req.stop, cb) } else { client.zrange(req.key, req.start, req.stop, req.withscores, cb) } } ) //zcard hemera.add( { topic, cmd: 'zcard', schema: { request: 'RequestZcard#' } }, function (req, cb) { client.zcard(req.key, cb) } ) //zcount hemera.add( { topic, cmd: 'zcount', schema: { request: 'RequestZcountZremrangebyscore#' } }, function (req, cb) { client.zcount(req.key, req.min, req.max, cb) } ) //zincrby hemera.add( { topic, cmd: 'zincrby', schema: { request: 'RequestZincrby#' } }, function (req, cb) { client.zincrby(req.key, req.number, req.member, cb) } ) //zinterstore hemera.add( { topic, cmd: 'zinterstore', schema: { request: 'RequestZinterstore#' } }, function (req, cb) { client.zinterstore(req.new_key , req.num_keys, cb) } ) //zlexcount hemera.add( { topic, cmd: 'zlexcount', schema: { request: 'RequestZlexcountZrangebylex#' } }, function (req, cb) { client.zlexcount(req.key, req.min, req.max, cb) } ) //zrangebylex hemera.add( { topic, cmd: 'zrangebylex', schema: { request: 'RequestZlexcountZrangebylex#' } }, function (req, cb) { if (req.limit == undefined || req.offset == undefined || req.count == undefined) { client.zrangebylex(req.key, req.min, req.max, cb) } else { client.zrangebylex(req.key, req.min, req.max, req.limit, req.offset, req.count, cb) } } ) //zrevrangebylex hemera.add( { topic, cmd: 'zrevrangebylex', schema: { request: 'RequestZlexcountZrangebylex#' } }, function (req, cb) { if (req.limit == undefined || req.offset == undefined || req.count == undefined) { client.zrevrangebylex(req.key, req.max, req.min, cb) } else { client.zrevrangebylex(req.key, req.max, req.min, req.limit, req.offset, req.count, cb) } } ) //zrank hemera.add( { topic, cmd: 'zrank', schema: { request: 'RequestZrankZscoreZrevrank#' } }, function (req, cb) { client.zrank(req.key, req.member, cb) } ) //zscore hemera.add( { topic, cmd: 'zscore', schema: { request: 'RequestZrankZscoreZrevrank#' } }, function (req, cb) { client.zscore(req.key, req.member, cb) } ) //zrevrank hemera.add( { topic, cmd: 'zrevrank', schema: { request: 'RequestZrankZscoreZrevrank#' } }, function (req, cb) { client.zrevrank(req.key, req.member, cb) } ) //zremrangebylex hemera.add( { topic, cmd: 'zremrangebylex', schema: { request: 'RequestZlexcountZrangebylex#' } }, function (req, cb) { client.zremrangebylex(req.key, req.min, req.max, cb) } ) //zremrangebyscore hemera.add( { topic, cmd: 'zremrangebyscore', schema: { request: 'RequestZcountZremrangebyscore#' } }, function (req, cb) { client.zremrangebyscore(req.key, req.min, req.max, cb) } ) //zremrangebyrank hemera.add( { topic, cmd: 'zremrangebyrank', schema: { request: 'RequestZremrangebyrank#' } }, function (req, cb) { client.zremrangebyrank(req.key, req.start, req.stop, cb) } ) //zrevrange hemera.add( { topic, cmd: 'zrevrange', schema: { request: 'RequestZremrangebyrank#' } }, function (req, cb) { if (req.withscores == undefined) { client.zrevrange(req.key, req.start, req.stop, cb) } else { client.zrevrange(req.key, req.start, req.stop, req.withscores, cb) } } ) //keys命令组 //exists hemera.add( { topic, cmd: 'exists', schema: { request: 'RequestKey#' } }, function (req, cb) { client.exists(req.key, cb) } ) //expire hemera.add( { topic, cmd: 'expire', schema: { request: 'RequestMilliSeconds#' } }, function (req, cb) { client.expire(req.key, req.delaytime, cb) } ) //pexpire hemera.add( { topic, cmd: 'pexpire', schema: { request: 'RequestMilliSeconds#' } }, function (req, cb) { client.pexpire(req.key, req.delaytime, cb) } ) //expireat hemera.add( { topic, cmd: 'expireat', schema: { request: 'RequestMilliSeconds#' } }, function (req, cb) { client.expireat(req.key, req.delaytime, cb) } ) //pexpireat hemera.add( { topic, cmd: 'pexpireat', schema: { request: 'RequestMilliSeconds#' } }, function (req, cb) { client.pexpireat(req.key, req.delaytime, cb) } ) //persist hemera.add( { topic, cmd: 'persist', schema: { request: 'RequestKey#' } }, function (req, cb) { client.persist(req.key, cb) } ) //ttl hemera.add( { topic, cmd: 'ttl', schema: { request: 'RequestKey#' } }, function (req, cb) { client.ttl(req.key, cb) } ) //keys hemera.add( { topic, cmd: 'keys', schema: { request: 'RequestPattern#' } }, function (req, cb) { client.keys(req.pattern, cb) } ) //lastsave hemera.add( { topic, cmd: 'lastsave' }, function (req, cb) { client.lastsave(cb) } ) done() }, { hemera: '>=5.0.0', name: 'server', options: { } })