File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -83,13 +83,11 @@ def cache_write(app_id, data):
8383 # return failed status
8484 return False
8585
86-
87- def redis_read (app_id ):
86+ def redis_connection ():
8887 """
89- Read app info from Redis cache .
88+ Parse redis config and connect .
9089 """
9190
92- # parse redis config and connect
9391 # try connection string, or default to separate REDIS_* env vars
9492 if "REDIS_URL" in os .environ :
9593 rds = redis .Redis .from_url (os .environ ["REDIS_URL" ])
@@ -100,6 +98,16 @@ def redis_read(app_id):
10098 password = os .environ ["REDIS_PASSWORD" ],
10199 )
102100
101+ # return connection
102+ return rds
103+
104+ def redis_read (app_id ):
105+ """
106+ Read app info from Redis cache.
107+ """
108+
109+ rds = redis_connection ()
110+
103111 try :
104112 # get info from cache
105113 data = rds .get (app_id )
@@ -134,13 +142,8 @@ def redis_write(app_id, data):
134142 Write app info to Redis cache.
135143 """
136144
137- # parse redis config and connect
138- rds = redis .Redis (
139- host = os .environ ["REDIS_HOST" ],
140- port = os .environ ["REDIS_PORT" ],
141- password = os .environ ["REDIS_PASSWORD" ],
142- )
143-
145+ rds = redis_connection ()
146+
144147 # write cache data and set ttl
145148 try :
146149 # convert dict to json
You can’t perform that action at this time.
0 commit comments