mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 08:38:27 -05:00
redis-cli is now using only the new protocol
This commit is contained in:
parent
249c3a7dd1
commit
cbb87f7f8a
241
redis-cli.c
241
redis-cli.c
@ -62,115 +62,114 @@ static struct config {
|
|||||||
struct redisCommand {
|
struct redisCommand {
|
||||||
char *name;
|
char *name;
|
||||||
int arity;
|
int arity;
|
||||||
int flags;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct redisCommand cmdTable[] = {
|
static struct redisCommand cmdTable[] = {
|
||||||
{"auth",2,REDIS_CMD_INLINE},
|
{"auth",2},
|
||||||
{"get",2,REDIS_CMD_INLINE},
|
{"get",2},
|
||||||
{"set",3,REDIS_CMD_BULK},
|
{"set",3},
|
||||||
{"setnx",3,REDIS_CMD_BULK},
|
{"setnx",3},
|
||||||
{"setex",4,REDIS_CMD_BULK},
|
{"setex",4},
|
||||||
{"append",3,REDIS_CMD_BULK},
|
{"append",3},
|
||||||
{"substr",4,REDIS_CMD_INLINE},
|
{"substr",4},
|
||||||
{"del",-2,REDIS_CMD_INLINE},
|
{"del",-2},
|
||||||
{"exists",2,REDIS_CMD_INLINE},
|
{"exists",2},
|
||||||
{"incr",2,REDIS_CMD_INLINE},
|
{"incr",2},
|
||||||
{"decr",2,REDIS_CMD_INLINE},
|
{"decr",2},
|
||||||
{"rpush",3,REDIS_CMD_BULK},
|
{"rpush",3},
|
||||||
{"lpush",3,REDIS_CMD_BULK},
|
{"lpush",3},
|
||||||
{"rpop",2,REDIS_CMD_INLINE},
|
{"rpop",2},
|
||||||
{"lpop",2,REDIS_CMD_INLINE},
|
{"lpop",2},
|
||||||
{"brpop",-3,REDIS_CMD_INLINE},
|
{"brpop",-3},
|
||||||
{"blpop",-3,REDIS_CMD_INLINE},
|
{"blpop",-3},
|
||||||
{"llen",2,REDIS_CMD_INLINE},
|
{"llen",2},
|
||||||
{"lindex",3,REDIS_CMD_INLINE},
|
{"lindex",3},
|
||||||
{"lset",4,REDIS_CMD_BULK},
|
{"lset",4},
|
||||||
{"lrange",4,REDIS_CMD_INLINE},
|
{"lrange",4},
|
||||||
{"ltrim",4,REDIS_CMD_INLINE},
|
{"ltrim",4},
|
||||||
{"lrem",4,REDIS_CMD_BULK},
|
{"lrem",4},
|
||||||
{"rpoplpush",3,REDIS_CMD_BULK},
|
{"rpoplpush",3},
|
||||||
{"sadd",3,REDIS_CMD_BULK},
|
{"sadd",3},
|
||||||
{"srem",3,REDIS_CMD_BULK},
|
{"srem",3},
|
||||||
{"smove",4,REDIS_CMD_BULK},
|
{"smove",4},
|
||||||
{"sismember",3,REDIS_CMD_BULK},
|
{"sismember",3},
|
||||||
{"scard",2,REDIS_CMD_INLINE},
|
{"scard",2},
|
||||||
{"spop",2,REDIS_CMD_INLINE},
|
{"spop",2},
|
||||||
{"srandmember",2,REDIS_CMD_INLINE},
|
{"srandmember",2},
|
||||||
{"sinter",-2,REDIS_CMD_INLINE},
|
{"sinter",-2},
|
||||||
{"sinterstore",-3,REDIS_CMD_INLINE},
|
{"sinterstore",-3},
|
||||||
{"sunion",-2,REDIS_CMD_INLINE},
|
{"sunion",-2},
|
||||||
{"sunionstore",-3,REDIS_CMD_INLINE},
|
{"sunionstore",-3},
|
||||||
{"sdiff",-2,REDIS_CMD_INLINE},
|
{"sdiff",-2},
|
||||||
{"sdiffstore",-3,REDIS_CMD_INLINE},
|
{"sdiffstore",-3},
|
||||||
{"smembers",2,REDIS_CMD_INLINE},
|
{"smembers",2},
|
||||||
{"zadd",4,REDIS_CMD_BULK},
|
{"zadd",4},
|
||||||
{"zincrby",4,REDIS_CMD_BULK},
|
{"zincrby",4},
|
||||||
{"zrem",3,REDIS_CMD_BULK},
|
{"zrem",3},
|
||||||
{"zremrangebyscore",4,REDIS_CMD_INLINE},
|
{"zremrangebyscore",4},
|
||||||
{"zmerge",-3,REDIS_CMD_INLINE},
|
{"zmerge",-3},
|
||||||
{"zmergeweighed",-4,REDIS_CMD_INLINE},
|
{"zmergeweighed",-4},
|
||||||
{"zrange",-4,REDIS_CMD_INLINE},
|
{"zrange",-4},
|
||||||
{"zrank",3,REDIS_CMD_BULK},
|
{"zrank",3},
|
||||||
{"zrevrank",3,REDIS_CMD_BULK},
|
{"zrevrank",3},
|
||||||
{"zrangebyscore",-4,REDIS_CMD_INLINE},
|
{"zrangebyscore",-4},
|
||||||
{"zcount",4,REDIS_CMD_INLINE},
|
{"zcount",4},
|
||||||
{"zrevrange",-4,REDIS_CMD_INLINE},
|
{"zrevrange",-4},
|
||||||
{"zcard",2,REDIS_CMD_INLINE},
|
{"zcard",2},
|
||||||
{"zscore",3,REDIS_CMD_BULK},
|
{"zscore",3},
|
||||||
{"incrby",3,REDIS_CMD_INLINE},
|
{"incrby",3},
|
||||||
{"decrby",3,REDIS_CMD_INLINE},
|
{"decrby",3},
|
||||||
{"getset",3,REDIS_CMD_BULK},
|
{"getset",3},
|
||||||
{"randomkey",1,REDIS_CMD_INLINE},
|
{"randomkey",1},
|
||||||
{"select",2,REDIS_CMD_INLINE},
|
{"select",2},
|
||||||
{"move",3,REDIS_CMD_INLINE},
|
{"move",3},
|
||||||
{"rename",3,REDIS_CMD_INLINE},
|
{"rename",3},
|
||||||
{"renamenx",3,REDIS_CMD_INLINE},
|
{"renamenx",3},
|
||||||
{"keys",2,REDIS_CMD_INLINE},
|
{"keys",2},
|
||||||
{"dbsize",1,REDIS_CMD_INLINE},
|
{"dbsize",1},
|
||||||
{"ping",1,REDIS_CMD_INLINE},
|
{"ping",1},
|
||||||
{"echo",2,REDIS_CMD_BULK},
|
{"echo",2},
|
||||||
{"save",1,REDIS_CMD_INLINE},
|
{"save",1},
|
||||||
{"bgsave",1,REDIS_CMD_INLINE},
|
{"bgsave",1},
|
||||||
{"rewriteaof",1,REDIS_CMD_INLINE},
|
{"rewriteaof",1},
|
||||||
{"bgrewriteaof",1,REDIS_CMD_INLINE},
|
{"bgrewriteaof",1},
|
||||||
{"shutdown",1,REDIS_CMD_INLINE},
|
{"shutdown",1},
|
||||||
{"lastsave",1,REDIS_CMD_INLINE},
|
{"lastsave",1},
|
||||||
{"type",2,REDIS_CMD_INLINE},
|
{"type",2},
|
||||||
{"flushdb",1,REDIS_CMD_INLINE},
|
{"flushdb",1},
|
||||||
{"flushall",1,REDIS_CMD_INLINE},
|
{"flushall",1},
|
||||||
{"sort",-2,REDIS_CMD_INLINE},
|
{"sort",-2},
|
||||||
{"info",1,REDIS_CMD_INLINE},
|
{"info",1},
|
||||||
{"mget",-2,REDIS_CMD_INLINE},
|
{"mget",-2},
|
||||||
{"expire",3,REDIS_CMD_INLINE},
|
{"expire",3},
|
||||||
{"expireat",3,REDIS_CMD_INLINE},
|
{"expireat",3},
|
||||||
{"ttl",2,REDIS_CMD_INLINE},
|
{"ttl",2},
|
||||||
{"slaveof",3,REDIS_CMD_INLINE},
|
{"slaveof",3},
|
||||||
{"debug",-2,REDIS_CMD_INLINE},
|
{"debug",-2},
|
||||||
{"mset",-3,REDIS_CMD_MULTIBULK},
|
{"mset",-3},
|
||||||
{"msetnx",-3,REDIS_CMD_MULTIBULK},
|
{"msetnx",-3},
|
||||||
{"monitor",1,REDIS_CMD_INLINE},
|
{"monitor",1},
|
||||||
{"multi",1,REDIS_CMD_INLINE},
|
{"multi",1},
|
||||||
{"exec",1,REDIS_CMD_INLINE},
|
{"exec",1},
|
||||||
{"discard",1,REDIS_CMD_INLINE},
|
{"discard",1},
|
||||||
{"hset",4,REDIS_CMD_MULTIBULK},
|
{"hset",4},
|
||||||
{"hget",3,REDIS_CMD_BULK},
|
{"hget",3},
|
||||||
{"hmset",-4,REDIS_CMD_MULTIBULK},
|
{"hmset",-4},
|
||||||
{"hmget",-3,REDIS_CMD_MULTIBULK},
|
{"hmget",-3},
|
||||||
{"hincrby",4,REDIS_CMD_INLINE},
|
{"hincrby",4},
|
||||||
{"hdel",3,REDIS_CMD_BULK},
|
{"hdel",3},
|
||||||
{"hlen",2,REDIS_CMD_INLINE},
|
{"hlen",2},
|
||||||
{"hkeys",2,REDIS_CMD_INLINE},
|
{"hkeys",2},
|
||||||
{"hvals",2,REDIS_CMD_INLINE},
|
{"hvals",2},
|
||||||
{"hgetall",2,REDIS_CMD_INLINE},
|
{"hgetall",2},
|
||||||
{"hexists",3,REDIS_CMD_BULK},
|
{"hexists",3},
|
||||||
{"config",-2,REDIS_CMD_BULK},
|
{"config",-2},
|
||||||
{"subscribe",-2,REDIS_CMD_INLINE},
|
{"subscribe",-2},
|
||||||
{"unsubscribe",-1,REDIS_CMD_INLINE},
|
{"unsubscribe",-1},
|
||||||
{"psubscribe",-2,REDIS_CMD_INLINE},
|
{"psubscribe",-2},
|
||||||
{"punsubscribe",-1,REDIS_CMD_INLINE},
|
{"punsubscribe",-1},
|
||||||
{"publish",3,REDIS_CMD_BULK},
|
{"publish",3},
|
||||||
{NULL,0,0}
|
{NULL,0}
|
||||||
};
|
};
|
||||||
|
|
||||||
static int cliReadReply(int fd);
|
static int cliReadReply(int fd);
|
||||||
@ -379,30 +378,12 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
|
|||||||
|
|
||||||
while(repeat--) {
|
while(repeat--) {
|
||||||
/* Build the command to send */
|
/* Build the command to send */
|
||||||
cmd = sdsempty();
|
cmd = sdscatprintf(sdsempty(),"*%d\r\n",argc);
|
||||||
if (rc->flags & REDIS_CMD_MULTIBULK) {
|
for (j = 0; j < argc; j++) {
|
||||||
cmd = sdscatprintf(cmd,"*%d\r\n",argc);
|
cmd = sdscatprintf(cmd,"$%lu\r\n",
|
||||||
for (j = 0; j < argc; j++) {
|
(unsigned long)sdslen(argv[j]));
|
||||||
cmd = sdscatprintf(cmd,"$%lu\r\n",
|
cmd = sdscatlen(cmd,argv[j],sdslen(argv[j]));
|
||||||
(unsigned long)sdslen(argv[j]));
|
cmd = sdscatlen(cmd,"\r\n",2);
|
||||||
cmd = sdscatlen(cmd,argv[j],sdslen(argv[j]));
|
|
||||||
cmd = sdscatlen(cmd,"\r\n",2);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (j = 0; j < argc; j++) {
|
|
||||||
if (j != 0) cmd = sdscat(cmd," ");
|
|
||||||
if (j == argc-1 && rc->flags & REDIS_CMD_BULK) {
|
|
||||||
cmd = sdscatprintf(cmd,"%lu",
|
|
||||||
(unsigned long)sdslen(argv[j]));
|
|
||||||
} else {
|
|
||||||
cmd = sdscatlen(cmd,argv[j],sdslen(argv[j]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cmd = sdscat(cmd,"\r\n");
|
|
||||||
if (rc->flags & REDIS_CMD_BULK) {
|
|
||||||
cmd = sdscatlen(cmd,argv[argc-1],sdslen(argv[argc-1]));
|
|
||||||
cmd = sdscatlen(cmd,"\r\n",2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
anetWrite(fd,cmd,sdslen(cmd));
|
anetWrite(fd,cmd,sdslen(cmd));
|
||||||
sdsfree(cmd);
|
sdsfree(cmd);
|
||||||
|
Loading…
Reference in New Issue
Block a user