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.

4

1 回答 1

0

希望还不算太晚。我对 Redis 不是很熟悉,但是如果您需要对 Redis 进行同步调用,为什么要使用 AsyncContext?

如果您只是将 redisCommand 与 redisContext 一起使用,那么一切都应该没问题。

假设变量ctx已被声明为

redisContext *ctx;

你可以redisCommand这样使用:

reply = (redisReply *)redisCommand(ctx, "HGET %s %s", hash, key);
于 2015-01-26T23:07:59.203 回答