Add dbm defs and remove memcache

This commit is contained in:
Даня Вакуленков 2024-12-15 01:21:54 +03:00
parent df4e6a685b
commit e80ec3730e
2 changed files with 14 additions and 12 deletions

14
bot/dbm_defs.py Normal file
View File

@ -0,0 +1,14 @@
import dbm
DB_FILE = 'data.dbm'
def add_rec(key, value):
with dbm.open(DB_FILE, 'c') as db:
db[str(key)] = str(value)
def get_rec(key):
with dbm.open(DB_FILE, 'r') as db:
value = db.get(str(key))
if value is None:
raise KeyError(f"Key '{key}' not found in the database.")
return int(value)

View File

@ -1,12 +0,0 @@
import os
from pymemcache.client import base
client = base.Client((os.getenv('MEMCACHED_HOST', 'localhost'), os.getenv('MEMCACHED_PORT', 11211)))
def add_rec(key, value):
client.set(str(key), value)
def get_rec(key):
value = client.get(str(key))
return (int(value))