hiredis and uint16_t

90 views
Skip to first unread message

Brian Knox

unread,
Nov 28, 2012, 10:45:56 AM11/28/12
to redi...@googlegroups.com
I've run into a slight issue that I can't figure out in regards to storing integers in redis.  I'm inserting some uint16_t's using the hiredis C client.  Things are going in fine, and when I check the values from the command line, the values in redis appear correct.

However, I'm doing something wrong retrieving the records and was looking for a little help.

My insert command is:

redisAppendCommand ( self->rctx, "SADD %lu %d",
                self->interval, self->data );

self->data is defined within a struct as:

uint16_t data;

Looking within my set with SMEMBERS, the data looks good.

Retrieving the data with:

redisReply *reply = redisCommand ( self->rctx,
                "SMEMBERS %lu", self->interval );

And then iterating over the replies:

for (i=0, i<reply->elements, i++) {
}

How do I properly retrieve reply->element[i] (which should be the uint16_t I stored) properly so that I retrieve the correct value?

Thanks for any help,
Brian




Brian Knox

unread,
Nov 28, 2012, 10:57:32 AM11/28/12
to redi...@googlegroups.com
Aha - as always, I figured it out 5 minutes after sending a question to the list.

reply->elements will contain an array of redisReply's.
reply->element[i]->str will have a string representation of the uint16_t.

Brian
Reply all
Reply to author
Forward
0 new messages