From a2f0c14f52e5b0bb0bcb879cdda4ea961191ef32 Mon Sep 17 00:00:00 2001 From: Rajiv Bakulesh Shah Date: Wed, 1 Sep 2021 23:25:01 -0700 Subject: [PATCH 1/3] Implement/test LOLWUT command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://redis.io/commands/lolwut This is a lot of fun to play with: ```python >>> from redis import Redis >>> redis = Redis() >>> print(redis.lolwut(5, 6, 7, 8).decode('utf-8')) ⣴⣶⣶⣶⣶⡆ ⣿⣿⣿⣿⣿⡇ ⠹⡿⠟⣿⡿⠃ ⠀⠀⠀⠀⠀⠀ Georg Nees - schotter, plotter on paper, 1968. Redis ver. 6.0.10 >>> print(redis.lolwut(5, 6, 7, 8).decode('utf-8')) ⢰⣶⣶⣶⣶⡆ ⢿⣿⣿⣿⣿⠁ ⠸⡿⢿⠿⡿⠃ ⠀⠀⠀⠀⠀⠀ Georg Nees - schotter, plotter on paper, 1968. Redis ver. 6.0.10 >>> print(redis.lolwut(5, 6, 7, 8).decode('utf-8')) ⢰⣶⣶⣶⣶⡆ ⣸⣿⣿⣻⣿⡅ ⠿⡿⠻⠿⠿⠁ ⠀⠀⠀⠀⠀⠀ Georg Nees - schotter, plotter on paper, 1968. Redis ver. 6.0.10 >>> ``` --- redis/commands.py | 7 +++++++ tests/test_commands.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/redis/commands.py b/redis/commands.py index 5f1f57b305..32cb1ee2bd 100644 --- a/redis/commands.py +++ b/redis/commands.py @@ -504,6 +504,13 @@ def lastsave(self): """ return self.execute_command('LASTSAVE') + def lolwut(self, *version_numbers): + "Get the Redis version and a piece of generative computer art" + if version_numbers: + return self.execute_command('LOLWUT VERSION', *version_numbers) + else: + return self.execute_command('LOLWUT') + def migrate(self, host, port, keys, destination_db, timeout, copy=False, replace=False, auth=None): """ diff --git a/tests/test_commands.py b/tests/test_commands.py index 254aba5f59..6b47339f76 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -518,6 +518,13 @@ def test_info(self, r): def test_lastsave(self, r): assert isinstance(r.lastsave(), datetime.datetime) + def test_lolwut(self, r): + lolwut = r.lolwut().decode('utf-8') + assert 'Redis ver.' in lolwut + + lolwut = r.lolwut(5, 6, 7, 8).decode('utf-8') + assert 'Redis ver.' in lolwut + def test_object(self, r): r['a'] = 'foo' assert isinstance(r.object('refcount', 'a'), int) From 43e3a11ca4006f18695345e4c500a4cd4fd5e957 Mon Sep 17 00:00:00 2001 From: Rajiv Bakulesh Shah Date: Sun, 5 Sep 2021 19:53:41 -0700 Subject: [PATCH 2/3] Add link to LOLWUT command documentation Co-authored-by: Chayim --- redis/commands.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/redis/commands.py b/redis/commands.py index 32cb1ee2bd..ddd12d64b6 100644 --- a/redis/commands.py +++ b/redis/commands.py @@ -505,7 +505,9 @@ def lastsave(self): return self.execute_command('LASTSAVE') def lolwut(self, *version_numbers): - "Get the Redis version and a piece of generative computer art" + """Get the Redis version and a piece of generative computer art + See: https://redis.io/commands/lolwut + """ if version_numbers: return self.execute_command('LOLWUT VERSION', *version_numbers) else: From 598707acb9136a33af923c5f146ed511fc46f31b Mon Sep 17 00:00:00 2001 From: Rajiv Bakulesh Shah Date: Thu, 30 Sep 2021 19:08:36 -0700 Subject: [PATCH 3/3] Skip LOLWUT unit test for Redis < 5.0.0 The `LOLWUT` command was introduced in Redis 5.0.0: https://redis.io/commands/lolwut --- tests/test_commands.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_commands.py b/tests/test_commands.py index 6b47339f76..e59c5b52e5 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -518,6 +518,7 @@ def test_info(self, r): def test_lastsave(self, r): assert isinstance(r.lastsave(), datetime.datetime) + @skip_if_server_version_lt('5.0.0') def test_lolwut(self, r): lolwut = r.lolwut().decode('utf-8') assert 'Redis ver.' in lolwut