Explorar el Código

Use pipeline for _set

This reduces the number of connections used, as every command takes a connection from the pool and returns it afterwards.
Pepijn de Vos hace 11 años
padre
commit
276753698a
Se han modificado 1 ficheros con 5 adiciones y 4 borrados
  1. 5 4
      celery/backends/redis.py

+ 5 - 4
celery/backends/redis.py

@@ -148,12 +148,13 @@ class RedisBackend(KeyValueStoreBackend):
         return self.ensure(self._set, (key, value), **retry_policy)
 
     def _set(self, key, value):
-        client = self.client
+        pipe = self.client.pipeline()
         if self.expires:
-            client.setex(key, value, self.expires)
+            pipe.setex(key, value, self.expires)
         else:
-            client.set(key, value)
-        client.publish(key, value)
+            pipe.set(key, value)
+        pipe.publish(key, value)
+        pipe.execute()
 
     def delete(self, key):
         self.client.delete(key)