@@ -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,20 +430,29 @@ async def all_collections(
441430            },
442431        ]
443432
444-         if  redis_enable  and  redis :
445-             if  next_token :
446-                 await  save_self_link (redis , next_token , current_url )
447- 
448-             prev_link  =  await  get_prev_link (redis , token )
449-             if  prev_link :
450-                 links .insert (
451-                     0 ,
452-                     {
453-                         "rel" : "prev" ,
454-                         "type" : "application/json" ,
455-                         "method" : "GET" ,
456-                         "href" : prev_link ,
457-                     },
433+         redis  =  None 
434+         if  redis_enable :
435+             try :
436+                 redis  =  await  connect_redis ()
437+                 logger .info ("Redis connection established successfully" )
438+                 if  redis  and  next_token :
439+                     await  save_self_link (redis , next_token , current_url )
440+ 
441+                     prev_link  =  await  get_prev_link (redis , token )
442+                     if  prev_link :
443+                         links .insert (
444+                             0 ,
445+                             {
446+                                 "rel" : "prev" ,
447+                                 "type" : "application/json" ,
448+                                 "method" : "GET" ,
449+                                 "href" : prev_link ,
450+                             },
451+                         )
452+             except  Exception  as  e :
453+                 redis  =  None 
454+                 logger .warning (
455+                     f"Redis connection failed, continuing without Redis: { e }  
458456                )
459457
460458        if  next_token :
@@ -906,20 +904,21 @@ async def post_search(
906904            try :
907905                redis  =  await  connect_redis ()
908906                logger .info ("Redis connection established successfully" )
909-                 self_link  =  str (request .url )
910-                 await  save_self_link (redis , next_token , self_link )
911- 
912-                 prev_link  =  await  get_prev_link (redis , token_param )
913-                 if  prev_link :
914-                     links .insert (
915-                         0 ,
916-                         {
917-                             "rel" : "prev" ,
918-                             "type" : "application/json" ,
919-                             "method" : "GET" ,
920-                             "href" : prev_link ,
921-                         },
922-                     )
907+                 if  redis  and  next_token :
908+                     self_link  =  str (request .url )
909+                     await  save_self_link (redis , next_token , self_link )
910+ 
911+                     prev_link  =  await  get_prev_link (redis , token_param )
912+                     if  prev_link :
913+                         links .insert (
914+                             0 ,
915+                             {
916+                                 "rel" : "prev" ,
917+                                 "type" : "application/json" ,
918+                                 "method" : "GET" ,
919+                                 "href" : prev_link ,
920+                             },
921+                         )
923922            except  Exception  as  e :
924923                logger .warning (
925924                    f"Redis connection failed, continuing without Redis: { e }  
0 commit comments