Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Properly Inheret Base and set Model Key Prefix #509

Open
thisiseddy-ab opened this issue May 10, 2023 · 0 comments
Open

How to Properly Inheret Base and set Model Key Prefix #509

thisiseddy-ab opened this issue May 10, 2023 · 0 comments

Comments

@thisiseddy-ab
Copy link

thisiseddy-ab commented May 10, 2023

I've Seen this video NoSQL Data Modeling with Redis: Building 1-to-Many Relationships , he inherits the base and sets the model key prefix.But he never shows the base code i have no idea how he does it.

###This is with what i cam up

def Base(model_prefix):
    class BaseModel():
        class Meta:
            global_key_prefix = RPU_REDIS_DATA_PREFIX
            model_key_prefix = model_prefix
            database =  get_redis_connection(host=RPU_REDIS_DATA_HOST,port=RPU_REDIS_DATA_PORT,db=RPU_REDIS_DATA_DB,decode_responses=True)
    return BaseModel

class User(Base("User"),JsonModel):
    My_Id : Optional[str] = Field(primary_key=True,index=True,default=str(ULID()))
    username: str = Field(index=True)
    name: str
    lastname: str

I don't know is this right how to write the BASE and if it creates a connection for every model this will be bad ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant