一. hiredis下载地址及C API  github下载:https://github.com/redis/hiredis

安装脚本:

#!/bin/zsh
git clone https://github.com/redis/hiredis.git
cd hiredis
make
make install

二. 文件pc,我是把libhiredis.so放到/usr/local/lib/中,把hiredis.h放到/usr/local/inlcude/hiredis/中的。

三. redis启动关闭

    服务启动:redis-server   

    客户端连接:redis-cli

    客户端关闭:redis-cli shutdown
四. hiredis测试:
 1 #include <stdio.h> 
 2 #include <hiredis/hiredis.h> 
 3 int main() 
 4 { 
 5      redisContext *conn  = redisConnect("127.0.0.1",6379); 
 6      if(conn != NULL && conn->err) 
 7      {   
 8          printf("connection error: %s\n",conn->errstr); 
 9          return 0; 
10      }   
11      redisReply *reply = (redisReply*)redisCommand(conn,"set foo 1234"); 
12      freeReplyObject(reply); 
13              
14      reply = redisCommand(conn,"get foo"); 
15      printf("%s\n",reply->str); 
16      freeReplyObject(reply); 
17              
18      redisFree(conn); 
19      return 0; 
20 }

编译:gcc -o  redis_test redis_test.c -L/usr/local/lib/ -lhiredis

 

相关文章:

  • 2022-12-23
  • 2021-08-12
  • 2021-06-28
  • 2022-02-12
  • 2022-02-27
  • 2022-12-23
  • 2021-05-16
  • 2021-10-23
猜你喜欢
  • 2021-09-03
  • 2021-06-12
  • 2021-04-28
  • 2022-12-23
  • 2022-01-17
  • 2021-11-23
相关资源
相似解决方案