diff --git a/mockredis/client.py b/mockredis/client.py index 05c2439..926e048 100644 --- a/mockredis/client.py +++ b/mockredis/client.py @@ -691,7 +691,11 @@ def lpush(self, key, *args): # Creates the list at this key if it doesn't exist, and appends args to its beginning args_reversed = [self._encode(arg) for arg in args] args_reversed.reverse() - self.redis[self._encode(key)] = args_reversed + redis_list + updated_list = args_reversed + redis_list + self.redis[self._encode(key)] = updated_list + + # Return the length of the list after the push operation + return len(updated_list) def rpop(self, key): """Emulate lpop.""" @@ -716,6 +720,9 @@ def rpush(self, key, *args): # Creates the list at this key if it doesn't exist, and appends args to it redis_list.extend(map(self._encode, args)) + # Return the length of the list after the push operation + return len(redis_list) + def lrem(self, key, value, count=0): """Emulate lrem.""" value = self._encode(value) diff --git a/mockredis/tests/test_list.py b/mockredis/tests/test_list.py index 5269d10..d9b85be 100644 --- a/mockredis/tests/test_list.py +++ b/mockredis/tests/test_list.py @@ -86,15 +86,15 @@ def test_lpush(self): Insertion maintains order but not uniqueness. """ # lpush two values - self.redis.lpush(LIST1, VAL1) - self.redis.lpush(LIST1, VAL2) + eq_(1, self.redis.lpush(LIST1, VAL1)) + eq_(2, self.redis.lpush(LIST1, VAL2)) # validate insertion eq_(b"list", self.redis.type(LIST1)) eq_([bVAL2, bVAL1], self.redis.lrange(LIST1, 0, -1)) # insert two more values with one repeated - self.redis.lpush(LIST1, VAL1, VAL3) + eq_(4, self.redis.lpush(LIST1, VAL1, VAL3)) # validate the update eq_(b"list", self.redis.type(LIST1)) @@ -128,15 +128,15 @@ def test_rpush(self): Insertion maintains order but not uniqueness. """ # rpush two values - self.redis.rpush(LIST1, VAL1) - self.redis.rpush(LIST1, VAL2) + eq_(1, self.redis.rpush(LIST1, VAL1)) + eq_(2, self.redis.rpush(LIST1, VAL2)) # validate insertion eq_(b"list", self.redis.type(LIST1)) eq_([bVAL1, bVAL2], self.redis.lrange(LIST1, 0, -1)) # insert two more values with one repeated - self.redis.rpush(LIST1, VAL1, VAL3) + eq_(4, self.redis.rpush(LIST1, VAL1, VAL3)) # validate the update eq_(b"list", self.redis.type(LIST1))