@@ -332,17 +332,6 @@ async def all_collections(
332332        current_url  =  str (request .url )
333333        redis_enable  =  get_bool_env ("REDIS_ENABLE" , default = False )
334334
335-         redis  =  None 
336-         if  redis_enable :
337-             try :
338-                 redis  =  await  connect_redis ()
339-                 logger .info ("Redis connection established successfully" )
340-             except  Exception  as  e :
341-                 redis  =  None 
342-                 logger .warning (
343-                     f"Redis connection failed, continuing without Redis: { e }  
344-                 )
345- 
346335        # Convert q to a list if it's a string 
347336        q_list  =  None 
348337        if  q  is  not None :
@@ -441,6 +430,17 @@ async def all_collections(
441430            },
442431        ]
443432
433+         redis  =  None 
434+         if  redis_enable :
435+             try :
436+                 redis  =  await  connect_redis ()
437+                 logger .info ("Redis connection established successfully" )
438+             except  Exception  as  e :
439+                 redis  =  None 
440+                 logger .warning (
441+                     f"Redis connection failed, continuing without Redis: { e }  
442+                 )
443+ 
444444        if  redis_enable  and  redis :
445445            if  next_token :
446446                await  save_self_link (redis , next_token , current_url )
@@ -775,7 +775,6 @@ async def post_search(
775775            HTTPException: If there is an error with the cql2_json filter. 
776776        """ 
777777        base_url  =  str (request .base_url )
778-         redis_enable  =  get_bool_env ("REDIS_ENABLE" , default = False )
779778
780779        search  =  self .database .make_search ()
781780
@@ -901,6 +900,8 @@ async def post_search(
901900                )
902901        links .extend (collection_links )
903902
903+         redis_enable  =  get_bool_env ("REDIS_ENABLE" , default = False )
904+ 
904905        if  redis_enable :
905906            redis  =  None 
906907            try :
0 commit comments