Skip to content

Instantly share code, notes, and snippets.

@rjsnh1522
Created April 26, 2019 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjsnh1522/d17414fca578166ee72fda1fc95c70e9 to your computer and use it in GitHub Desktop.
Save rjsnh1522/d17414fca578166ee72fda1fc95c70e9 to your computer and use it in GitHub Desktop.
python-code-snippet
# To use redis in django
# in settings.py
REDIS = {
'host': 'localhost',
'port': 6379,
'db': 2
}
# make a singleton class and make one redis instance
import redis
from django.conf import settings as s
redis = redis.Redis(host=s.REDIS["host"],
port=s.REDIS["port"],
db=s.REDIS["db"],
encoding="utf-8",
decode_responses=True)
#when saving data
redis = Redis().get_redis_instance()
data = {
json_file_name: {
'user_id': request.user.id,
'from': 0,
'to': s.SENTENCE_LIMIT,
}
}
redis.hmset('readSentence', data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment