Giter VIP home page Giter VIP logo

Comments (16)

GoogleCodeExporter avatar GoogleCodeExporter commented on August 20, 2024
Addes sets, and a small bugfix.

Original comment by [email protected] on 27 Feb 2009 at 4:24

Attachments:

from redis.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 20, 2024
Ludo, sounds great! I'm not sure I understand the unicode stuff very well. The 
Redis
client should just handle binary stuff but I guess that Python supports unicode 
in a
native way, and the information that the string is unicode is stored inside the
object. If you send it to Redis you don't know anymore when you do "GETs" if the
original string was unicode or not. I guess there is no clear solution to this
problem, maybe to just abort? I wonder what memcached Python clients are doing.

Original comment by [email protected] on 27 Feb 2009 at 4:55

from redis.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 20, 2024
Well, in most Python libraries (the ones I know at least), one of two things 
happen:

* you take care in your code of all conversions to/from unicode (which is a 
pain), or

* the library takes care of it for you, using a default encoding or one 
specified by
you at initialization time

If you plan on using redis from Django for example, encoding/decoding 
everything adds
unnecessary clutter to your code, when you could just encode/decode in a couple 
of
places in the redis client.

The problem arises from the fact that there's no datatype in redis, i.e. 
everything
is a string, so if the client tries to decode something to return it as 
unicode, he
might well break it (think of a pickled object).

What I did was the minimum sufficient to make the client work:

* if you pass an encoded string, all is well

* if you pass a unicode object, it gets encoded using Python's default encoding
(usually 'ascii'), and any encoding errors get trapped and reraised as one of 
the
client's exceptions

* nothing is done on strings coming from redis, they are returned to the user 
as they are

If there's someone with a better plan, modifying the code is trivial.

Original comment by [email protected] on 27 Feb 2009 at 6:48

from redis.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 20, 2024
It's safe to assume that basically every string can be encoded in UTF-8. The 
correct behavior for any library 
should be to only work with unicode strings (in fact this is how Python 3.0 
works). This means that you library 
should actually enforce callers to pass only (and I mean if not raise an 
exception) unicode strings that then 
you can encode to UTF-8 and store to redis. Redis can't do anything with 
unicode because sockets only 
support byte strings and unicode is not a byte string but a memory 
representation (that in python happen to 
use UCS-2 or UCS-4).

So... My suggestion is, if you don't want to raise an exception when 
non-unicode is passed (although this is 
the only good idea to avoid an encoding mess when something changes outside of 
your library and you are 
unable to decode anything from redis), to encode unicode strings to UTF-8 and 
then store them.

Original comment by [email protected] on 28 Feb 2009 at 2:07

from redis.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 20, 2024
Vale, it won't work: if you accept only Unicode, you have to return Unicode. 
But you
cannot, as you cannot be sure that a redis string is a string. And what if the 
string
to store in redis is a pickled or marshaled object, do we still encode it?

What I did is wrap the encoding exception we get if the client gets a unicode 
string
that cannot be decoded. It might be useful to add an optional charset arg to 
init, so
that encoding can be done with it instead of the ascii default.

Original comment by [email protected] on 28 Feb 2009 at 9:43

from redis.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 20, 2024
[deleted comment]

from redis.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 20, 2024
Sorry for the off-topic, Redis SVN has some protocol differences, clients should
reflect this if possible, more info in the home page of the project.

Original comment by [email protected] on 28 Feb 2009 at 10:45

from redis.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 20, 2024
Could you give me write access to the svn for the python client? If it's ok for 
you,
I'd prefer to develop against it as it will make things easier for everybody.

Original comment by [email protected] on 28 Feb 2009 at 11:02

from redis.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 20, 2024
Ludo: sure! Just I need to find how to do it but should be hopefully simple, 
let me try.

Original comment by [email protected] on 28 Feb 2009 at 11:07

from redis.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 20, 2024
I think I added you, please ACK as I'm not sure :)

Original comment by [email protected] on 28 Feb 2009 at 11:09

from redis.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 20, 2024
It works perfectly, thanks!

I'll sync the client and hopefully update it with the latest svn changes by 
tonight.
Have a great weekend! :)

Original comment by [email protected] on 28 Feb 2009 at 11:15

from redis.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 20, 2024
Thanks! A good we to you too. And I will try to don't break the protocol again 
in the
future ;)

Original comment by [email protected] on 28 Feb 2009 at 11:17

from redis.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 20, 2024
On current SVN:

SyntaxError: Non-ASCII character '\xc3' in file redis.py on line 12, but no 
encoding
declared; see http://www.python.org/peps/pep-0263.html for details

You should add a coding-line on top of the file.

Original comment by [email protected] on 11 Mar 2009 at 5:43

from redis.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 20, 2024
It's pretty strange, as on line 12 there's only the SVN LastChangedDate 
keyword...

Original comment by [email protected] on 11 Mar 2009 at 7:25

from redis.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 20, 2024

Original comment by [email protected] on 12 Mar 2009 at 10:06

  • Changed state: Fixed

from redis.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 20, 2024
Great!

Original comment by [email protected] on 4 Nov 2009 at 8:06

from redis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.