Created
April 26, 2019 06:21
-
-
Save rjsnh1522/d17414fca578166ee72fda1fc95c70e9 to your computer and use it in GitHub Desktop.
python-code-snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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