PHP Redis client that supports objects serialization

3,779 views
Skip to first unread message

Chris

unread,
Jul 30, 2010, 4:27:22 AM7/30/10
to Redis DB
If you use memcache in PHP you can store a whole object just using $mc-
>set($key, $object).
I am currently using phpredis and it does not support this feature, If
you try, it says that the function was expecting a string). Do you
know a PHP client that does support object serialization?

Thank you in advance

Alvaro Videla

unread,
Jul 30, 2010, 5:58:38 AM7/30/10
to redi...@googlegroups.com
Why don't you just do:

set($key, serialize($object));

or you can even extend the class with that functionality…

> --
> You received this message because you are subscribed to the Google Groups "Redis DB" group.
> To post to this group, send email to redi...@googlegroups.com.
> To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.
>

Konstantin Merenkov

unread,
Jul 30, 2010, 5:59:23 AM7/30/10
to redi...@googlegroups.com

I don't know about PHP clients but such a feature should be easy to
implement on your side, after that every client will be suitable,
usable, etc :-)

--
Best Regards,
Konstantin Merenkov

Nicolas Favre-Félix

unread,
Jul 30, 2010, 6:40:09 AM7/30/10
to redi...@googlegroups.com
Hello,

As one of the authors of phpredis, maybe I can explain this choice.
If phpredis serialized everything, it would break the compatibility with other libraries. If you were using phpredis and wanted to migrate to predis, you would have to call unserialize() on all your data.
Also, PHPRedis can read any value from redis. If you wanted to read non-serialized data that was added to redis by another library or from another programming language, phpredis would fail to unserialize it.

You can indeed use serialize() by hand, in a wrapper class for example. Such a wrapper would also make it easy for you to change libraries if you wanted to.

I suppose it could still be added, but disabled by default. But the thing is, the semantics have to be well-defined. What will happen to the commands that work on integers (INCR, DECR...). If the value is serialized then they won't work. What about the contents of lists, sets, sorted sets, hashes. Should they be serialized? That would break several commands, among them SORT BY.

All of this needs to be considered and a decision made for each data type. As of today I am not convinced that phpredis should do it. A call to serialize/unserialize in a wrapper class might be a better pick. That's what we do where I work; we also add a call to gzcompress/gzuncompress.


Nicolas

Shumkov

unread,
Jul 31, 2010, 6:57:22 AM7/31/10
to Redis DB
Rediska (http://rediska.geometria-lab.net/) has very custoizable
serializer. And Rediska serialize only arrays and objects and that no
failing commands like INCR and APPEND.

Daniele Alessandri

unread,
Aug 1, 2010, 2:12:02 AM8/1/10
to redi...@googlegroups.com

I completely agree with Nicolas, but I'm convinced on the fact that
object serialization / deserialization shouldn't be a concern of a
client library. This feature will never be implemented in Predis.

As others already pointed out, if you need (de)serialization you can
easily handle it on top of any existing client library and inside the
logic of your application. With Predis you could even redefine
existing commands to handle everything at library level if you really
need this badly, but I don't encourage this kind of use.

--
Daniele Alessandri
http://clorophilla.net/
http://twitter.com/JoL1hAHN

Reply all
Reply to author
Forward
0 new messages