diff --git a/generate_commands.js b/generate_commands.js new file mode 100644 index 0000000..b06dd22 --- /dev/null +++ b/generate_commands.js @@ -0,0 +1,39 @@ +var http = require("http"), + sys = require("sys"), + fs = require("fs"); + +http.get({host: "redis.io", path: "/commands.json"}, function(res) { + console.log("Response from redis.io/commands.json: " + res.statusCode); + + var commandString = ""; + res.on('data', function(chunk) { + commandString += chunk; + }); + + res.on('end', function() { + var commands = JSON.parse(commandString); + writeCommandsToFile(commands, "lib/commands.js"); + }) +}).on('error', function(e) { + console.log("Got error: " + e.message); +}); + +function writeCommandsToFile(commands, path) { + console.log("Writing " + path); + + var fileContents = "// This file was generated by ./generate_commands.js on " + prettyCurrentTime() + "\n"; + + var lowerCommands = []; + for (var command in commands) { + lowerCommands.push(command.toLowerCase()); + } + + fileContents += "exports.Commands = " + JSON.stringify(lowerCommands, null, " ") + ";\n"; + + fs.writeFile(path, fileContents); +} + +function prettyCurrentTime() { + var date = new Date(); + return date.toLocaleString(); +} \ No newline at end of file diff --git a/index.js b/index.js index c4f8611..85e930a 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ /*global Buffer require exports console setTimeout */ var net = require("net"), + Commands = require("./lib/commands").Commands, util = require("./lib/util").util, Queue = require("./lib/queue").Queue, to_array = require("./lib/to_array"), @@ -568,29 +569,7 @@ function Multi(client, args) { } } -// Official source is: http://redis.io/commands.json -// This list needs to be updated, and perhaps auto-updated somehow. -[ - // string commands - "get", "set", "setnx", "setex", "append", "substr", "strlen", "del", "exists", "incr", "decr", "mget", - // list commands - "rpush", "lpush", "rpushx", "lpushx", "linsert", "rpop", "lpop", "brpop", "blpop", "brpoplpush", "llen", "lindex", "lset", "lrange", - "ltrim", "lrem", "rpoplpush", - // set commands - "sadd", "srem", "smove", "sismember", "scard", "spop", "srandmember", "sinter", "sinterstore", "sunion", "sunionstore", "sdiff", "sdiffstore", "smembers", - // sorted set commands - "zadd", "zincrby", "zrem", "zremrangebyscore", "zremrangebyrank", "zunionstore", "zinterstore", "zrange", "zrangebyscore", "zrevrangebyscore", - "zcount", "zrevrange", "zcard", "zscore", "zrank", "zrevrank", - // hash commands - "hset", "hsetnx", "hget", "hmget", "hincrby", "hdel", "hlen", "hkeys", "hvals", "hgetall", "hexists", "incrby", "decrby", - //bit commands - "getbit", "setbit", "getrange", "setrange", - // misc - "getset", "mset", "msetnx", "randomkey", "select", "move", "rename", "renamenx", "expire", "expireat", "keys", "dbsize", "ping", "echo", - "save", "bgsave", "bgwriteaof", "shutdown", "lastsave", "type", "sync", "flushdb", "flushall", "sort", "info", "discard", - "monitor", "ttl", "persist", "slaveof", "debug", "config", "subscribe", "unsubscribe", "psubscribe", "punsubscribe", "publish", "watch", "unwatch", - "quit" -].forEach(function (command) { +Commands.forEach(function (command) { RedisClient.prototype[command] = function () { var args = to_array(arguments); args.unshift(command); // put command at the beginning diff --git a/lib/commands.js b/lib/commands.js new file mode 100644 index 0000000..d785a50 --- /dev/null +++ b/lib/commands.js @@ -0,0 +1,126 @@ +// This file was generated by ./generate_commands.js on Thu Jun 02 2011 21:50:36 GMT-0500 (CDT) +exports.Commands = [ + "append", + "auth", + "bgrewriteaof", + "bgsave", + "blpop", + "brpop", + "brpoplpush", + "config get", + "config set", + "config resetstat", + "dbsize", + "debug object", + "debug segfault", + "decr", + "decrby", + "del", + "discard", + "echo", + "exec", + "exists", + "expire", + "expireat", + "flushall", + "flushdb", + "get", + "getbit", + "getrange", + "getset", + "hdel", + "hexists", + "hget", + "hgetall", + "hincrby", + "hkeys", + "hlen", + "hmget", + "hmset", + "hset", + "hsetnx", + "hvals", + "incr", + "incrby", + "info", + "keys", + "lastsave", + "lindex", + "linsert", + "llen", + "lpop", + "lpush", + "lpushx", + "lrange", + "lrem", + "lset", + "ltrim", + "mget", + "monitor", + "move", + "mset", + "msetnx", + "multi", + "object", + "persist", + "ping", + "psubscribe", + "publish", + "punsubscribe", + "quit", + "randomkey", + "rename", + "renamenx", + "rpop", + "rpoplpush", + "rpush", + "rpushx", + "sadd", + "save", + "scard", + "sdiff", + "sdiffstore", + "select", + "set", + "setbit", + "setex", + "setnx", + "setrange", + "shutdown", + "sinter", + "sinterstore", + "sismember", + "slaveof", + "smembers", + "smove", + "sort", + "spop", + "srandmember", + "srem", + "strlen", + "subscribe", + "sunion", + "sunionstore", + "sync", + "ttl", + "type", + "unsubscribe", + "unwatch", + "watch", + "zadd", + "zcard", + "zcount", + "zincrby", + "zinterstore", + "zrange", + "zrangebyscore", + "zrank", + "zrem", + "zremrangebyrank", + "zremrangebyscore", + "zrevrange", + "zrevrangebyscore", + "zrevrank", + "zscore", + "zunionstore" +];