production-evyos-systems-an.../ServicesTask/app/core/utils.py

16 lines
390 B
Python

import json
import time
from typing import Any, Dict
def now_ms() -> int:
return int(time.time() * 1000)
def jd(obj: Dict[str, Any]) -> Dict[bytes, bytes]:
"""JSON to Redis fields."""
return {"data": json.dumps(obj).encode("utf-8")}
def jl(fields: Dict[bytes, bytes]) -> Dict[str, Any]:
"""Redis fields to JSON."""
return json.loads(fields[b"data"].decode("utf-8"))