|  | 
| 19 | 19 | from stac_pydantic.links import Relations | 
| 20 | 20 | from stac_pydantic.shared import BBox, MimeTypes | 
| 21 | 21 | from stac_pydantic.version import STAC_VERSION | 
|  | 22 | +from stac_fastapi.core.utilities import get_bool_env | 
| 22 | 23 | 
 | 
| 23 | 24 | from stac_fastapi.core.base_database_logic import BaseDatabaseLogic | 
| 24 | 25 | from stac_fastapi.core.base_settings import ApiBaseSettings | 
| @@ -277,11 +278,13 @@ async def all_collections( | 
| 277 | 278 |                 sort = parsed_sort | 
| 278 | 279 | 
 | 
| 279 | 280 |         current_url = str(request.url) | 
| 280 |  | -        redis = None | 
| 281 |  | -        try: | 
| 282 |  | -            redis = await connect_redis_sentinel() | 
| 283 |  | -        except Exception: | 
| 284 |  | -            redis = None | 
|  | 281 | +        redis_enable = get_bool_env("REDIS_ENABLE", default=False) | 
|  | 282 | + | 
|  | 283 | +        if redis_enable: | 
|  | 284 | +            try: | 
|  | 285 | +                redis = await connect_redis_sentinel() | 
|  | 286 | +            except Exception: | 
|  | 287 | +                redis = None | 
| 285 | 288 | 
 | 
| 286 | 289 |         # Convert q to a list if it's a string | 
| 287 | 290 |         q_list = None | 
| @@ -311,7 +314,7 @@ async def all_collections( | 
| 311 | 314 |             }, | 
| 312 | 315 |         ] | 
| 313 | 316 | 
 | 
| 314 |  | -        if redis: | 
|  | 317 | +        if redis_enable and redis: | 
| 315 | 318 |             if next_token: | 
| 316 | 319 |                 await save_self_link(redis, next_token, current_url) | 
| 317 | 320 | 
 | 
| @@ -557,10 +560,14 @@ async def post_search( | 
| 557 | 560 |             HTTPException: If there is an error with the cql2_json filter. | 
| 558 | 561 |         """ | 
| 559 | 562 |         base_url = str(request.base_url) | 
| 560 |  | -        try: | 
| 561 |  | -            redis = await connect_redis_sentinel() | 
| 562 |  | -        except Exception: | 
| 563 |  | -            redis = None | 
|  | 563 | +        redis_enable = get_bool_env("REDIS_ENABLE", default=False) | 
|  | 564 | + | 
|  | 565 | +        redis = None | 
|  | 566 | +        if redis_enable: | 
|  | 567 | +            try: | 
|  | 568 | +                redis = await connect_redis_sentinel() | 
|  | 569 | +            except Exception: | 
|  | 570 | +                redis = None | 
| 564 | 571 | 
 | 
| 565 | 572 |         search = self.database.make_search() | 
| 566 | 573 | 
 | 
| @@ -690,7 +697,7 @@ async def post_search( | 
| 690 | 697 |                 ) | 
| 691 | 698 |         links.extend(collection_links) | 
| 692 | 699 | 
 | 
| 693 |  | -        if redis: | 
|  | 700 | +        if redis_enable and redis: | 
| 694 | 701 |             self_link = str(request.url) | 
| 695 | 702 |             await save_self_link(redis, next_token, self_link) | 
| 696 | 703 | 
 | 
|  | 
0 commit comments