Reputation: 43
I'm working on a project where there are like 30 to 40 gps trackers, I want to give the client the ability to select any tracker and then track its location. I was able to get the trackers to communicate using a django rest framework, being a real time application I'm using channels.
The database is divided such that the one table is for the trackers, and another table for tracking their current location. Using the seconds table I'm able to server the requested trackers location to the user.
I wanted to know if there is a way for me to implement django rest framework with redis, such that the post request from the tracker is directly cached, instead of inserting or updating in the database. The historical location of the trackers is not important to me, just their current location.
Upvotes: 2
Views: 1295
Reputation: 15758
You can store your coordinates directly in redis withouth need of database access.
For example:
import redis
redis_instance = redis.StrictRedis(host=settings.REDIS_HOST,
port=settings.REDIS_PORT, db=0)
redis_instance.set(kwargs['key'], new_value)
and get value from it
redis_instance.redis_instance.get(key)
Same you could do by utilizing Django cache ( when you configure it to use redis)
from django.core.cache import cache
cache.set('my_key', 'hello, world!', None)
cache.get('my_key')
Upvotes: 2