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

Refactored, now will past CI. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 8 additions & 4 deletions mockredis/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class MockRedisPipeline(object):
"""
Simulates a redis-python pipeline object.
"""

def __init__(self, mock_redis, transaction=True, shard_hint=None):
self.mock_redis = mock_redis
self._reset()
Expand All @@ -28,6 +27,7 @@ def wrapper(*args, **kwargs):
else:
self.commands.append(lambda: command(*args, **kwargs))
return self

return wrapper

def watch(self, *keys):
Expand All @@ -39,7 +39,9 @@ def watch(self, *keys):
raise RedisError("Cannot issue a WATCH after a MULTI")
self.watching = True
for key in keys:
self._watched_keys[key] = deepcopy(self.mock_redis.redis.get(self.mock_redis._encode(key))) # noqa
self._watched_keys[key] = deepcopy(
self.mock_redis.redis.get(
self.mock_redis._encode(key))) # noqa

def multi(self):
"""
Expand All @@ -49,7 +51,8 @@ def multi(self):
if self.explicit_transaction:
raise RedisError("Cannot issue nested calls to MULTI")
if self.commands:
raise RedisError("Commands without an initial WATCH have already been issued")
raise RedisError(
"Commands without an initial WATCH have already been issued")
self.explicit_transaction = True

def execute(self):
Expand All @@ -58,7 +61,8 @@ def execute(self):
"""
try:
for key, value in self._watched_keys.items():
if self.mock_redis.redis.get(self.mock_redis._encode(key)) != value:
if self.mock_redis.redis.get(
self.mock_redis._encode(key)) != value:
raise WatchError("Watched variable changed.")
return [command() for command in self.commands]
finally:
Expand Down