| windows | linux | ||
| redis下载 | redis-plus-plus-master.zip文件的下载 | http://download.redis.io/releases/redis-7.2.0.tar.gz tar -zxvf redis-7.2.0.tar.gz //-z:gzip属性 ;-x:解压;-v:显示;-f:文件 make make install //make distclean | |
| hiredis下载 | hiredis-master.zip文件的下载 https://github.com/redis/hiredis.git | ||
| 安装与编译 |
1.hiredis cmake | ||
| 编译后生成的文件 |
| ||
| 需要添加的头文件和源文件 | 1.工程->属性->C++->附加包含目录: 原始下载的hiredis-master下的D:\IPS3000\tangfiles\linux\centos-src-9-74\hiredis\hiredis-master 2.工程->属性->链接器->输入 ..\Debug\hiredisd.lib 3. | GitHub - redis/hiredis: Minimalistic C client for Redis >= 1.2 | |
| 重要的函数 | 重要的函数就3个: redisContext *redisConnect(const char *ip, int port); void *redisCommand(redisContext *c, const char *format, ...); void freeReplyObject(void *reply); |
1.1 hiredis
GitHub - sewenew/redis-plus-plus: Redis client written in C++
https://github.com/sewenew/redis-plus-plus
1.2 redis官网下载+安装+编译
如果下的是7的版本,不需要下hiredis.直接编译即可。
- $ wget http://download.redis.io/releases/redis-7.2.0.tar.gz
- $ tar -zxvf redis-7.2.0.tar.gz
- # -z:gzip x:解压 v:显示所有过程 f:文件
- $ cd redis-7.2.0
- $ make
- $ make install
-
- $ redis-server
- $ redis-cli
-
-
- 默认的安装目录:/usr/local/redis
- /usr/
-
- /usr/local/include
- /usr/local/lib
- /usr/local/lib/pkgconfig
错误提示:
1./bin/sh: 1: pkg-config: not found
apt-get install pkg-config
make distclean && make
srv/ftp/
- #1.ubuntu 下安装tftp
- apt-get install vsftpd
- apt-get install ftp
-
-
-
- #2.修改配置文件
- vim /etc/vsftpd.conf
- local_enables=YES
- write_enable=YES
- anonymous_enable=YES
- anon_mkdir_write_enable=YES //允许匿名用户在FTP上创建目录
- anon_upload_enable=YES //允许匿名用户在FTP服务器上上传文件
- anon_other_write_enable=YES //开启匿名用户的其他写权限
-
-
- #不要用root 或者 anonymous访问
-
-
1.1make 之前
| 5.0.14 | 7.2.0 | ||
| make | 1.deps/jemalloc 多了lib文件夹 2.deps/lua/ 多了.o文件 3.src 下多了.o文件 | make test | |
| 两个版本的对比: | 1.deps/fpconv 2.deps/hdr_histogram 3.deps/hiredis :ssl sockcompat 4.src/commands 5.src/ 多了好多函数 | ||
| make install | 之前bin,lib,inlcude3个文件夹下什么都没有。 | 1.redis-7.2.0/src下有6个应用程序redis-server 只保留一个版本。 无 | |
| 所有文件在目录下: /home/tang/redis-5.0.14 | |||
| 配置文件: | /home/tang/redis-5.0.14/redis.conf | ||
| 日志文件: | /var/log/redis/redis-server.log |
1.make 前后的对比

2.5版本和7版本的对比
2.1 src下启动
cd redis7/src
redis-server
redis-cli
- ./src/redis-cli
- #带Host、Port、Auth连接: ./src/redis-cli -h 127.0.0.1 -p 6379 -a 123456
2.2 修改环境变量
/etc/profile
https://github.com/redis/hiredis
- #1.创建一个放工程文件的文件夹 与redis安装包同级别
- mkdir /home/tang/redisprj
- #2.修改环境变量
- vim ~/.bashrc
- source .bashrc
-
- vim /etc/profile
-
- #2.1 动态库+静态库链接库文件
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/tang/redis-7.2.0/deps/hiredis
- export LIBRARY_PATH=$LIBRARY_PATH
- #2.2 头文件
- #gcc头文件
- export C_INCLUDE_PATH=/usr/include
- #g++找到头文件的路径
- export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/include
- #2.3 可执行文件
- export PATH =$PATH:/home/tang/redis-7.2.0/src
-
- # 安装软件放在 /usr/local/include下
1. 编写一个最基本的c文件。
1.1编写test_main00.c,只输出一个字符串。
- #include
- int main()
- {
- printf("my test_main.c\n");
- return 0;
- }
1.2编译运行,看是否正常输出。
- 编译运行
- gcc test_main00.c -o testmain # -o 编译后的应用程序名,可以有后缀也可以没有后缀
- ./testmain # 运行程序 ./表示当前文件夹
2.编写1个调用hiredis set和get 的c文件
2.1 编写文件
- //1.连接
- //2.发送
- //3.处理返回
- //4.清空
- #include
- #include
- #include
- #include
- void main()
- {
- redisContext *pc = redisConnect("127.0.0.1", 6379); //1.连接
- if (pc == NULL || pc->err)
- {
- if (pc)
- {
- printf("Error: %s\n", pc->errstr);
- }
- else
- {
- printf("Can't allocate redis context\n");
- }
- }
-
- redisReply *psetreply;
- psetreply= redisCommand(pc, "PING"); //2.发送PING
- printf("PING: %s\n", psetreply->str);
- freeReplyObject(psetreply);
-
- psetreply= redisCommand(pc, "SET %s %s", "foo", "hello world"); //2.发送SET
- printf("SET: %s\n", psetreply->str);
- freeReplyObject(psetreply);
-
- psetreply= redisCommand(pc, "SET %b %b", "bar", (size_t) 3, "hello", (size_t) 5); //2.发送
- printf("SET (binary API): %s\n", psetreply->str);
- freeReplyObject( psetreply);
-
-
- // reply = redisCommand(context, "SET foo %s", value);
- // reply = redisCommand(context, "SET foo %b", value, (size_t) valuelen);
- // reply = redisCommand(context, "SET key:%s %s", myid, value);
-
-
- //4.清空
- redisFree(pc);
-
- //5.get();
- }
- //1.连接
- //2.发送
- //3.处理返回
- //4.清空
-
- void get()
- {
-
- redisContext *c = redisConnect("127.0.0.1", 6379); //1.连接
- if (c == NULL || c->err)
- {
- if (c)
- {
- printf("Error: %s\n", c->errstr);
- }
- else
- {
- printf("Can't allocate redis context\n");
- }
- }
-
- redisReply *pgetreply;
- pgetreply= redisCommand(c, "GET foo"); //2.GET foo
- printf("GET foo: %s\n", pgetreply->str);
- freeReplyObject(pgetreply);
-
- pgetreply= redisCommand(c, "INCR counter"); //2.GET
- printf("INCR counter: %lld\n", pgetreply->integer);
- freeReplyObject(pgetreply);
-
- pgetreply= redisCommand(c,"INCR counter");
- printf("INCR counter: %lld\n", pgetreply->integer);
- freeReplyObject(pgetreply);
-
- redisReply *reply ;
- /* Create a list of numbers, from 0 to 9 */
- reply = redisCommand(c,"DEL mylist");
- freeReplyObject(reply);
- for (int j = 0; j < 10; j++) {
- char buf[64];
-
- snprintf(buf,64,"%u",j);
- reply = redisCommand(c,"LPUSH mylist element-%s", buf);
- freeReplyObject(reply);
- }
-
- /* Let's check what we have inside the list */
- reply = redisCommand(c,"LRANGE mylist 0 -1");
- if (reply->type == REDIS_REPLY_ARRAY)
- {
- for ( int j = 0; j < reply->elements; j++) {
- printf("%u) %s\n", j, reply->element[j]->str);
- }
- }
- //4.清空
- redisFree(c);
- }
2.2 编译输出
gcc redis_mainsetget01.c -o redis_mainsetget01 -L/home/tang/redis-7.2.0/deps/hiredis -lhiredis
2.3 远程连接
redis-cli -h [IP地址] -p [PORT端口号] -a [密码password]