skip to Main Content

I want to implement consistent hashing in django with redis as my cache DB.
Firstly I tried utilising uhashing(https://pypi.org/project/uhashring/) package to implement consistent hashing with redis but I am unable to provide link between django and the package.
The second thing I did is searching for Configuring Redis with consistent hashing in django itself but I am unable to find anything related. I can only find configuring redis with memcached.

Is there any way to get solution for my problem.
Any small hint will also be helpful, Thank you.

2

Answers


  1. Chosen as BEST ANSWER

    I just found some solution to my question.

    The external package which I want to use is need to be added to the installed apps in the seetings.py file so the there is no need to especially connect django to the script in which the package is used. This package is imported and utilised in the views.py.

    Thanks for the help, cheers..!


  2. Why not simple generate a key based on a string you can more easily control and read?

    Examples:
    If you are caching a specific users list of posts you could simply generate the key like so. There is no specific need to use a hashing algorithm if you can generate the keys from string values.

    < f'user.{user.id}.posts'
    
    > 'user.1.posts'
    

    Example:
    If you are caching a companies list of staff:

    < f'company.{company.id}.staff'
    
    > 'company.5693667b-f8a7-4dc6-9171-a3941c4a97ad.posts'
    

    Example:
    Caching the result of a complex query by a user:

    < f'user.{user.id}.search-query.{base64.b64encode(<querystring>)}'
    
    > 'user.1.search-query.c3VwZXItc3BlY2lhbC1xdWVyeS1zdHJpbmc='
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search