Skip to content

Set a Global Prefix in Node Om #184

@thisiseddy-ab

Description

@thisiseddy-ab

I'm Trying to use Redis Om for Node and Python,python has a Meta "global_key_prefix" variable.I Found no such thing for Node OM, a solution a found is to set for every schema prefix like this prefix: ${global_prefix}:User.
It Works i just wondering is there an another way

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 : str = Field(primary_key=True,index=True,default=str(ULID()))
    username: str = Field(index=True)
    name: str
    lastname: str
class User extends Entity{
}

const User_Schema = new Schema(User,{
    My_Id: { type: 'string', indexed: true },
    username : { type: 'string', indexed: true },
    name: { type: 'string', indexed: false },
    lastname: { type: 'string', indexed: false },
},{
    dataStructure: 'JSON',
    prefix: `${RPU_REDIS_DATA_PREFIX}:User`,
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions