summaryrefslogtreecommitdiff
path: root/redis/client.py
diff options
context:
space:
mode:
authorAndy McCurdy <andy@andymccurdy.com>2010-05-03 09:38:19 -0700
committerAndy McCurdy <andy@andymccurdy.com>2010-05-03 09:38:19 -0700
commitb936a60a02a5c9f1fafe301c952a8aa044ec6536 (patch)
tree92a693ffeee6d90011f4d284e3d1a84d07b8d4e9 /redis/client.py
parentf4c8393113e2205eb8eeddeed10d42ad70d648ef (diff)
downloadredis-py-b936a60a02a5c9f1fafe301c952a8aa044ec6536.tar.gz
values with scores of 0 were previously failing due to the way the callback converted values. changed to a separate function to get proper handling. fixes #33
Diffstat (limited to 'redis/client.py')
-rw-r--r--redis/client.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/redis/client.py b/redis/client.py
index d29df67..28dbf46 100644
--- a/redis/client.py
+++ b/redis/client.py
@@ -178,6 +178,17 @@ def zset_score_pairs(response, **options):
return response
return zip(response[::2], map(float, response[1::2]))
+def int_or_none(response):
+ if response is None:
+ return None
+ return int(response)
+
+def float_or_none(response):
+ if response is None:
+ return None
+ return float(response)
+
+
class Redis(threading.local):
"""
Implementation of the Redis protocol.
@@ -196,7 +207,7 @@ class Redis(threading.local):
),
string_keys_to_dict(
'DECRBY HLEN INCRBY LLEN SCARD SDIFFSTORE SINTERSTORE '
- 'SUNIONSTORE ZCARD ZRANK ZREMRANGEBYSCORE ZREVRANK',
+ 'SUNIONSTORE ZCARD ZREMRANGEBYSCORE ZREVRANK',
int
),
string_keys_to_dict(
@@ -204,8 +215,7 @@ class Redis(threading.local):
'LPUSH RPUSH',
lambda r: isinstance(r, int) and r or r == 'OK'
),
- string_keys_to_dict('ZSCORE ZINCRBY',
- lambda r: r is not None and float(r) or r),
+ string_keys_to_dict('ZSCORE ZINCRBY', float_or_none),
string_keys_to_dict(
'FLUSHALL FLUSHDB LSET LTRIM MSET RENAME '
'SAVE SELECT SET SHUTDOWN',
@@ -225,6 +235,7 @@ class Redis(threading.local):
'PING': lambda r: r == 'PONG',
'RANDOMKEY': lambda r: r and r or None,
'TTL': lambda r: r != -1 and r or None,
+ 'ZRANK': int_or_none,
}
)