如果要推送到列表的元素数量是固定的:redisCommand
与格式化参数一起使用
const char *list = "list-name";
const char *non_empty_val = "value";
const char *empty_val = "";
/* or use %b to push binary element, as the other answer mentioned. */
redisReply *reply = (redisReply*)redisCommand(redis,
"lpush %s %s %s", list, non_empty_val, empty_val);
如果元素的数量是动态的:使用redisCommandArgv
int argc = 4; /* number of arguments including command name. */
const char **argv = (const char**)malloc(sizeof(const char**) * argc);
argv[0] = strdup("lpush");
argv[1] = strdup(list);
argv[2] = strdup(non_empty_val);
argv[3] = strdup(empty_val);
/* specify the length of each argument. */
size_t *argv_len = (size_t*)malloc(sizeof(size_t) * argc);
for (int i = 0; i < argc; ++i)
argv_len[i] = strlen(argv[i]);
redisReply *reply = (redisReply*)redisCommandArgv(redis, argc, argv, argv_len);