Repository: redis/redis-py
Pull request #1610 (2021-10-14 09:57:38)

Adding ROLE Command
### Pull Request check-list

_Please make sure to review and check all of these items:_

- [x] Does `$ tox` pass with this change (including linting)?
- [x] Do the CI tests pass with this change (enable it first in your forked repo and wait for the github action build to finish)?
- [x] Is the new or changed code fully tested?
- [x] Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?

_NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open._

### Description of change

_Please provide a description of the change here._


codecov-commenter: # [Codecov](https://codecov.io/gh/redis/redis-py/pull/1610?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=redis) Report
> Merging [#1610](https://codecov.io/gh/redis/redis-py/pull/1610?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=redis) (a552c47) into [master](https://codecov.io/gh/redis/redis-py/commit/64791a54f4b2c28b6a61920a23df9e1f614e6983?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=redis) (64791a5) will **decrease** coverage by `0.40%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/redis/redis-py/pull/1610/graphs/tree.svg?width=650&height=150&src=pr&token=yenl5fzxxr&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=redis)](https://codecov.io/gh/redis/redis-py/pull/1610?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=redis)

```diff
@@            Coverage Diff             @@
##           master    #1610      +/-   ##
==========================================
- Coverage   89.04%   88.63%   -0.41%     
==========================================
  Files          53       53              
  Lines       11051    10662     -389     
==========================================
- Hits         9840     9450     -390     
- Misses       1211     1212       +1     
```


| [Impacted Files](https://codecov.io/gh/redis/redis-py/pull/1610?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=redis) | Coverage Δ | |
|---|---|---|
| [redis/commands/core.py](https://codecov.io/gh/redis/redis-py/pull/1610/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=redis#diff-cmVkaXMvY29tbWFuZHMvY29yZS5weQ==) | `83.88% <100.00%> (+0.01%)` | :arrow_up: |
| [tests/test\_commands.py](https://codecov.io/gh/redis/redis-py/pull/1610/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=redis#diff-dGVzdHMvdGVzdF9jb21tYW5kcy5weQ==) | `92.50% <100.00%> (-0.64%)` | :arrow_down: |
| [redis/retry.py](https://codecov.io/gh/redis/redis-py/pull/1610/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=redis#diff-cmVkaXMvcmV0cnkucHk=) | `95.23% <0.00%> (-4.77%)` | :arrow_down: |
| [tests/test\_connection.py](https://codecov.io/gh/redis/redis-py/pull/1610/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=redis#diff-dGVzdHMvdGVzdF9jb25uZWN0aW9uLnB5) | `69.56% <0.00%> (-2.44%)` | :arrow_down: |
| [redis/utils.py](https://codecov.io/gh/redis/redis-py/pull/1610/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=redis#diff-cmVkaXMvdXRpbHMucHk=) | `58.82% <0.00%> (-2.29%)` | :arrow_down: |
| [tests/test\_monitor.py](https://codecov.io/gh/redis/redis-py/pull/1610/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=redis#diff-dGVzdHMvdGVzdF9tb25pdG9yLnB5) | `73.46% <0.00%> (-1.05%)` | :arrow_down: |
| [redis/backoff.py](https://codecov.io/gh/redis/redis-py/pull/1610/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=redis#diff-cmVkaXMvYmFja29mZi5weQ==) | `56.52% <0.00%> (-0.93%)` | :arrow_down: |
| [tests/test\_lock.py](https://codecov.io/gh/redis/redis-py/pull/1610/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=redis#diff-dGVzdHMvdGVzdF9sb2NrLnB5) | `99.46% <0.00%> (-0.54%)` | :arrow_down: |
| [tests/conftest.py](https://codecov.io/gh/redis/redis-py/pull/1610/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=redis#diff-dGVzdHMvY29uZnRlc3QucHk=) | `91.72% <0.00%> (-0.54%)` | :arrow_down: |
| ... and [19 more](https://codecov.io/gh/redis/redis-py/pull/1610/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=redis) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/redis/redis-py/pull/1610?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=redis).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=redis)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/redis/redis-py/pull/1610?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=redis). Last update [64791a5...a552c47](https://codecov.io/gh/redis/redis-py/pull/1610?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=redis). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=redis).


Patch:
diff --git a/redis/commands/core.py b/redis/commands/core.py
index 462fba7f..fec3095c 100644
--- a/redis/commands/core.py
+++ b/redis/commands/core.py
@@ -333,6 +333,16 @@ class ManagementCommands:
             pieces.append("SCHEDULE")
         return self.execute_command("BGSAVE", *pieces, **kwargs)
 
+    def role(self):
+        """
+        Provide information on the role of a Redis instance in
+        the context of replication, by returning if the instance
+        is currently a master, slave, or sentinel.
+
+        For more information check https://redis.io/commands/role
+        """
+        return self.execute_command("ROLE")
+
     def client_kill(self, address, **kwargs):
         """Disconnects the client at ``address`` (ip:port)
 
@@ -864,11 +874,15 @@ class ManagementCommands:
 
         For more information check https://redis.io/commands/slowlog-get
         """
+        from redis.client import NEVER_DECODE
+
         args = ["SLOWLOG GET"]
         if num is not None:
             args.append(num)
         decode_responses = self.get_connection_kwargs().get("decode_responses", False)
-        return self.execute_command(*args, decode_responses=decode_responses, **kwargs)
+        if decode_responses is True:
+            kwargs[NEVER_DECODE] = []
+        return self.execute_command(*args, **kwargs)
 
     def slowlog_len(self, **kwargs):
         """
diff --git a/tox.ini b/tox.ini
index f4eaedc8..32d1680a 100644
--- a/tox.ini
+++ b/tox.ini
@@ -73,7 +73,7 @@ healtcheck_cmd = python -c "import socket;print(True) if 0 == socket.socket(sock
 
 [docker:lots-of-pythons]
 name = lots-of-pythons
-image = redisfab/lots-of-pythons
+image = redisfab/lots-of-pythons:latest
 volumes =
     bind:rw:{toxinidir}:/data
 


Test patch:
diff --git a/tests/test_commands.py b/tests/test_commands.py
index 7c7d0f3d..556df840 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -653,6 +653,13 @@ class TestRedisCommands:
     def test_quit(self, r):
         assert r.quit()
 
+    @skip_if_server_version_lt("2.8.12")
+    @pytest.mark.onlynoncluster
+    def test_role(self, r):
+        assert r.role()[0] == b"master"
+        assert isinstance(r.role()[1], int)
+        assert isinstance(r.role()[2], list)
+
     @pytest.mark.onlynoncluster
     def test_slowlog_get(self, r, slowlog):
         assert r.slowlog_reset()
diff --git a/tests/test_connection_pool.py b/tests/test_connection_pool.py
index 276e77cd..138fcad4 100644
--- a/tests/test_connection_pool.py
+++ b/tests/test_connection_pool.py
@@ -450,7 +450,7 @@ class TestConnectionPoolUnixSocketURLParsing:
             pass
 
         pool = redis.ConnectionPool.from_url(
-            'unix:///socket', connection_class=MyConnection
+            "unix:///socket", connection_class=MyConnection
         )
         assert pool.connection_class == MyConnection
 
@@ -469,7 +469,7 @@ class TestSSLConnectionURLParsing:
             pass
 
         pool = redis.ConnectionPool.from_url(
-            'rediss://my.host', connection_class=MyConnection
+            "rediss://my.host", connection_class=MyConnection
         )
         assert pool.connection_class == MyConnection