#include
#include
#include
#include
#define CMD_MAX_LENGHT 256
typedef enum USE_RESULT
{
SUCCESS=0,
FAILURE=1
}USE_RESULT;
USE_RESULT LrangeUseBySid(char *sid);
USE_RESULT exeRedisStrCmd(char *cmd);
int main()
{
redisContext* context = redisConnect("127.0.0.1",6379);
if(context->err)
{
printf("connecttion error:%s\n",context->errstr);
return FAILURE;
}
printf("connect redis server success\n");
USE_RESULT LrangeUseBySid(char *sid)
{
char cmd[CMD_MAX_LENGHT] = {0};
if(NULL==sid)
{
printf("%d NULL pointer\n",__LINE__);
return FAILURE;
}
snprintf(cmd,CMD_MAX_LENGHT,"LRANGE ACCTMSG:%s,%s",sid);
}
USE_RESULT exeRedisStrCmd(char *cmd)
{
if(NULL == cmd)
{
printf("NULL pointer");
return FAILURE;
}
redisReply *reply = (redisReply *)redisCommand(context, cmd);
if(NULL == reply)
{
printf("%d execute command:%s failure\n",__LINE__,cmd);
redisFree(context);
return FAILURE;
}
if(!(reply->type == REDIS_REPLY_ARRAY && reply->elements > 0))
{
printf("%d execute command:%s failure\n",__LINE__, cmd);
freeReplyObject(reply);
redisFree(context);
return FAILURE;
}
printf("%d,%lu\n",reply->type,reply->elements);
int i = 0;
for(i=0;i < reply->elements;i++)
{
if(i%2 ==0)
{
printf("%s:",reply->element[i]->str);
}
else
{
printf("%s\n",reply->element[i]->str);
}
}
freeReplyObject(reply);
redisFree(context);
return SUCCESS;
}
LrangeUseBySid("1 10");
return 0;
}