Comments (16)
Addes sets, and a small bugfix.
Original comment by [email protected]
on 27 Feb 2009 at 4:24
Attachments:
from redis.
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.
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.
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.
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.
[deleted comment]
from redis.
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.
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.
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.
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.
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.
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.
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.
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.
Original comment by [email protected]
on 12 Mar 2009 at 10:06
- Changed state: Fixed
from redis.
Great!
Original comment by [email protected]
on 4 Nov 2009 at 8:06
from redis.
Related Issues (20)
- BRPOPLPUSH return type is contingent on success HOT 2
- A 8G .aof file lead redis loading so slowly... HOT 3
- The command "config get databases" does not return
- Allow SORT Command to STORE results as sorted set HOT 1
- Even after flushall maxmemory shows the previous max value. HOT 10
- [FEATURE REQUEST]HMSETX/HSETX HOT 3
- BRPOPLPUSH and a single LPUSH with several items doesn't work well together HOT 2
- Suggestion on either using AOF or Save setting HOT 4
- [FEATURE REQUEST]maxmemory-policy HOT 4
- The issue about the special scenario in redis-2.2.12 HOT 5
- setex silent data loss when using unix time for expiration value HOT 4
- Need Git Tag for 2.2.13 HOT 1
- DBNUM Command HOT 4
- EXPIREAT make test fails
- Hello, antirez. At what time release b-tree version disk store? HOT 1
- make test error CentOS HOT 2
- Could not connect to Redis at 127.0.0.1:6379: Connection refused HOT 1
- configure bind two interface
- minor change (call to id instead of whoami) in install script HOT 1
- /
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redis.