1

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.

1
  • Did you succeed connecting from the same machine that runs your code using the CLI ? Commented May 6, 2013 at 12:39

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.