Repository: redis/redis-py (Python)

Issue:
running dump() fails when decode_responses=True
redis-py 3.3.6
python 3.6.9
Ubuntu 18.04
redis 4.0.9

I have a `Redis` instance that I created with `decode_responses=True`. When I run `.dump(key)` the decoder fails to decode the bytes response, which makes sense, because it isn't unicode.

```
  File "/home/brian/.local/lib/python3.6/site-packages/redis/client.py", line 3677, in execute
    return execute(conn, stack, raise_on_error)
  File "/home/brian/.local/lib/python3.6/site-packages/redis/client.py", line 3570, in _execute_transaction
    response = self.parse_response(connection, '_')
  File "/home/brian/.local/lib/python3.6/site-packages/redis/client.py", line 3636, in parse_response
    self, connection, command_name, **options)
  File "/home/brian/.local/lib/python3.6/site-packages/redis/client.py", line 853, in parse_response
    response = connection.read_response()
  File "/home/brian/.local/lib/python3.6/site-packages/redis/connection.py", line 687, in read_response
    response = self._parser.read_response()
  File "/home/brian/.local/lib/python3.6/site-packages/redis/connection.py", line 442, in read_response
    response = self._reader.gets()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 1: invalid continuation byte
```


Hints:
Hello,

I have an issue too on decode_responses. UTF8 decoding for sentinel part seems not working : 

```
self.master = self.sentinel.master_for(redis_sentinels_master, socket_timeout=socket_db_timeout, db=db,  encoding=u'utf-8', decode_responses=True)
```

```
print(self.master.get(myKey))
b'xyz'
```


I don't know why, but this seems to have broken for me as well.

Patch:
diff --git a/redis/commands/core.py b/redis/commands/core.py
--- a/redis/commands/core.py
+++ b/redis/commands/core.py
@@ -637,6 +637,31 @@ def flushdb(self, asynchronous=False, **kwargs):
             args.append(b"ASYNC")
         return self.execute_command("FLUSHDB", *args, **kwargs)
 
+    def sync(self):
+        """
+        Initiates a replication stream from the master.
+
+        For more information check https://redis.io/commands/sync
+        """
+        from redis.client import NEVER_DECODE
+
+        options = {}
+        options[NEVER_DECODE] = []
+        return self.execute_command("SYNC", **options)
+
+    def psync(self, replicationid, offset):
+        """
+        Initiates a replication stream from the master.
+        Newer version for `sync`.
+
+        For more information check https://redis.io/commands/sync
+        """
+        from redis.client import NEVER_DECODE
+
+        options = {}
+        options[NEVER_DECODE] = []
+        return self.execute_command("PSYNC", replicationid, offset, **options)
+
     def swapdb(self, first, second, **kwargs):
         """
         Swap two databases
diff --git a/redis/connection.py b/redis/connection.py
--- a/redis/connection.py
+++ b/redis/connection.py
@@ -382,7 +382,7 @@ def __del__(self):
         except Exception:
             pass
 
-    def on_connect(self, connection):
+    def on_connect(self, connection, **kwargs):
         self._sock = connection._sock
         self._socket_timeout = connection.socket_timeout
         kwargs = {


Test patch:
diff --git a/tests/test_commands.py b/tests/test_commands.py
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -4151,6 +4151,18 @@ def test_replicaof(self, r):
             assert r.replicaof("NO ONE")
         assert r.replicaof("NO", "ONE")
 
+    @skip_if_server_version_lt("2.8.0")
+    def test_sync(self, r):
+        r2 = redis.Redis(port=6380, decode_responses=False)
+        res = r2.sync()
+        assert b"REDIS" in res
+
+    @skip_if_server_version_lt("2.8.0")
+    def test_psync(self, r):
+        r2 = redis.Redis(port=6380, decode_responses=False)
+        res = r2.psync(r2.client_id(), 1)
+        assert b"FULLRESYNC" in res
+
 
 @pytest.mark.onlynoncluster
 class TestBinarySave: