C++使用hiredis连接带密码的redis服务


 1 c = redisConnect((char*)redis_host, redis_port);
 2 if (c->err) {    /* Error flags, 0 when there is no error */
 3 printf("连接Redis失败: %s\n", c->errstr);
 4 exit(1);
 5 }
 6 else
 7 {
 8 printf("连接Redis成功!\n");
 9 }
10 
11 reply = (redisReply *)redisCommand(c, "AUTH %s", redis_password);
12 if (reply->type == REDIS_REPLY_ERROR) {
13 printf("Redis认证失败!\n");
14 }
15 else
16 {
17 printf("Redis认证成功!\n");
18 }
19 freeReplyObject(reply);

就是在正常连接服务后加上auth命令传入密码


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM