Skip to main content

This package provides a simple model structure for redis based storage.

Project description

Redis Models

This package provides a simple model structure for redis based storage. It acts like an ORM and allows you to create models with validation.

Installation

pip install redis_models

Usage

First, you need to create your model. It's similar to Pydantic models, or built-in dataclass.

from redis_models.models import RedisModel


class MyUserModel(RedisModel):
    name: str
    age: int

    class Meta:
        redis_url = "redis://localhost:6379/0"

Let's create a User object

user = User(name="John Doe", age=30)

Let's try creating an object that does not fit to the definition

try:
    bad_user = User(name="John", eye_color="blue")
except ValidationError:
    pass

Let's write it to Redis

user.save()

Let's see its id. ids are UUID4 hex strings

print(user.id)

Fetch the record from Redis

user_again = User.get(id=user.id)

See the object as dictionary

print(user.asd)

Let's delete the record

user_again.delete()

Trying to find a non-existing record throws NotFound exception

from redis_models.errors import NotFound

try:
    user_not_found = User.get(id=user_again.id)
except NotFound:
    print("User not found!")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

redis_models-0.2.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

redis_models-0.2.0-py2.py3-none-any.whl (4.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file redis_models-0.2.0.tar.gz.

File metadata

  • Download URL: redis_models-0.2.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for redis_models-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c9c3d4b31ffe0e3bcf4e0bf33bb3564e97736d4735a644311e7fe0e2890baeea
MD5 4c21eebe93bd476a306b579e8ceecdad
BLAKE2b-256 d0f1d2adfd3b2ff998e519609a61233feb4e816fcd8079741fe92f54cc794787

See more details on using hashes here.

File details

Details for the file redis_models-0.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for redis_models-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d897acd57ce71b57bd60fddc1f41269c405da3efb7097bdb6276c5c39b9729d0
MD5 7f1b1e77a8fbe75feda4d47d493d8115
BLAKE2b-256 ebd2b2df9b3400a7d5c17513b8d3380afb6010d78627a4381021116c28ca2b07

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page