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

Implemented hstrlen #205

Merged
merged 1 commit into from
Aug 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,6 @@ geo
* georadiusbymember


hash
----

* hstrlen


sorted_set
----------

Expand Down
4 changes: 4 additions & 0 deletions fakeredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,10 @@ def hget(self, name, key):
"Return the value of ``key`` within the hash ``name``"
return self._get_hash(name).get(key)

def hstrlen(self, name, key):
"Returns the string length of the value associated with field in the hash stored at key"
return len(self._get_hash(name).get(key, ""))

def hgetall(self, name):
"Return a Python dict of the hash's name/value pairs"
all_items = dict()
Expand Down
10 changes: 10 additions & 0 deletions test_fakeredis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,16 @@ def test_empty_list(self):

# Tests for the hash type.

def test_hstrlen_missing(self):
self.assertEqual(self.redis.hstrlen('foo', 'doesnotexist'), 0)

self.redis.hset('foo', 'key', 'value')
self.assertEqual(self.redis.hstrlen('foo', 'doesnotexist'), 0)

def test_hstrlen(self):
self.redis.hset('foo', 'key', 'value')
self.assertEqual(self.redis.hstrlen('foo', 'key'), 5)

def test_hset_then_hget(self):
self.assertEqual(self.redis.hset('foo', 'key', 'value'), 1)
self.assertEqual(self.redis.hget('foo', 'key'), b'value')
Expand Down