0

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 2

0

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='
Sign up to request clarification or add additional context in comments.

3 Comments

I need to use more than one redis(as per orders), for this to happen and for data to be uniformly distributed best option is consistent hashing. I hope you got me..!
one redis(as per orders)? Can you give more information please.
For example let us take that I should use three redis dbs, for uniform distribution of data among dbs I should implement consistent hashing by placing the redis dbs on hashring(toptal.com/big-data/consistent-hashing). The data(as request) is received from django server, so I got a problem that how to connect django with this consistent hashing along redis.
0

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..!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.