Skip to content

Commit 2767536

Browse files
pepijndevosask
authored andcommitted
Use pipeline for _set
This reduces the number of connections used, as every command takes a connection from the pool and returns it afterwards.
1 parent 0ed4732 commit 2767536

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

celery/backends/redis.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,13 @@ def set(self, key, value, **retry_policy):
148148
return self.ensure(self._set, (key, value), **retry_policy)
149149

150150
def _set(self, key, value):
151-
client = self.client
151+
pipe = self.client.pipeline()
152152
if self.expires:
153-
client.setex(key, value, self.expires)
153+
pipe.setex(key, value, self.expires)
154154
else:
155-
client.set(key, value)
156-
client.publish(key, value)
155+
pipe.set(key, value)
156+
pipe.publish(key, value)
157+
pipe.execute()
157158

158159
def delete(self, key):
159160
self.client.delete(key)

0 commit comments

Comments
 (0)