This commit is contained in:
commit
279b2a7e90
49 files changed
+2664
No files matched your search
@@ -0,0 +1,24 @@
|
||||
import redis
|
||||
from redis.backoff import ExponentialBackoff
|
||||
from redis.exceptions import ConnectionError, TimeoutError
|
||||
from redis.retry import Retry
|
||||
|
||||
from config import settings
|
||||
|
||||
r: redis.Redis | None = None
|
||||
if not settings.redis.enabled:
|
||||
r = None
|
||||
else:
|
||||
r = redis.Redis(
|
||||
host=settings.redis.host,
|
||||
port=settings.redis.port,
|
||||
password=settings.redis.password,
|
||||
decode_responses=True,
|
||||
socket_connect_timeout=2,
|
||||
socket_timeout=2,
|
||||
socket_keepalive=True,
|
||||
health_check_interval=30,
|
||||
retry_on_timeout=True,
|
||||
retry=Retry(ExponentialBackoff(cap=10, base=0.5), retries=0),
|
||||
retry_on_error=[ConnectionError, TimeoutError],
|
||||
)
|
||||
@@ -0,0 +1,19 @@
|
||||
import json
|
||||
|
||||
from config import settings
|
||||
from loon.redis import r
|
||||
|
||||
|
||||
def set_chunk_cache(x: int, z: int, chunk_payload):
|
||||
r.setex(f'{x}:{z}', settings.redis.expire_time, str(json.dumps(chunk_payload)))
|
||||
|
||||
def get_chunk_cache(x: int, z: int):
|
||||
chunk = r.get(f'{x}:{z}')
|
||||
|
||||
if chunk:
|
||||
return json.loads(chunk)
|
||||
|
||||
return None
|
||||
|
||||
def reset_chunk_cache(x: int, z: int):
|
||||
return r.delete(f'{x}:{z}')
|
||||
Reference in new issue
Block a user