1 c = redisConnect((char*)redis_host, redis_port); 2 if (c->err) { /* Error flags, 0 when there is no error */ 3 printf("连接Redis失败: %s ", c->errstr); 4 exit(1); 5 } 6 else 7 { 8 printf("连接Redis成功! "); 9 } 10 11 reply = (redisReply *)redisCommand(c, "AUTH %s", redis_password); 12 if (reply->type == REDIS_REPLY_ERROR) { 13 printf("Redis认证失败! "); 14 } 15 else 16 { 17 printf("Redis认证成功! "); 18 } 19 freeReplyObject(reply);
就是在正常连接服务后加上auth命令传入密码