diff --git a/channels/backends/database.py b/channels/backends/database.py index fdc866a..d1514fa 100644 --- a/channels/backends/database.py +++ b/channels/backends/database.py @@ -168,3 +168,6 @@ class DatabaseChannelBackend(BaseChannelBackend): def __str__(self): return "%s(alias=%s)" % (self.__class__.__name__, self.connection.alias) + + def flush(self): + pass diff --git a/channels/backends/memory.py b/channels/backends/memory.py index 1d78363..9fff16c 100644 --- a/channels/backends/memory.py +++ b/channels/backends/memory.py @@ -92,3 +92,9 @@ class InMemoryChannelBackend(BaseChannelBackend): Unlocks the named channel. Always succeeds. """ locks.discard(channel) + + def flush(self): + global queues, groups, locks + queues = {} + groups = {} + locks = set() diff --git a/channels/backends/redis_py.py b/channels/backends/redis_py.py index df81a35..f48f799 100644 --- a/channels/backends/redis_py.py +++ b/channels/backends/redis_py.py @@ -61,11 +61,6 @@ class RedisChannelBackend(BaseChannelBackend): host, port = self.hosts[index] return redis.Redis(host=host, port=port) - @property - def connections(self): - for i in range(len(self.hosts)): - return self.connection(i) - def send(self, channel, message): # if channel is no str (=> bytes) convert it if not isinstance(channel, str): @@ -189,3 +184,7 @@ class RedisChannelBackend(BaseChannelBackend): def __str__(self): return "%s(hosts=%s)" % (self.__class__.__name__, self.hosts) + + def flush(self): + for i in range(self.ring_size): + self.connection(i).flushdb() diff --git a/channels/tests/test_backends.py b/channels/tests/test_backends.py index 3d63e0e..c2cbba6 100644 --- a/channels/tests/test_backends.py +++ b/channels/tests/test_backends.py @@ -13,6 +13,7 @@ class MemoryBackendTests(TestCase): def setUp(self): self.backend = self.backend_class(routing={}) + self.backend.flush() def test_send_recv(self): """