1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00

Update commands list and remove unecessary code

Add use strict

Add changelog entry
This commit is contained in:
Ruben Bridgewater
2015-09-03 21:50:29 +02:00
parent feb1faa824
commit b06985a219
4 changed files with 45 additions and 30 deletions

View File

@@ -7,7 +7,10 @@ var net = require("net"),
to_array = require("./lib/to_array"),
events = require("events"),
crypto = require("crypto"),
parsers = [], commands,
parsers = [],
// This static list of commands is updated from time to time.
// ./lib/commands.js can be updated with generate_commands.js
commands = require("./lib/commands"),
connection_id = 0,
default_port = 6379,
default_host = "127.0.0.1",
@@ -892,40 +895,19 @@ function Multi(client, args) {
exports.Multi = Multi;
// take 2 arrays and return the union of their elements
function set_union(seta, setb) {
var obj = {};
seta.forEach(function (val) {
obj[val] = true;
});
setb.forEach(function (val) {
obj[val] = true;
});
return Object.keys(obj);
}
// This static list of commands is updated from time to time. ./lib/commands.js can be updated with generate_commands.js
commands = set_union(["get", "set", "setnx", "setex", "append", "strlen", "del", "exists", "setbit", "getbit", "setrange", "getrange", "substr",
"incr", "decr", "mget", "rpush", "lpush", "rpushx", "lpushx", "linsert", "rpop", "lpop", "brpop", "brpoplpush", "blpop", "llen", "lindex",
"lset", "lrange", "ltrim", "lrem", "rpoplpush", "sadd", "srem", "smove", "sismember", "scard", "spop", "srandmember", "sinter", "sinterstore",
"sunion", "sunionstore", "sdiff", "sdiffstore", "smembers", "zadd", "zincrby", "zrem", "zremrangebyscore", "zremrangebyrank", "zunionstore",
"zinterstore", "zrange", "zrangebyscore", "zrevrangebyscore", "zcount", "zrevrange", "zcard", "zscore", "zrank", "zrevrank", "hset", "hsetnx",
"hget", "hmset", "hmget", "hincrby", "hdel", "hlen", "hkeys", "hvals", "hgetall", "hexists", "incrby", "decrby", "getset", "mset", "msetnx",
"randomkey", "select", "move", "rename", "renamenx", "expire", "expireat", "keys", "dbsize", "auth", "ping", "echo", "save", "bgsave",
"bgrewriteaof", "shutdown", "lastsave", "type", "multi", "exec", "discard", "sync", "flushdb", "flushall", "sort", "info", "monitor", "ttl",
"persist", "slaveof", "debug", "config", "subscribe", "unsubscribe", "psubscribe", "punsubscribe", "publish", "watch", "unwatch", "cluster",
"restore", "migrate", "dump", "object", "client", "eval", "evalsha"], require("./lib/commands"));
commands.forEach(function (fullCommand) {
var command = fullCommand.split(' ')[0];
// Skip all full commands that have already been added instead of overwriting them over and over again
if (RedisClient.prototype[command]) {
return;
}
RedisClient.prototype[command] = function (args, callback) {
if (Array.isArray(args)) {
return this.send_command(command, args, callback);
} else {
return this.send_command(command, to_array(arguments));
}
return this.send_command(command, to_array(arguments));
};
RedisClient.prototype[command.toUpperCase()] = RedisClient.prototype[command];