Add dbm defs and remove memcache
This commit is contained in:
parent
df4e6a685b
commit
e80ec3730e
14
bot/dbm_defs.py
Normal file
14
bot/dbm_defs.py
Normal 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)
|
|
@ -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))
|
|
Loading…
Reference in New Issue
Block a user