We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Fixed ConnectionsPool.[pubsub_channels/pubsub_patterns]
Fixed bug in `commands.pubsub.PubSubCommandsMixin.subscribe` (and psubscribe). `ConnectionsPool.pubsub_channles` code was called before `ConnectionsPool._pubsub_conn` creation, and therefore `pubsub_channles` 

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `aioredis/commands/pubsub.py`
Content:
```
1 import json
2 
3 from aioredis.util import wait_make_dict
4 
5 
6 class PubSubCommandsMixin:
7     """Pub/Sub commands mixin.
8 
9     For commands details see: http://redis.io/commands/#pubsub
10     """
11 
12     def publish(self, channel, message):
13         """Post a message to channel."""
14         return self.execute(b'PUBLISH', channel, message)
15 
16     def publish_json(self, channel, obj):
17         """Post a JSON-encoded message to channel."""
18         return self.publish(channel, json.dumps(obj))
19 
20     def subscribe(self, channel, *channels):
21         """Switch connection to Pub/Sub mode and
22         subscribe to specified channels.
23 
24         Arguments can be instances of :class:`~aioredis.Channel`.
25 
26         Returns :func:`asyncio.gather()` coroutine which when done will return
27         a list of :class:`~aioredis.Channel` objects.
28         """
29         conn = self._pool_or_conn
30         return wait_return_channels(
31             conn.execute_pubsub(b'SUBSCRIBE', channel, *channels),
32             conn.pubsub_channels)
33 
34     def unsubscribe(self, channel, *channels):
35         """Unsubscribe from specific channels.
36 
37         Arguments can be instances of :class:`~aioredis.Channel`.
38         """
39         conn = self._pool_or_conn
40         return conn.execute_pubsub(b'UNSUBSCRIBE', channel, *channels)
41 
42     def psubscribe(self, pattern, *patterns):
43         """Switch connection to Pub/Sub mode and
44         subscribe to specified patterns.
45 
46         Arguments can be instances of :class:`~aioredis.Channel`.
47 
48         Returns :func:`asyncio.gather()` coroutine which when done will return
49         a list of subscribed :class:`~aioredis.Channel` objects with
50         ``is_pattern`` property set to ``True``.
51         """
52         conn = self._pool_or_conn
53         return wait_return_channels(
54             conn.execute_pubsub(b'PSUBSCRIBE', pattern, *patterns),
55             conn.pubsub_patterns)
56 
57     def punsubscribe(self, pattern, *patterns):
58         """Unsubscribe from specific patterns.
59 
60         Arguments can be instances of :class:`~aioredis.Channel`.
61         """
62         conn = self._pool_or_conn
63         return conn.execute_pubsub(b'PUNSUBSCRIBE', pattern, *patterns)
64 
65     def pubsub_channels(self, pattern=None):
66         """Lists the currently active channels."""
67         args = [b'PUBSUB', b'CHANNELS']
68         if pattern is not None:
69             args.append(pattern)
70         return self.execute(*args)
71 
72     def pubsub_numsub(self, *channels):
73         """Returns the number of subscribers for the specified channels."""
74         return wait_make_dict(self.execute(
75             b'PUBSUB', b'NUMSUB', *channels))
76 
77     def pubsub_numpat(self):
78         """Returns the number of subscriptions to patterns."""
79         return self.execute(b'PUBSUB', b'NUMPAT')
80 
81     @property
82     def channels(self):
83         """Returns read-only channels dict.
84 
85         See :attr:`~aioredis.RedisConnection.pubsub_channels`
86         """
87         return self._pool_or_conn.pubsub_channels
88 
89     @property
90     def patterns(self):
91         """Returns read-only patterns dict.
92 
93         See :attr:`~aioredis.RedisConnection.pubsub_patterns`
94         """
95         return self._pool_or_conn.pubsub_patterns
96 
97     @property
98     def in_pubsub(self):
99         """Indicates that connection is in PUB/SUB mode.
100 
101         Provides the number of subscribed channels.
102         """
103         return self._pool_or_conn.in_pubsub
104 
105 
106 async def wait_return_channels(fut, channels_dict):
107     return [channels_dict[name]
108             for cmd, name, count in await fut]
109
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/aioredis/commands/pubsub.py b/aioredis/commands/pubsub.py
--- a/aioredis/commands/pubsub.py
+++ b/aioredis/commands/pubsub.py
@@ -29,7 +29,7 @@
         conn = self._pool_or_conn
         return wait_return_channels(
             conn.execute_pubsub(b'SUBSCRIBE', channel, *channels),
-            conn.pubsub_channels)
+            conn, 'pubsub_channels')
 
     def unsubscribe(self, channel, *channels):
         """Unsubscribe from specific channels.
@@ -52,7 +52,7 @@
         conn = self._pool_or_conn
         return wait_return_channels(
             conn.execute_pubsub(b'PSUBSCRIBE', pattern, *patterns),
-            conn.pubsub_patterns)
+            conn, 'pubsub_patterns')
 
     def punsubscribe(self, pattern, *patterns):
         """Unsubscribe from specific patterns.
@@ -103,6 +103,7 @@
         return self._pool_or_conn.in_pubsub
 
 
-async def wait_return_channels(fut, channels_dict):
-    return [channels_dict[name]
-            for cmd, name, count in await fut]
+async def wait_return_channels(fut, conn, field):
+    res = await fut
+    channels_dict = getattr(conn, field)
+    return [channels_dict[name] for cmd, name, count in res]

{"golden_diff": "diff --git a/aioredis/commands/pubsub.py b/aioredis/commands/pubsub.py\n--- a/aioredis/commands/pubsub.py\n+++ b/aioredis/commands/pubsub.py\n@@ -29,7 +29,7 @@\n         conn = self._pool_or_conn\n         return wait_return_channels(\n             conn.execute_pubsub(b'SUBSCRIBE', channel, *channels),\n-            conn.pubsub_channels)\n+            conn, 'pubsub_channels')\n \n     def unsubscribe(self, channel, *channels):\n         \"\"\"Unsubscribe from specific channels.\n@@ -52,7 +52,7 @@\n         conn = self._pool_or_conn\n         return wait_return_channels(\n             conn.execute_pubsub(b'PSUBSCRIBE', pattern, *patterns),\n-            conn.pubsub_patterns)\n+            conn, 'pubsub_patterns')\n \n     def punsubscribe(self, pattern, *patterns):\n         \"\"\"Unsubscribe from specific patterns.\n@@ -103,6 +103,7 @@\n         return self._pool_or_conn.in_pubsub\n \n \n-async def wait_return_channels(fut, channels_dict):\n-    return [channels_dict[name]\n-            for cmd, name, count in await fut]\n+async def wait_return_channels(fut, conn, field):\n+    res = await fut\n+    channels_dict = getattr(conn, field)\n+    return [channels_dict[name] for cmd, name, count in res]\n", "issue": "Fixed ConnectionsPool.[pubsub_channels/pubsub_patterns]\nFixed bug in `commands.pubsub.PubSubCommandsMixin.subscribe` (and psubscribe). `ConnectionsPool.pubsub_channles` code was called before `ConnectionsPool._pubsub_conn` creation, and therefore `pubsub_channles` \n", "before_files": [{"content": "import json\n\nfrom aioredis.util import wait_make_dict\n\n\nclass PubSubCommandsMixin:\n    \"\"\"Pub/Sub commands mixin.\n\n    For commands details see: http://redis.io/commands/#pubsub\n    \"\"\"\n\n    def publish(self, channel, message):\n        \"\"\"Post a message to channel.\"\"\"\n        return self.execute(b'PUBLISH', channel, message)\n\n    def publish_json(self, channel, obj):\n        \"\"\"Post a JSON-encoded message to channel.\"\"\"\n        return self.publish(channel, json.dumps(obj))\n\n    def subscribe(self, channel, *channels):\n        \"\"\"Switch connection to Pub/Sub mode and\n        subscribe to specified channels.\n\n        Arguments can be instances of :class:`~aioredis.Channel`.\n\n        Returns :func:`asyncio.gather()` coroutine which when done will return\n        a list of :class:`~aioredis.Channel` objects.\n        \"\"\"\n        conn = self._pool_or_conn\n        return wait_return_channels(\n            conn.execute_pubsub(b'SUBSCRIBE', channel, *channels),\n            conn.pubsub_channels)\n\n    def unsubscribe(self, channel, *channels):\n        \"\"\"Unsubscribe from specific channels.\n\n        Arguments can be instances of :class:`~aioredis.Channel`.\n        \"\"\"\n        conn = self._pool_or_conn\n        return conn.execute_pubsub(b'UNSUBSCRIBE', channel, *channels)\n\n    def psubscribe(self, pattern, *patterns):\n        \"\"\"Switch connection to Pub/Sub mode and\n        subscribe to specified patterns.\n\n        Arguments can be instances of :class:`~aioredis.Channel`.\n\n        Returns :func:`asyncio.gather()` coroutine which when done will return\n        a list of subscribed :class:`~aioredis.Channel` objects with\n        ``is_pattern`` property set to ``True``.\n        \"\"\"\n        conn = self._pool_or_conn\n        return wait_return_channels(\n            conn.execute_pubsub(b'PSUBSCRIBE', pattern, *patterns),\n            conn.pubsub_patterns)\n\n    def punsubscribe(self, pattern, *patterns):\n        \"\"\"Unsubscribe from specific patterns.\n\n        Arguments can be instances of :class:`~aioredis.Channel`.\n        \"\"\"\n        conn = self._pool_or_conn\n        return conn.execute_pubsub(b'PUNSUBSCRIBE', pattern, *patterns)\n\n    def pubsub_channels(self, pattern=None):\n        \"\"\"Lists the currently active channels.\"\"\"\n        args = [b'PUBSUB', b'CHANNELS']\n        if pattern is not None:\n            args.append(pattern)\n        return self.execute(*args)\n\n    def pubsub_numsub(self, *channels):\n        \"\"\"Returns the number of subscribers for the specified channels.\"\"\"\n        return wait_make_dict(self.execute(\n            b'PUBSUB', b'NUMSUB', *channels))\n\n    def pubsub_numpat(self):\n        \"\"\"Returns the number of subscriptions to patterns.\"\"\"\n        return self.execute(b'PUBSUB', b'NUMPAT')\n\n    @property\n    def channels(self):\n        \"\"\"Returns read-only channels dict.\n\n        See :attr:`~aioredis.RedisConnection.pubsub_channels`\n        \"\"\"\n        return self._pool_or_conn.pubsub_channels\n\n    @property\n    def patterns(self):\n        \"\"\"Returns read-only patterns dict.\n\n        See :attr:`~aioredis.RedisConnection.pubsub_patterns`\n        \"\"\"\n        return self._pool_or_conn.pubsub_patterns\n\n    @property\n    def in_pubsub(self):\n        \"\"\"Indicates that connection is in PUB/SUB mode.\n\n        Provides the number of subscribed channels.\n        \"\"\"\n        return self._pool_or_conn.in_pubsub\n\n\nasync def wait_return_channels(fut, channels_dict):\n    return [channels_dict[name]\n            for cmd, name, count in await fut]\n", "path": "aioredis/commands/pubsub.py"}], "after_files": [{"content": "import json\n\nfrom aioredis.util import wait_make_dict\n\n\nclass PubSubCommandsMixin:\n    \"\"\"Pub/Sub commands mixin.\n\n    For commands details see: http://redis.io/commands/#pubsub\n    \"\"\"\n\n    def publish(self, channel, message):\n        \"\"\"Post a message to channel.\"\"\"\n        return self.execute(b'PUBLISH', channel, message)\n\n    def publish_json(self, channel, obj):\n        \"\"\"Post a JSON-encoded message to channel.\"\"\"\n        return self.publish(channel, json.dumps(obj))\n\n    def subscribe(self, channel, *channels):\n        \"\"\"Switch connection to Pub/Sub mode and\n        subscribe to specified channels.\n\n        Arguments can be instances of :class:`~aioredis.Channel`.\n\n        Returns :func:`asyncio.gather()` coroutine which when done will return\n        a list of :class:`~aioredis.Channel` objects.\n        \"\"\"\n        conn = self._pool_or_conn\n        return wait_return_channels(\n            conn.execute_pubsub(b'SUBSCRIBE', channel, *channels),\n            conn, 'pubsub_channels')\n\n    def unsubscribe(self, channel, *channels):\n        \"\"\"Unsubscribe from specific channels.\n\n        Arguments can be instances of :class:`~aioredis.Channel`.\n        \"\"\"\n        conn = self._pool_or_conn\n        return conn.execute_pubsub(b'UNSUBSCRIBE', channel, *channels)\n\n    def psubscribe(self, pattern, *patterns):\n        \"\"\"Switch connection to Pub/Sub mode and\n        subscribe to specified patterns.\n\n        Arguments can be instances of :class:`~aioredis.Channel`.\n\n        Returns :func:`asyncio.gather()` coroutine which when done will return\n        a list of subscribed :class:`~aioredis.Channel` objects with\n        ``is_pattern`` property set to ``True``.\n        \"\"\"\n        conn = self._pool_or_conn\n        return wait_return_channels(\n            conn.execute_pubsub(b'PSUBSCRIBE', pattern, *patterns),\n            conn, 'pubsub_patterns')\n\n    def punsubscribe(self, pattern, *patterns):\n        \"\"\"Unsubscribe from specific patterns.\n\n        Arguments can be instances of :class:`~aioredis.Channel`.\n        \"\"\"\n        conn = self._pool_or_conn\n        return conn.execute_pubsub(b'PUNSUBSCRIBE', pattern, *patterns)\n\n    def pubsub_channels(self, pattern=None):\n        \"\"\"Lists the currently active channels.\"\"\"\n        args = [b'PUBSUB', b'CHANNELS']\n        if pattern is not None:\n            args.append(pattern)\n        return self.execute(*args)\n\n    def pubsub_numsub(self, *channels):\n        \"\"\"Returns the number of subscribers for the specified channels.\"\"\"\n        return wait_make_dict(self.execute(\n            b'PUBSUB', b'NUMSUB', *channels))\n\n    def pubsub_numpat(self):\n        \"\"\"Returns the number of subscriptions to patterns.\"\"\"\n        return self.execute(b'PUBSUB', b'NUMPAT')\n\n    @property\n    def channels(self):\n        \"\"\"Returns read-only channels dict.\n\n        See :attr:`~aioredis.RedisConnection.pubsub_channels`\n        \"\"\"\n        return self._pool_or_conn.pubsub_channels\n\n    @property\n    def patterns(self):\n        \"\"\"Returns read-only patterns dict.\n\n        See :attr:`~aioredis.RedisConnection.pubsub_patterns`\n        \"\"\"\n        return self._pool_or_conn.pubsub_patterns\n\n    @property\n    def in_pubsub(self):\n        \"\"\"Indicates that connection is in PUB/SUB mode.\n\n        Provides the number of subscribed channels.\n        \"\"\"\n        return self._pool_or_conn.in_pubsub\n\n\nasync def wait_return_channels(fut, conn, field):\n    res = await fut\n    channels_dict = getattr(conn, field)\n    return [channels_dict[name] for cmd, name, count in res]\n", "path": "aioredis/commands/pubsub.py"}]}