Skip to content

Commit 62326d7

Browse files
authored
Monkey patch the Redis client to implement LOLWUT (#446)
1. `LOLWUT` command: https://redis.io/commands/lolwut 2. PR upstream: redis/redis-py#1448
1 parent 915585d commit 62326d7

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

pottery/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131

3232
__title__ = 'pottery'
33-
__version__ = '1.3.3'
33+
__version__ = '1.3.4'
3434
__description__, __long_description__ = (
3535
s.strip() for s in __doc__.split(sep='\n\n', maxsplit=1)
3636
)

pottery/monkey.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __eq__(self: ConnectionPool, other: Any) -> bool:
4646
ConnectionPool.__eq__ = __eq__ # type: ignore
4747

4848
_logger.info(
49-
'Monkey patched ConnectionPool.__eq__() to compare Redis clients by '
49+
'Monkey patched redis.ConnectionPool.__eq__() to compare Redis clients by '
5050
'connection params'
5151
)
5252

@@ -73,3 +73,24 @@ def _default(self: Any, obj: Any) -> Union[Dict[str, Any], List[Any], str]:
7373
'instance of any class that defines a .to_dict(), .to_list(), or .to_str() '
7474
'method'
7575
)
76+
77+
78+
# Monkey patch the Redis client to implement the LOLWUT command.
79+
# 1. LOLWUT command: https://redis.io/commands/lolwut
80+
# 2. PR upstream: https://github.com/andymccurdy/redis-py/pull/1448
81+
82+
from redis import Redis # isort: skip
83+
84+
def lolwut(self: Redis, *version_numbers: int) -> bytes:
85+
"Get the Redis version and a piece of generative computer art"
86+
if version_numbers:
87+
return self.execute_command('LOLWUT VERSION', *version_numbers)
88+
else:
89+
return self.execute_command('LOLWUT')
90+
91+
Redis.lolwut = lolwut # type: ignore
92+
93+
_logger.info(
94+
'Monkey patched redis.Redis.lolwut() to get the Redis version and a piece '
95+
'of generative art'
96+
)

tests/test_monkey.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,10 @@ def test_json_encoder(self):
3030
"Object of type 'object' is not JSON serializable", # Python 3.6
3131
'Object of type object is not JSON serializable', # Python 3.7+
3232
}
33+
34+
def test_redis_lolwut(self):
35+
lolwut = self.redis.lolwut().decode('utf-8')
36+
assert 'Redis ver.' in lolwut
37+
38+
lolwut = self.redis.lolwut(5, 6, 7, 8).decode('utf-8')
39+
assert 'Redis ver.' in lolwut

0 commit comments

Comments
 (0)