aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby <[email protected]>2023-11-10 23:49:33 -0500
committerBobby <[email protected]>2023-11-10 23:49:33 -0500
commit9f5c83865ebcca3293d8f30dea6ea6fa8ed5abc2 (patch)
treea61e00f74fd8b6222f7c34e29bd25f7243e33a72
parenta79e6040f7d79c658374ceab26f90bd9f1d9ea59 (diff)
downloadthatcomputerscientist-9f5c83865ebcca3293d8f30dea6ea6fa8ed5abc2.tar.xz
thatcomputerscientist-9f5c83865ebcca3293d8f30dea6ea6fa8ed5abc2.zip
Moved to Redis Cloud
-rw-r--r--chat/chat_cache.py12
-rw-r--r--middleware/uuidmiddleware.py10
-rw-r--r--thatcomputerscientist/settings.py13
3 files changed, 30 insertions, 5 deletions
diff --git a/chat/chat_cache.py b/chat/chat_cache.py
index 43354ef7..8c107a6c 100644
--- a/chat/chat_cache.py
+++ b/chat/chat_cache.py
@@ -2,7 +2,17 @@ import json
import redis
-r = redis.Redis(host='localhost', port=6379, db=0)
+import os
+from dotenv import load_dotenv
+
+load_dotenv()
+
+r = redis.Redis(
+ host=os.getenv('REDIS_HOST'),
+ port=os.getenv('REDIS_PORT'),
+ password=os.getenv('REDIS_PASSWORD'),
+ db=0
+)
def handle_connect():
# increase number of connected users
diff --git a/middleware/uuidmiddleware.py b/middleware/uuidmiddleware.py
index a6dd1ca3..42fe5903 100644
--- a/middleware/uuidmiddleware.py
+++ b/middleware/uuidmiddleware.py
@@ -2,9 +2,17 @@ import json
import uuid
import redis
+import os
+from dotenv import load_dotenv
-redis_instance = redis.StrictRedis(host='localhost', port=6379, db=0)
+load_dotenv()
+redis_instance = redis.StrictRedis(
+ host=os.getenv('REDIS_HOST'),
+ port=os.getenv('REDIS_PORT'),
+ password=os.getenv('REDIS_PASSWORD'),
+ db=0
+)
class UserUUIDMiddleware:
# assign a uuid to the user if they don't have one
diff --git a/thatcomputerscientist/settings.py b/thatcomputerscientist/settings.py
index 8632a951..1ca6b2df 100644
--- a/thatcomputerscientist/settings.py
+++ b/thatcomputerscientist/settings.py
@@ -24,7 +24,13 @@ BASE_DIR = Path(__file__).resolve().parent.parent
import redis
-r = redis.Redis(host='localhost', port=6379, db=0)
+# r = redis.Redis(host='localhost', port=6379, db=0)
+r = redis.Redis(
+ host=os.getenv('REDIS_HOST'),
+ port=os.getenv('REDIS_PORT'),
+ password=os.getenv('REDIS_PASSWORD'),
+ db=0
+)
r.set('n_connected_lc_users', 0)
# Quick-start development settings - unsuitable for production
@@ -140,7 +146,7 @@ CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
- "hosts": [("127.0.0.1", 6379)],
+ "hosts": [(f'redis://:{os.getenv("REDIS_PASSWORD")}@{os.getenv("REDIS_HOST")}:{os.getenv("REDIS_PORT")}')],
},
},
}
@@ -177,9 +183,10 @@ AUTH_PASSWORD_VALIDATORS = [
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
- "LOCATION": "redis://127.0.0.1:6379/1",
+ "LOCATION": f"redis://{os.getenv('REDIS_HOST')}:{os.getenv('REDIS_PORT')}",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
+ "PASSWORD": os.getenv('REDIS_PASSWORD'),
}
}
}