Permalink
Browse files

add python 3.2 compatibility

  • Loading branch information...
1 parent c1d8678 commit d31614c12564cbd55b240386d1cc18bf309a038f @salimane committed Sep 8, 2012
Showing with 66 additions and 72 deletions.
  1. +1 −1 .travis.yml
  2. +1 −1 README.md
  3. +1 −1 rediscluster/__init__.py
  4. +9 −14 rediscluster/client.py
  5. +1 −1 requirements.txt
  6. +2 −2 run_tests
  7. +0 −1 setup.py
  8. +51 −51 tests/server_commands.py
View
@@ -2,7 +2,7 @@ language: python
python:
- "2.6"
- "2.7"
-# - "3.2"
+ - "3.2"
# - "pypy"
# command to install dependencies
install:
View
@@ -5,7 +5,7 @@ a Python interface to a Cluster of Redis key-value store.
## Travis CI
-Currently, rediscluster-py is being tested via travis ci for python version 2.6, and 2.7:
+Currently, rediscluster-py is being tested via travis ci for python version 2.6, 2.7 and 3.2:
[![Build Status](https://secure.travis-ci.org/salimane/rediscluster-py.png?branch=master)](http://travis-ci.org/salimane/rediscluster-py)
View
@@ -10,7 +10,7 @@
WatchError,
)
-__version__ = '0.1.1'
+__version__ = '0.1.2'
VERSION = tuple(map(int, __version__.split('.')))
__all__ = [
View
@@ -1,6 +1,7 @@
# -*- coding: UTF-8 -*-
import redis
import binascii
+from rediscluster._compat import (b, iteritems, dictvalues)
class StrictRedis:
"""
@@ -42,7 +43,7 @@ class StrictRedis:
'sunion' : 'sunion', 'sunionstore' : 'sunionstore', 'unsubscribe' : 'unsubscribe', 'unwatch' : 'unwatch',
'watch' : 'watch', 'zadd' : 'zadd', 'zincrby' : 'zincrby', 'zinterstore' : 'zinterstore',
'zrem' : 'zrem', 'zremrangebyrank' : 'zremrangebyrank', 'zremrangebyscore' : 'zremrangebyscore', 'zunionstore' : 'zunionstore',
- 'mset' : 'mset','msetnx' : 'msetnx', 'rename' : 'rename', 'renamenx' : 'renamenx',
+ 'mset' : 'mset', 'msetnx' : 'msetnx', 'rename' : 'rename', 'renamenx' : 'renamenx',
'del' : 'del', 'delete' : 'delete', 'ttl' : 'ttl', 'flushall' : 'flushall', 'flushdb' : 'flushdb',
}
@@ -68,7 +69,7 @@ class StrictRedis:
}
loop_keys = {
- 'keys' : 'keys',
+ 'keys' : 'keys',
'save' : 'save', 'bgsave' : 'bgsave',
'bgrewriteaof' : 'bgrewriteaof',
'dbsize' : 'dbsize', 'info' : 'info',
@@ -84,10 +85,10 @@ def __init__(self, cluster = {}, db = 0):
self.cluster = cluster
self.no_servers = len(cluster['master_of'])
- slaves = cluster['master_of'].values()
+ slaves = dictvalues(cluster['master_of'])
self.redises = {}
#connect to all servers
- for alias, server in cluster['nodes'].iteritems():
+ for alias, server in iteritems(cluster['nodes']):
try:
self.__redis = redis.StrictRedis(host=server['host'], port=server['port'], db=db)
sla = self.__redis.config_get('slaveof')['slaveof']
@@ -102,7 +103,7 @@ def __init__(self, cluster = {}, db = 0):
except Exception as e:
#if node is slave and is down, replace its connection with its master's
try:
- ms = [k for k, v in cluster['master_of'].iteritems() if v == alias and sla != ''][0]
+ ms = [k for k, v in iteritems(cluster['master_of']) if v == alias and sla != ''][0]
except IndexError as ie:
ms = None
@@ -120,7 +121,7 @@ def __init__(self, cluster = {}, db = 0):
else:
raise Exception("rediscluster cannot connect to: %s:%s %s" % (server['host'], server['port'], e))
- self.redises[alias] = self.__redis
+ self.redises[alias] = self.__redis
def __getattr__(self, name, *args, **kwargs):
@@ -143,7 +144,7 @@ def function(*args, **kwargs):
args[0] = args[0][1]
#get the node number
- node = str((abs(binascii.crc32(hkey) & 0xffffffff) % self.no_servers) + 1)
+ node = str((abs(binascii.crc32(b(hkey)) & 0xffffffff) % self.no_servers) + 1)
redisent = self.redises[self.cluster['default_node']]
if name in StrictRedis.write_keys:
redisent = self.redises['node_' + node]
@@ -155,7 +156,7 @@ def function(*args, **kwargs):
else:
result = {}
- for alias, redisent in self.redises.iteritems():
+ for alias, redisent in iteritems(self.redises):
if name in StrictRedis.write_keys and alias not in self.cluster['master_of']:
res = None
else:
@@ -169,9 +170,3 @@ def function(*args, **kwargs):
return result
return function
-
-
-
-
-
-
View
@@ -1,2 +1,2 @@
-redis>=2.4.12
+redis>=2.4.0
hiredis
View
@@ -5,5 +5,5 @@ from tests import all_tests
if __name__ == "__main__":
- tests = all_tests()
- results = unittest.TextTestRunner().run(tests)
+ tests = all_tests()
+ results = unittest.TextTestRunner().run(tests)
View
@@ -38,7 +38,6 @@
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
- 'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
Oops, something went wrong.

0 comments on commit d31614c

Please sign in to comment.