Any ideas on HGET return zero(c/c++ program with hiredis)?

347 views
Skip to first unread message

Ricky Leo

unread,
Oct 30, 2014, 1:51:46 AM10/30/14
to redi...@googlegroups.com
I am encountering a circumstance that I have set a hash field&value like 

HSET test field1 value1

and I can get the value correctly in the redis-cli, 


but when I run the command in my own program, it always returns "0", but there maybe one correct in 5 executes, I am using the  hiredis in c++ program, 

/* This is the reply object returned by redisCommand() */
typedef struct redisReply {
    int type; /* REDIS_REPLY_* */
    long long integer; /* The integer when type is REDIS_REPLY_INTEGER */
    int len; /* Length of string */
    char *str; /* Used for both REDIS_REPLY_ERROR and REDIS_REPLY_STRING */
    size_t elements; /* number of elements, for REDIS_REPLY_ARRAY */
    struct redisReply **element; /* elements vector for REDIS_REPLY_ARRAY */
} redisReply;

This is the redisReply structure from the hiredis.h, I print the type and it's 1(REDIS_REPLY_STRING), but there is nothing in the str.

I do not know if had do someting wrong, any ideas will be appreciated, thanks!


Paulino Huerta

unread,
Oct 30, 2014, 2:03:23 PM10/30/14
to redi...@googlegroups.com
Hi,

You should put the code snippet, otherwise it is difficult.
You can get the value of "reply-> len"
when "reply-> str" contains "value" is 5, but if "0" ...? maybe it
helps the debugging.

--Paulino

2014-10-30 6:51 GMT+01:00, Ricky Leo <rick...@gmail.com>:
> I am encountering a circumstance that I have set a hash field&value like
>
> HSET test field1 value1
>
> and I can get the value correctly in the redis-cli,
> <https://lh3.googleusercontent.com/-qtxhCNwcEkM/VFHQhe6AQYI/AAAAAAAAAAw/JaQIDJYTi3g/s1600/QQ%E5%9B%BE%E7%89%8720141030134206.jpg>
>
>
> but when I run the command in my own program, it always returns "0", but
> there maybe one correct in 5 executes, I am using the hiredis in c++
> program,
> <https://lh3.googleusercontent.com/-Zj-LzztZ-X4/VFHRGAC1l7I/AAAAAAAAABA/11PSC8DWDOI/s1600/QQ%E5%9B%BE%E7%89%8720141030134748.png>
>
> /* This is the reply object returned by redisCommand() */
> typedef struct redisReply {
> int type; /* REDIS_REPLY_* */
> long long integer; /* The integer when type is REDIS_REPLY_INTEGER */
> int len; /* Length of string */
> char *str; /* Used for both REDIS_REPLY_ERROR and REDIS_REPLY_STRING */
> size_t elements; /* number of elements, for REDIS_REPLY_ARRAY */
> struct redisReply **element; /* elements vector for REDIS_REPLY_ARRAY
> */
> } redisReply;
>
> This is the redisReply structure from the hiredis.h, I print the type and
> it's 1(REDIS_REPLY_STRING), but there is nothing in the str.
>
> I do not know if had do someting wrong, any ideas will be appreciated,
> thanks!
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Redis DB" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to redis-db+u...@googlegroups.com.
> To post to this group, send email to redi...@googlegroups.com.
> Visit this group at http://groups.google.com/group/redis-db.
> For more options, visit https://groups.google.com/d/optout.
>

Ricky Leo

unread,
Oct 31, 2014, 2:28:17 AM10/31/14
to redi...@googlegroups.com
Thanks for your reply, I have sloved the problem, the reason is I had been using one redis connection object in multiple threads, after I added a lock in every thread it works well.
Reply all
Reply to author
Forward
0 new messages