linux hiredis升级,Redis hiRedis linux安装与demo示例

Redis

1. wget http://download.redis.io/releases/redis-4.0.8.tar.gz

2. tar xzvf redis-4.0.8.tar.gz

3.

cd redis-4.0.8

make

cd src

make install #PREFIX=/usr/local/redis

export LD_LIBRARY_PATH=/usr/local/lib #or modify bash_profile

4.

cd ../

mkdir /usr/local/redis/etc

mv redis.conf /usr/local/redis/etc

5.

cd /usr/local/redis/bin

./redis-server

./redis-cli

6.

keys *

set key1 "tom"

get key1

7.

HIRedis

https://github.com/redis/hiredis

download zip

unzip and make

qss_redis_API.h

#ifndef RTSSERVER_QSS_REDIS_API_H#define RTSSERVER_QSS_REDIS_API_H

int Send2Redis(const char *ip,intport,const char *key,const char *value,intlen_value);#endif //RTSSERVER_QSS_REDIS_API_H

qss_redis_API.c

#include #include#include#include"hiredis.h"

int Send2Redis(const char *ip,intport,const char *key,const char *value,intlen_value){

printf("Enter Send2Redis\n");

redisContext*context =redisConnect(ip, port);if (context == NULL || context->err) {if(context) {

printf("Error: %s\n", context->errstr);//handle error

return -1;

}else{

printf("Can't allocate redis context\n");return -2;

}

}

printf("send date key:[%s] value[%d]:[%s]\n",key,len_value,value);

redisReply*reply;

redisAppendCommand(context,"SET %s %b",key, value, (size_t) len_value);if(REDIS_OK != redisGetReply(context,(void**)&reply))//reply for SET

{

printf("ERR:after set: reply:[%s]\n",reply->str);

freeReplyObject(reply);gotoERR;

}

printf("after set: reply:[%s]\n",reply->str);

freeReplyObject(reply);//redisAppendCommand(context, "GET %s ",key);//redisGetReply(context,(void**)&reply);//reply for SET//printf("after GET: reply:[%s]\n",reply->str);//freeReplyObject(reply);

printf("return \n");

ERR:

redisFree(context);

}

main.c

#include #include#include#include"qss_redis_API.h"

intmain(){char key[]="key1512";char value[]="this is the message for test!!!";

Send2Redis("127.0.0.1", 6379,

key,value,strlen(value));

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值