Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why pickle strings? #59

Closed
askaliuk opened this issue Mar 10, 2014 · 4 comments
Closed

Why pickle strings? #59

askaliuk opened this issue Mar 10, 2014 · 4 comments

Comments

@askaliuk
Copy link

Hello @niwibe ,

IMHO, I found strange django-redis behavior in simple JSON caching.

from django.core.cache import cache
cache.set("123", '{"test":"test"}')

Redis monitor:

~$ redis-cli monitor
OK
1394490905.897550 [1 127.0.0.1:49782] "SETEX" "123" "300" "\x80\x02U\x0f{\"test\":\"test\"}q\x01."

Why does it pickle simple JSON string? Pickled version will take more memory.
Please explain - is it desired behavior?

@niwinz
Copy link
Collaborator

niwinz commented Mar 10, 2014

Hi @askaliuk

I have used pickle for serialize everything for conserve the real type for everything (django-redis-cache was some bugs related to serialize string, but deserializes integer...)

Now, django-redis deals with integer values as special values and stores it without pickling, allowing
redis atomic operations over it. And... now if I enable string storage without pickling, the previous strange and inconsistent behavior will return (when I set("foo", "1"), get("foo") will return 1 (int))

For more information: https://github.com/niwibe/django-redis/blob/master/redis_cache/client/default.py#L281

If you know any better approach for it, maintaining atomic operations for integers, improvements are welcome.

@niwinz
Copy link
Collaborator

niwinz commented Mar 10, 2014

As workaround, if you want store raw strings, you can use redis_cache.get_redis_connection(alias) for obtain a raw redis client and use it for store raw strings without serializing.

Also, you can subclass the default client, and overwrite pickle and unpickle methods with own behavior (WARNING: in future release these methods will change to serialize/deserialize ;))

@askaliuk
Copy link
Author

Thank you @niwibe for explanation.
I don't have good ideas for now, so feel free to close this issue.

@niwinz
Copy link
Collaborator

niwinz commented Mar 10, 2014

Thanks to you for your interest! ;)

@niwinz niwinz closed this as completed Mar 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants