同步调用
连接
cpp
redisContext* redisConnect(constchar*ip,intport);
发送命令并且获取响应
cpp
void *redisCommand(redisContext *c, const char *format, ...);
void *redisvCommand(redisContext *c, const char *format, va_list ap);
void *redisCommandArgv(redisContext *c, int argc, const char **argv, const size_t *argvlen);
返回的结果结构体为
cpp
typedef struct redisReply {
int type; /* REDIS_REPLY_* */
long long integer; /* The integer when type is REDIS_REPLY_INTEGER */
int len; /* Length of string */
char *str; /* Used for both REDIS_REPLY_ERROR and REDIS_REPLY_STRING */
size_t elements; /* number of elements, for REDIS_REPLY_ARRAY */
struct redisReply **element; /* elements vector for REDIS_REPLY_ARRAY */
} redisRepl
type支持的值有
- REDIS_REPLY_STRING
- REDIS_REPLY_ARRAY
- REDIS_REPLY_INTEGER
- REDIS_REPLY_NIL
- REDIS_REPLY_STATUS
- REDIS_REPLY_ERROR
阻塞模式下的管道命令
将命令写入输出缓冲区,也是在阻塞模式下的命令管道
cpp
int redisvAppendCommand(redisContext *c, const char *format, va_list ap);
int redisAppendCommand(redisContext *c, const char *format, ...);
int redisAppendCommandArgv(redisContext *c, int argc, const char **argv, const size_t *argvlen);
获取响应
cpp
int redisGetReply(redisContext *c, void **reply);
int redisGetReplyFromReader(redisContext *c, void **reply);
释放响应对象
cpp
void freeReplyObject(void *reply)