Couldn't unserialize serialized data from redis

1,397 views
Skip to first unread message

Rauan Maemirov

unread,
Apr 7, 2009, 10:05:45 AM4/7/09
to redi...@googlegroups.com
Hi list. I've got problems with unserializing data saved in redis that
contains utf-8 (non-english) symbols. Having this:

Notice: unserialize() [function.unserialize]: Error at offset 0 of 6 byte...

Data simply looks like array(1, 'фывапро').

Firstly I thought that there are problems in my php version. But when
i save data (with much more complicated structure that this) in
memcached it successfully serializes, unserializes without having such
problems.

So, that's why, I think, that something wrong in redis or in phpredis.
Using phpredis C module/extension.

Salvatore Sanfilippo

unread,
Apr 7, 2009, 10:36:58 AM4/7/09
to redi...@googlegroups.com
Hello Rauan,

you should try to get they key "by hand" with ./redis-cli get
<keyname> and get what is stored there instead of your serialized
data. Btw redis does not have problems with binary data AFAIK. Please
try if you can get more info just asking Redis directly to show you
the serialized data, I guess everything will become obvious then.

Cheers,
Salvatore

2009/4/7 Rauan Maemirov <ra...@maemirov.com>:
--
Salvatore 'antirez' Sanfilippo
http://invece.org

Rauan Maemirov

unread,
Apr 8, 2009, 4:53:40 AM4/8/09
to redi...@googlegroups.com
Hi, Salvatore.

I tried to switch serialize with json_encode, and then with simple utf-8 string.

./redis-cli get <key> works correct. at least it shows me what i need.

from php i couldn't event get simple string without broking encoding.
Earlier i didn't have such problems.
Now, it's clear, that the problem is in phpredis module.

I wonder, if Alfonso Jimenez read this list. :)

2009/4/7 Salvatore Sanfilippo <ant...@gmail.com>:

Ludovico Magnocavallo

unread,
Apr 8, 2009, 4:56:24 AM4/8/09
to redi...@googlegroups.com
Rauan Maemirov wrote:
> Hi, Salvatore.
>
> I tried to switch serialize with json_encode, and then with simple utf-8 string.
>
> ./redis-cli get <key> works correct. at least it shows me what i need.
>
> from php i couldn't event get simple string without broking encoding.
> Earlier i didn't have such problems.
> Now, it's clear, that the problem is in phpredis module.

The PHP module probably has the same bug I fixed in the Python module
last week: basically it strips trailing blanks and newlines even when it
should not.

Salvatore can fix it, or I can do it if he has no time.

L.

Salvatore Sanfilippo

unread,
Apr 8, 2009, 4:58:39 AM4/8/09
to redi...@googlegroups.com
2009/4/8 Ludovico Magnocavallo <lu...@qix.it>:

> The PHP module probably has the same bug I fixed in the Python module
> last week: basically it strips trailing blanks and newlines even when it
> should not.
>
> Salvatore can fix it, or I can do it if he has no time.

Hello Ludovico, I think that Rauan is using the C PHP module.
I wonder if the two pure-PHP implementations contain this bug... I
didn't used serialization bug in Retwis utf-8 is handled correctly by
the PHP4 module.

Cheers,
Salvatore

jstrellner

unread,
Apr 8, 2009, 8:34:27 PM4/8/09
to Redis DB
Rauan,

PHP's serealize() command is not UTF-8 compatible. Instead encode it
as a JSON string (json_encode), or convert your strings which contain
UTF-8 to arrays.

I'll post some code later if I have a chance.

-Joel
Reply all
Reply to author
Forward
0 new messages