源码不长,五分钟就都能翻出来。

void* redisCommand(redisContext c,const char format,...); 

返回值是一个void类型的指针,实际为指向一个redisReply类型的指针

redisReply结构体定义如下:

/* This is the reply object returned by redisCommand() */
typedef struct redisReply {
    int type; /* REDIS_REPLY_* */
    long long integer; /* The integer when type is REDIS_REPLY_INTEGER */
    size_t 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 */
} redisReply;

下面是几种redis的常见错误及返回值类型:

#define REDIS_ERR -1
#define REDIS_OK 0
 
//错误码
#define REDIS_ERR_IO 1 /* Error in read or write */
#define REDIS_ERR_EOF 3 /* End of file */
#define REDIS_ERR_PROTOCOL 4 /* Protocol error */
#define REDIS_ERR_OOM 5 /* Out of memory */
#define REDIS_ERR_OTHER 2 /* Everything else... */
 
//OK码
#define REDIS_REPLY_STRING 1    //存放在char *str
#define REDIS_REPLY_ARRAY 2		 //存储数组
#define REDIS_REPLY_INTEGER 3   //integer存储为数据条数
#define REDIS_REPLY_NIL 4			 // null值
#define REDIS_REPLY_STATUS 5   //成功状态码为:"OK"  存放在char *str
#define REDIS_REPLY_ERROR 6    //存放在char *str

在这里插入图片描述

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐