1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-04 15:02:09 +03:00

Developing the 'somehow' in 'This list [of commands] needs to be updated, and perhaps auto-updated somehow'

This commit is contained in:
Dave Hoover
2011-06-02 21:12:13 -05:00
parent c73af8d477
commit e210755b52
3 changed files with 173 additions and 23 deletions

43
generate_commands.js Normal file
View File

@@ -0,0 +1,43 @@
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 ";
fileContents += prettyCurrentTime();
fileContents += "\nCommands = [\n";
var lowerCommands = [];
for (var command in commands) {
lowerCommands.push(" \"" + command.toLowerCase() + "\"");
}
fileContents += lowerCommands.join(",\n");
fileContents += "\n];\n\n"
fileContents += "exports.Commands = Commands;"
fs.writeFile(path, fileContents);
}
function prettyCurrentTime() {
var date = new Date();
return date.toLocaleString();
}

View File

@@ -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

128
lib/commands.js Normal file
View File

@@ -0,0 +1,128 @@
// This file was generated by ./generate_commands.js on Thu Jun 02 2011 21:09:35 GMT-0500 (CDT)
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"
];
exports.Commands = Commands;