microsoftarchive / redis

Redis is an in-memory database that persists on disk. The data model is key-value, but many different kind of values are supported: Strings, Lists, Sets, Sorted Sets, Hashes
http://redis.io
Other
20.78k stars 5.37k forks source link

Can't get binary data (string) from hiredis, Emergency! #585

Closed liuzhuoling2011 closed 6 years ago

liuzhuoling2011 commented 6 years ago

Currently I face a problem witch makes me so confusing, when I get binary data (string) from redis: reply->type=1, reply->len=296, reply->str="" Therefor, I can't get anything from hiredis reply. I use the same command in redis-cli, it will return the binary data. 1 2

tporadowski commented 6 years ago

Just guessing - isn't it showing the string because of first 0 byte (\x00) which simply leads to ""?

liuzhuoling2011 commented 6 years ago

Strings in C are null-terminated, so if you print them they will be empty if there are only null values in it. The length however is correct, so you can safely copy out the necessary data (only zeroes in this case)