redis-om-python icon indicating copy to clipboard operation
redis-om-python copied to clipboard

Does this package support for redis cluster?

Open TsaiZX opened this issue 3 years ago • 3 comments

This package is helpful for the single-node Redis. But when I use it on the Redis cluster, I got the below error

Screenshot from 2022-03-30 15-56-29

So I wonder know this package supports Redis cluster version now?

TsaiZX avatar Mar 30 '22 07:03 TsaiZX

Hello! I'm not sure that it will work, but I want to try something like this

class Test(JsonModel):
    id: int 

    class Meta:
        database = RedisCluster(startup_nodes=redis_conf, decode_responses=True)

DennyD17 avatar May 12 '22 10:05 DennyD17

There is indeed basic cluster support. However, some commands do fail

import datetime
from typing import Optional

from pydantic import EmailStr

from redis_om import (
    Field,
    HashModel,
    JsonModel,
    Migrator,
    get_redis_connection
)


redis_conn = get_redis_connection(
    url=f"redis://10.9.9.5:7002",
    decode_responses=True,
    password="D1ngD0ng"
)

class Customer(HashModel):
    first_name: str
    last_name: str = Field(index=True)
    email: EmailStr
    join_date: datetime.date
    age: int = Field(index=True)
    bio: Optional[str]
    class Meta:
        database = redis_conn


 # First, we create a new `Customer` object:
andrew = Customer(
    first_name="Andrew",
    last_name="Brookins",
    email="[email protected]",
    join_date=datetime.date.today(),
    age=38,
    bio="Python developers, works at Redis, Inc."
)

 # The model generates a globally unique primary key automatically without needing to talk to Redis.
print(andrew.pk)
> "01FJM6PH661HCNNRC884H6K30C"

 # We can save the model to Redis by calling `save()`:
Migrator().run()
andrew.save()


 # Expire the model after 2 mins (120 seconds)
andrew.expire(120)


 # To retrieve this customer with its primary key, we use `Customer.get()`:
assert Customer.get(andrew.pk) == andrew
print(Customer.get(andrew.pk))

print(Customer.find(Customer.age == 38).all()) # This line fails

XChikuX avatar Nov 04 '22 23:11 XChikuX

Mentioning #412 here to track.

XChikuX avatar Jan 17 '23 10:01 XChikuX