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

Fix Issue #101 - Should raise an error when attempting to get a key holding a list #136

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions fakeredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ def echo(self, value):

def get(self, name):
value = self._db.get(name)
if isinstance(value, list) or isinstance(value, set):
raise redis.ResponseError("WRONGTYPE Operation against a key "
"holding the wrong kind of value")
if isinstance(value, _StrKeyDict):
raise redis.ResponseError("WRONGTYPE Operation against a key "
"holding the wrong kind of value")
Expand Down
15 changes: 15 additions & 0 deletions test_fakeredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ def test_get_invalid_type(self):
with self.assertRaises(redis.ResponseError):
self.redis.get('foo')

def test_get_invalid_type_list(self):
self.assertEqual(self.redis.rpush('foo', 'bar'), True)
with self.assertRaises(redis.ResponseError):
self.redis.get('foo')

def test_get_invalid_type_set(self):
self.assertEqual(self.redis.sadd('foo', 'bar'), True)
with self.assertRaises(redis.ResponseError):
self.redis.get('foo')

def test_get_invalid_type_sorted_set(self):
self.assertEqual(self.redis.zadd('foo', 1, 'bar'), True)
with self.assertRaises(redis.ResponseError):
self.redis.get('foo')

def test_set_non_str_keys(self):
self.assertEqual(self.redis.set(2, 'bar'), True)
self.assertEqual(self.redis.get(2), b'bar')
Expand Down