Replace execute_command with specific redis functions when possible (#346)
* replace execute_command * change to root_path
This commit is contained in:
parent
60f102d188
commit
57608d85f4
3 changed files with 8 additions and 7 deletions
|
|
@ -31,6 +31,7 @@ from pydantic.fields import ModelField, Undefined, UndefinedType
|
|||
from pydantic.main import ModelMetaclass, validate_model
|
||||
from pydantic.typing import NoArgAnyCallable
|
||||
from pydantic.utils import Representation
|
||||
from redis.commands.json.path import Path
|
||||
from typing_extensions import Protocol, get_args, get_origin
|
||||
from ulid import ULID
|
||||
|
||||
|
|
@ -1490,7 +1491,7 @@ class JsonModel(RedisModel, abc.ABC):
|
|||
db = self._get_db(pipeline)
|
||||
|
||||
# TODO: Wrap response errors in a custom exception?
|
||||
await db.execute_command("JSON.SET", self.key(), ".", self.json())
|
||||
await db.json().set(self.key(), Path.root_path(), json.loads(self.json()))
|
||||
return self
|
||||
|
||||
@classmethod
|
||||
|
|
@ -1535,8 +1536,8 @@ class JsonModel(RedisModel, abc.ABC):
|
|||
|
||||
@classmethod
|
||||
async def get(cls, pk: Any) -> "JsonModel":
|
||||
document = await cls.db().execute_command("JSON.GET", cls.make_primary_key(pk))
|
||||
if not document:
|
||||
document = json.dumps(await cls.db().json().get(cls.make_key(pk)))
|
||||
if document == "null":
|
||||
raise NotFoundError
|
||||
return cls.parse_raw(document)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue