Redis hiRedis linux安装与demo示例
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Redis hiRedis linux安装与demo示例,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1935字,纯文字阅读大概需要3分钟。
内容图文
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,int port, const char *key,const char *value,int len_value); #endif //RTSSERVER_QSS_REDIS_API_H
qss_redis_API.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "hiredis.h" int Send2Redis(const char *ip,int port, const char *key,const char *value,int len_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); goto ERR; } 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 <stdio.h> #include <stdlib.h> #include <string.h> #include "qss_redis_API.h" int main(){ char key[]="key1512"; char value[]="this is the message for test!!!"; Send2Redis("127.0.0.1", 6379, key,value,strlen(value)); }
内容总结
以上是互联网集市为您收集整理的Redis hiRedis linux安装与demo示例全部内容,希望文章能够帮你解决Redis hiRedis linux安装与demo示例所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。