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

Type inference does not work with byte buffers #11

Closed
mjrusso opened this issue Feb 9, 2010 · 3 comments
Closed

Type inference does not work with byte buffers #11

mjrusso opened this issue Feb 9, 2010 · 3 comments

Comments

@mjrusso
Copy link

mjrusso commented Feb 9, 2010

The following code (the last lines of _get_value) does not work properly if the value stored in Redis is a byte buffer.

data = ''.join(buf)[:-2]
try:
    if not '.' in data:
        value = int(data)
    else:
        value = self.float_fn(data)
    return value
except (ValueError, decimal.InvalidOperation):
    return data.decode(self.charset)

Ignoring the general type inference issues (discussed on the Redis mailing list here: http://groups.google.com/group/redis-db/browse_thread/thread/9888eb9ff383c90c), there is a serious issue with the data.decode call in the event that the data is representative of a byte buffer. In this case, decoding the buffer with a codec results in an incorrect response being returned to the client. Instead, data itself should be returned to the caller.

@andymccurdy
Copy link
Contributor

I've pushed a new branch of redis-py called "newapi". It's a completely refactored client. There are numerous changes under the hood, including pipelining, a more consistent interface across commands, and removal of "magic value decoding".

I've made an effort to be backwards compatible where possible, issuing DeprecationWarnings for things that will go away in a future version. Hopefully this will give people time to upgrade their code. Nevertheless, there are several backwards incompatible changes, most notably that the Redis client no longer attempts to be "clever" about casting values to ints and floats if the data looks like a number. For example:

r = Redis()
r.set('foo', 1)
r.get('foo')
'1' # a string, not an integer

There are tests for all the commands and I should have a working set of tests for pipelining and connection pooling this evening.

If you have some spare cycles, it'd be awesome if you could give the new client a test drive and provide any feedback.

Thanks!
-andy

@andymccurdy
Copy link
Contributor

This issue has been resolved in the 1.34 release of redis-py.

@mjrusso
Copy link
Author

mjrusso commented Feb 19, 2010

Thanks Andy, this is excellent. Sidenote: thanks also for making the naming of the commands/methods consistent-- the old style was driving me insane.

This issue was closed.
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