Skip to content

Commit 3cec686

Browse files
author
Jesse Myers
committed
Merge branch 'release/2.9.0.9'
2 parents d50963f + 29790ab commit 3cec686

File tree

8 files changed

+52
-2
lines changed

8 files changed

+52
-2
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ language: python
22
python:
33
- '2.7'
44
- '3.2'
5+
- '3.3'
6+
- '3.4'
57
- pypy
68
install: pip install . --use-mirrors
79
script: python setup.py nosetests

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Version 2.9.0.9
2+
3+
- Support: RENAME and RENAMENX
4+
- SADD will raise an exception if an empty list is passed to it
5+
16
Version 2.9.0.8
27

38
- Add inclusive syntax (parenthesis) support for zero sets ZRANGEBYSCORE, ZREVRANGEBYSCORE & ZREMRANGEBYSCORE

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ Many unit tests exist to verify correctness of mock functionality. In addition,
3030
unit tests support testing against an actual redis-server instance to verify the tests
3131
against ground truth. See `mockredis.tests.fixtures` for more details and disclaimers.
3232

33+
## Supported python versions
34+
35+
- Python 2.7
36+
- Python 3.2
37+
- Python 3.3
38+
- Python 3.4
39+
- PyPy
40+
3341
## Attribution
3442

3543
This code is shamelessly derived from work by [John DeRosa][john].

mockredis/client.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,18 @@ def flushdb(self):
230230
self.pubsub.clear()
231231
self.timeouts.clear()
232232

233+
def rename(self, old_key, new_key):
234+
return self._rename(old_key, new_key)
235+
236+
def renamenx(self, old_key, new_key):
237+
return 1 if self._rename(old_key, new_key, True) else 0
238+
239+
def _rename(self, old_key, new_key, nx=False):
240+
if old_key in self.redis and (not nx or new_key not in self.redis):
241+
self.redis[new_key] = self.redis.pop(old_key)
242+
return True
243+
return False
244+
233245
#### String Functions ####
234246

235247
def get(self, key):
@@ -830,6 +842,8 @@ def value_function():
830842

831843
def sadd(self, key, *values):
832844
"""Emulate sadd."""
845+
if len(values) == 0:
846+
raise ResponseError("wrong number of arguments for 'sadd' command")
833847
redis_set = self._get_set(key, 'SADD', create=True)
834848
before_count = len(redis_set)
835849
redis_set.update(map(str, values))
@@ -1368,6 +1382,7 @@ def _score_inclusive(self, score):
13681382
return False, float(score[1:])
13691383
return True, float(score)
13701384

1385+
13711386
def get_total_seconds(td):
13721387
"""
13731388
For python 2.6 support

mockredis/tests/test_redis.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,16 @@ def test_delitem(self):
208208
eq_(None, self.redis.get("foo"))
209209
# redispy does not correctly raise KeyError here, so we don't either
210210
del self.redis["foo"]
211+
212+
def test_rename(self):
213+
self.redis["foo"] = "bar"
214+
ok_(self.redis.rename("foo", "new_foo"))
215+
eq_("bar", self.redis.get("new_foo"))
216+
217+
def test_renamenx(self):
218+
self.redis["foo"] = "bar"
219+
self.redis["foo2"] = "bar2"
220+
eq_(self.redis.renamenx("foo", "foo2"), 0)
221+
eq_("bar2", self.redis.get("foo2"))
222+
eq_(self.redis.renamenx("foo", "foo3"), 1)
223+
eq_("bar", self.redis.get("foo3"))

mockredis/tests/test_set.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from nose.tools import assert_raises, eq_, ok_
22

3+
from mockredis.exceptions import ResponseError
34
from mockredis.tests.fixtures import setup
45

56

@@ -9,6 +10,12 @@ class TestRedisSet(object):
910
def setup(self):
1011
setup(self)
1112

13+
def test_sadd_empty(self):
14+
key = "set"
15+
values = []
16+
with assert_raises(ResponseError):
17+
self.redis.sadd(key, *values)
18+
1219
def test_sadd(self):
1320
key = "set"
1421
values = ["one", "uno", "two", "three"]

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from setuptools import setup, find_packages
44

55
# Match releases to redis-py versions
6-
__version__ = '2.9.0.8'
6+
__version__ = '2.9.0.9'
77

88
# Jenkins will replace __build__ with a unique value.
99
__build__ = ''

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py27, py32, pypy
2+
envlist = py27, py32, py33, py34, pypy
33

44
[testenv]
55
commands = python setup.py nosetests

0 commit comments

Comments
 (0)