From d734ec02feb551921e8dd8b6f89ee588a51956db Mon Sep 17 00:00:00 2001 From: Joe Heck Date: Mon, 17 Mar 2014 22:17:31 -0700 Subject: [PATCH] force a possible set into a list * resolves issue #42 * test from issue included in PR --- fakeredis.py | 2 +- test_fakeredis.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/fakeredis.py b/fakeredis.py index 750c67b..19c784e 100644 --- a/fakeredis.py +++ b/fakeredis.py @@ -380,7 +380,7 @@ def sort(self, name, start=None, num=None, by=None, get=None, desc=False, raise redis.RedisError( "RedisError: ``start`` and ``num`` must both be specified") try: - data = self._db[name][:] + data = list(self._db[name])[:] if by is not None: # _sort_using_by_arg mutates data so we don't # need need a return value. diff --git a/test_fakeredis.py b/test_fakeredis.py index 4b8d32e..191e755 100644 --- a/test_fakeredis.py +++ b/test_fakeredis.py @@ -1250,6 +1250,12 @@ def test_sort_with_hash(self): self.redis.sort('foo', by='record_*->age', get='record_*->name'), ['baby', 'teen', 'adult']) + def test_sort_with_set(self): + self.redis.sadd('foo', '3') + self.redis.sadd('foo', '1') + self.redis.sadd('foo', '2') + self.assertEqual(self.redis.sort('foo'), ['1', '2', '3']) + def test_pipeline(self): # The pipeline method returns an object for # issuing multiple commands in a batch.