Reputation: 433
I am unable to connect to redis server running with default options (127.0.0.1:6379) using credis_connect()
. Here is the test code I used:
#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;
}
FYI: I am running redis 2.6.10 and credis 0.2.3 on ubuntu 12.10.
Upvotes: 1
Views: 2481
Reputation: 73206
I don't think credis 0-2-3 can work with modern Redis version (2.6). credis 0-2-3 was released in 2010, and Redis has evolved a lot.
Connection fails because credis needs to parse the output of the INFO command just after socket connection. Purpose is to retrieve the Redis server version. Because the output of INFO has changed (it is now including comments to isolate sections), credis is not able anymore to extract the version, so it returns an error.
If you want to fix this specific issue (but there may be many others ...) you just have to edit credis.c source code and replace:
int items = sscanf(rhnd->reply.bulk,
"redis_version:%d.%d.%d\r\n",
&(rhnd->version.major),
&(rhnd->version.minor),
&(rhnd->version.patch));
by:
int items = sscanf(rhnd->reply.bulk,
"# Server\nredis_version:%d.%d.%d\r\n",
&(rhnd->version.major),
&(rhnd->version.minor),
&(rhnd->version.patch));
My suggestion would be to switch to hiredis, which is the official C client.
Upvotes: 1