summaryrefslogtreecommitdiff
path: root/searx
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2022-01-07 17:29:32 +0100
committerMarkus Heiser <markus.heiser@darmarit.de>2022-01-07 17:33:40 +0100
commitdca83944b588be3ec9e49486daea6cf15ef58f78 (patch)
treea69762bf67f8f1f4ca566d84eee15411cd017201 /searx
parenta6cfab93fa7c1b1f0a04c073df42b50f2834d845 (diff)
downloadsearxng-dca83944b588be3ec9e49486daea6cf15ef58f78.tar.gz
searxng-dca83944b588be3ec9e49486daea6cf15ef58f78.zip
[fix] redis: don't create a new connection at each client() call
Suggested-by: @dalf https://github.com/searxng/searxng/pull/686#pullrequestreview-844942973 Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx')
-rw-r--r--searx/shared/redisdb.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/searx/shared/redisdb.py b/searx/shared/redisdb.py
index 613b82a38..da71d169c 100644
--- a/searx/shared/redisdb.py
+++ b/searx/shared/redisdb.py
@@ -24,10 +24,16 @@ import redis
from searx import get_setting
logger = logging.getLogger('searx.shared.redis')
+_client = None
def client():
- return redis.Redis.from_url(get_setting('redis.url'))
+ global _client # pylint: disable=global-statement
+ if _client is None:
+ # not thread safe: in the worst case scenario, two or more clients are
+ # initialized only one is kept, the others are garbage collected.
+ _client = redis.Redis.from_url(get_setting('redis.url'))
+ return _client
def init():