forked from zaclys/searxng
		
	[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>
This commit is contained in:
		
							parent
							
								
									a6cfab93fa
								
							
						
					
					
						commit
						dca83944b5
					
				
					 1 changed files with 7 additions and 1 deletions
				
			
		|  | @ -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(): | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Markus Heiser
						Markus Heiser