-
Notifications
You must be signed in to change notification settings - Fork 8
/
run_util_reset_redis.py
48 lines (38 loc) · 1.45 KB
/
run_util_reset_redis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import sys
from src.store.redis.redis_api import RedisApi
from src.utils.config_parsers.internal_parsed import InternalConf
from src.utils.config_parsers.user_parsed import UserConf
from src.utils.exceptions import InitialisationException
from src.utils.logging import create_logger
def run() -> None:
# Check if Redis enabled
if not UserConf.redis_enabled:
raise InitialisationException('Redis is not set up. Run the setup '
'script to configure Redis.')
logger = create_logger(InternalConf.redis_log_file, 'redis',
InternalConf.logging_level)
print('Deleting all Redis keys.')
# Redis database
try:
RedisApi(
logger, InternalConf.redis_database, UserConf.redis_host,
UserConf.redis_port, password=UserConf.redis_password,
namespace=UserConf.unique_alerter_identifier
).delete_all_unsafe()
except Exception as e:
sys.exit(e)
# Redis test database
try:
RedisApi(
logger, InternalConf.redis_test_database, UserConf.redis_host,
UserConf.redis_port, password=UserConf.redis_password,
namespace=UserConf.unique_alerter_identifier
).delete_all_unsafe()
except Exception as e:
sys.exit(e)
print('Done deleting all Redis keys.')
if __name__ == '__main__':
try:
run()
except InitialisationException as ie:
sys.exit(ie)