import requests import os import logging from redis import Redis logging.basicConfig() logging.getLogger().setLevel(logging.INFO) log = logging.getLogger(__name__) REDIS_HOST = os.environ['REDIS_HOST'] REDIS_PORT = os.environ['REDIS_PORT'] REDIS_EVENT_LOG_STREAM = os.environ['REDIS_EVENT_LOG_STREAM'] REDIS_MREADINGS_NOT_VALIDATED_STREAM = os.environ['REDIS_MREADINGS_NOT_VALIDATED_STREAM'] REDIS_MREADINGS_VALIDATED_STREAM = os.environ['REDIS_MREADINGS_VALIDATED_STREAM'] REDIS_PASSWORD = os.getenv('REDIS_PASSWORD') REDIS_TRIM = os.getenv('REDIS_TRIM') if __name__ == '__main__': try: redis = Redis(host=REDIS_HOST, port=REDIS_PORT, password=REDIS_PASSWORD) deleted_entries = redis.xtrim(REDIS_EVENT_LOG_STREAM,REDIS_TRIM) log.info(f'Removed {deleted_entries} old entries from {REDIS_EVENT_LOG_STREAM}') deleted_entries = redis.xtrim(REDIS_MREADINGS_VALIDATED_STREAM,REDIS_TRIM) log.info(f'Removed {deleted_entries} old entries {REDIS_MREADINGS_VALIDATED_STREAM}') deleted_entries = redis.xtrim(REDIS_MREADINGS_NOT_VALIDATED_STREAM,REDIS_TRIM) log.info(f'Removed {deleted_entries} old entries from {REDIS_MREADINGS_NOT_VALIDATED_STREAM}') except Exception as e: log.error(e)