1
我無法使用credis_connect()
連接到使用默認選項(127.0.0.1:6379)運行的redis服務器。以下是我使用的測試代碼:無法連接到redis服務器
#include <stdio.h>
#include "credis.h"
int main(int argc, char **argv)
{
REDIS rh;
char *val;
int rc;
printf("connecting to server at Port:6379\n");
rh = credis_connect(NULL, 6379, 10000);
if(rh == NULL)
{
printf("Error in connecting to server.\n");
return -1;
}
printf("Connected to Redis Server. \n");
/* ping server */
rc = credis_ping(rh);
printf("ping returned: %d\n", rc);
/* set value of key "kalle" to "kula" */
printf("Setting Key value to Redis Server.\n");
credis_set(rh, "kalle", "kula");
printf("Key value is set.\n");
/* get value of key "kalle" */
credis_get(rh, "kalle", &val);
printf("get kalle returned: %s\n", val);
/* close connection to redis server */
credis_close(rh);
return 0;
}
僅供參考:我在ubuntu 12.10上運行redis 2.6.10和credis 0.2.3。
您是否成功地通過使用CLI運行代碼的同一臺機器進行連接? – 2013-05-06 12:39:01