Skip to content

Commit

Permalink
Merge pull request #205 from thedrow/hstrlen
Browse files Browse the repository at this point in the history
Implemented hstrlen
  • Loading branch information
bmerry committed Aug 19, 2018
2 parents cb10fbe + bcc1209 commit cc200e2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
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

0 comments on commit cc200e2

Please sign in to comment.