Updated syntax for async handlers
authorThierry Florac <tflorac@ulthar.net>
Sun, 14 Jan 2018 12:23:07 +0100
changeset 12 6d51d3409b54
parent 11 191d9ec5136a
child 13 5a6cadfd5b72
Updated syntax for async handlers
src/pyams_cache/handler/memcached.py
src/pyams_cache/handler/redis.py
--- a/src/pyams_cache/handler/memcached.py	Mon Dec 11 15:26:55 2017 +0100
+++ b/src/pyams_cache/handler/memcached.py	Sun Jan 14 12:23:07 2018 +0100
@@ -65,8 +65,8 @@
             ip, port = server.split(':')
             self.client = MemcachedClient(ip, int(port))
 
-        def get(self, key, default=None):
-            yield from self.client.get(key, default)
+        async def get(self, key, default=None):
+            return await self.client.get(key, default)
 
-        def set(self, key, value):
-            yield from self.client.set(key, value)
+        async def set(self, key, value):
+            await self.client.set(key, value)
--- a/src/pyams_cache/handler/redis.py	Mon Dec 11 15:26:55 2017 +0100
+++ b/src/pyams_cache/handler/redis.py	Sun Jan 14 12:23:07 2018 +0100
@@ -66,10 +66,15 @@
             ip, port = server.split(':')
             self.connection = ip, int(port)
 
-        def get(self, key, default=None):
-            connection = yield from aioredis.create_connection(self.connection)
-            yield from connection.execute('get', key)
+        async def get(self, key, default=None):
+            connection = await aioredis.create_connection(self.connection)
+            value = await connection.execute('get', key)
+            connection.close()
+            await connection.wait_closed()
+            return value
 
-        def set(self, key, value):
-            connection = yield from aioredis.create_connection(self.connection)
-            yield from connection.execute('set', key, value)
+        async def set(self, key, value):
+            connection = await aioredis.create_connection(self.connection)
+            await connection.execute('set', key, value)
+            connection.close()
+            await connection.wait_closed()