函數(shù)公式 C 中訪問redis,用hiredis接口可以指定密碼嗎?
C 中訪問redis,用hiredis接口可以指定密碼嗎?redisContext*c=redisConnect(“hostname”,port)if(c!=NULL&&;c->er
C 中訪問redis,用hiredis接口可以指定密碼嗎?
redisContext*c=redisConnect(“hostname”,port)if(c!=NULL&&;c->err){printf(“Error:%sn”,c->errstr)//handle Error}否則{printf(“Connected to Redisn”)redisReply*replyreply=redisCommand(c,“AUTH Password”)freereplyobject(reply)。。。Redisfree(c)
hiredis可以通過設(shè)置密碼連接到redis服務(wù)器。但是,在連接過程中沒有指定密碼,但是在連接成功后,可以通過發(fā)送“auth”命令來指定密碼。如以上代碼所示。