0

I'm using the hiredis C client library to interact with Redis in an async context.

On some point of my workflow I have to make a Sync call to Redis but I'm not being able to get a successful response from Redis.

I'm not sure whether I can issue a sync command to Redis from an async context but...

I have something like this

redisAsyncContext * redis_ctx;
redisReply * reply;

// ...

reply = redisCommand(&(redis_ctx->c), COMMAND);

After redisCommand call, my reply is NULL what is documented as an error condition and my redis_ctx->c is like

err    = 0
errstr = '\000' <repeats 127 times>
fd     = 11
flags  = 2
obuf   = "*5\r\n$4\r\nEVAL\r\n$215\r\n\"math.randomseed(tonumber(ARGV[1])) local keys = redis.call('hkeys',KEYS[1]) if #keys == 0 then return nil end local key = keys[math.random(#keys)] local value = redis.call('hget', KEYS[1], key) return {key, value}\"\r\n$1\r\n1\r\n$0\r\n\r\n$1\r\n1\r\n"
reader = 0x943730

I can't figure out whether the command was issued or not.

PauloASilva
  • 1,000
  • 1
  • 7
  • 19

1 Answers1

0

Hope it's not too late. I'm not so expert about Redis, but if you need to make a Sync call to Redis, why would you use an AsyncContext?

If you just use redisCommand with a redisContext everything should be fine.

Assuming that variable ctx has been declared as

redisContext *ctx;

you can use redisCommand like this:

reply = (redisReply *)redisCommand(ctx, "HGET %s %s", hash, key);
Matteo Sticco
  • 131
  • 1
  • 1
  • 5
  • My point is whether it is possible to get the `redisContext` (sync) from `redisAsyncContext` (async) and then issue the `redisCommand` (sync). – PauloASilva Jan 27 '15 at 11:23
  • Have you tried to use `redisAsyncInitialize`? I'm not sure if this could be useful to what you're trying to do. Source: [link](https://github.com/redis/hiredis/blob/master/async.c) – Matteo Sticco Jan 28 '15 at 00:22
  • everything is working perfect about the async context/commands, but at some point of my workflow I want to issue a sync command what requires a redis sync context, which is available on the AsyncContext struct. If it was possible to get a sync context from an async one, I could avoid to declare another context – PauloASilva Jan 29 '15 at 13:59