如果你想推到列表是固定的元素個數:使用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);
你怎麼叫redisComand?任何示例? –
添加了示例 –