Skip to content

Commit 5e519b9

Browse files
committed
CC - Fix issue #85. Return length of list after LPUSH/RPUSH command.
See: http://redis.io/commands/lpush http://redis.io/commands/rpush #85
1 parent 45c0099 commit 5e519b9

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

mockredis/client.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,11 @@ def lpush(self, key, *args):
648648
# Creates the list at this key if it doesn't exist, and appends args to its beginning
649649
args_reversed = [self._encode(arg) for arg in args]
650650
args_reversed.reverse()
651-
self.redis[self._encode(key)] = args_reversed + redis_list
651+
updated_list = args_reversed + redis_list
652+
self.redis[self._encode(key)] = updated_list
653+
654+
# Return the length of the list after the push operation
655+
return len(updated_list)
652656

653657
def rpop(self, key):
654658
"""Emulate lpop."""
@@ -673,6 +677,9 @@ def rpush(self, key, *args):
673677
# Creates the list at this key if it doesn't exist, and appends args to it
674678
redis_list.extend(map(self._encode, args))
675679

680+
# Return the length of the list after the push operation
681+
return len(redis_list)
682+
676683
def lrem(self, key, value, count=0):
677684
"""Emulate lrem."""
678685
value = self._encode(value)

mockredis/tests/test_list.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ def test_lpush(self):
8686
Insertion maintains order but not uniqueness.
8787
"""
8888
# lpush two values
89-
self.redis.lpush(LIST1, VAL1)
90-
self.redis.lpush(LIST1, VAL2)
89+
eq_(1, self.redis.lpush(LIST1, VAL1))
90+
eq_(2, self.redis.lpush(LIST1, VAL2))
9191

9292
# validate insertion
9393
eq_(b"list", self.redis.type(LIST1))
9494
eq_([bVAL2, bVAL1], self.redis.lrange(LIST1, 0, -1))
9595

9696
# insert two more values with one repeated
97-
self.redis.lpush(LIST1, VAL1, VAL3)
97+
eq_(4, self.redis.lpush(LIST1, VAL1, VAL3))
9898

9999
# validate the update
100100
eq_(b"list", self.redis.type(LIST1))
@@ -128,15 +128,15 @@ def test_rpush(self):
128128
Insertion maintains order but not uniqueness.
129129
"""
130130
# rpush two values
131-
self.redis.rpush(LIST1, VAL1)
132-
self.redis.rpush(LIST1, VAL2)
131+
eq_(1, self.redis.rpush(LIST1, VAL1))
132+
eq_(2, self.redis.rpush(LIST1, VAL2))
133133

134134
# validate insertion
135135
eq_(b"list", self.redis.type(LIST1))
136136
eq_([bVAL1, bVAL2], self.redis.lrange(LIST1, 0, -1))
137137

138138
# insert two more values with one repeated
139-
self.redis.rpush(LIST1, VAL1, VAL3)
139+
eq_(4, self.redis.rpush(LIST1, VAL1, VAL3))
140140

141141
# validate the update
142142
eq_(b"list", self.redis.type(LIST1))

0 commit comments

Comments
 (0)