hiredis-rb icon indicating copy to clipboard operation
hiredis-rb copied to clipboard

Configurable encoding for Hiredis::Reader

Open pietern opened this issue 11 years ago • 2 comments

This would bring it up to par with hiredis-py.

pietern avatar Jan 20 '14 22:01 pietern

Shouldn't we just make sure we treat everything as binary and let the user handle encoding?

badboy avatar Jan 28 '15 22:01 badboy

From the python version:

Unicode

hiredis.Reader is able to decode bulk data to any encoding Python supports. To do so, specify the encoding you want to use for decoding replies when initializing it:

>> reader = hiredis.Reader(encoding="utf-8")
>> reader.feed("$3\r\n\xe2\x98\x83\r\n")
>> reader.gets()
u'☃'

When bulk data in a reply could not be properly decoded using the specified encoding, it will be returned as a plain string. When the encoding cannot be found, a LookupError will be raised after calling gets for the first reply with bulk data (identical to what Python's unicode method would do).

mattsta avatar Jan 28 '15 22:01 mattsta