-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
33 lines (30 loc) · 1.01 KB
/
Copy pathdatabase.py
File metadata and controls
33 lines (30 loc) · 1.01 KB
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
import logging
from redis.asyncio import Redis, ConnectionPool
from typing import Optional
from config_reader import config
connection_params = {
'host': config.redis_host.get_secret_value(),
'port': int(config.redis_port.get_secret_value()),
'decode_responses': True,
'username': config.redis_username.get_secret_value(),
'password': config.redis_password.get_secret_value(),
'protocol': 3
}
connection_pool = ConnectionPool(**connection_params)
async def get_file_id(filename: str) -> str|None:
r = Redis().from_pool(connection_pool)
file_id = await r.get(filename)
await r.close()
assert isinstance(file_id, Optional[str])
return file_id
async def set_file_id(filename: str, file_id: str) -> bool:
r = Redis().from_pool(connection_pool)
try:
await r.set(filename, file_id)
success = True
except Exception as e:
logging.error(f'Error during insert to database: {e}')
success = False
finally:
await r.close()
return success