From 1bb0aa7433ec5f9d1bc6252204c8d6e8a682396c Mon Sep 17 00:00:00 2001 From: Bobby Date: Sun, 28 May 2023 00:41:28 -0400 Subject: Post show view count now, Django session uses redis cache --- chat/chat_cache.py | 3 ++- chat/consumers.py | 8 ++++++-- chat/routing.py | 1 + chat/skippy.py | 1 + 4 files changed, 10 insertions(+), 3 deletions(-) (limited to 'chat') diff --git a/chat/chat_cache.py b/chat/chat_cache.py index 08cbf178..43354ef7 100644 --- a/chat/chat_cache.py +++ b/chat/chat_cache.py @@ -1,6 +1,7 @@ -import redis import json +import redis + r = redis.Redis(host='localhost', port=6379, db=0) def handle_connect(): diff --git a/chat/consumers.py b/chat/consumers.py index 0b3017c4..da81449c 100644 --- a/chat/consumers.py +++ b/chat/consumers.py @@ -1,9 +1,13 @@ import json -from channels.generic.websocket import WebsocketConsumer + from asgiref.sync import async_to_sync -from .chat_cache import handle_connect, handle_disconnect, handle_alone_user, discard_user_messages +from channels.generic.websocket import WebsocketConsumer + +from .chat_cache import (discard_user_messages, handle_alone_user, + handle_connect, handle_disconnect) from .skippy import invokeMFSkippy + class ChatConsumer(WebsocketConsumer): def connect(self): self.room_group_name = "chat" diff --git a/chat/routing.py b/chat/routing.py index 69101be1..fe6b4681 100644 --- a/chat/routing.py +++ b/chat/routing.py @@ -1,4 +1,5 @@ from django.urls import re_path + from . import consumers websocket_urlpatterns = [ diff --git a/chat/skippy.py b/chat/skippy.py index bf6ab6ac..6fa3aaa1 100644 --- a/chat/skippy.py +++ b/chat/skippy.py @@ -1,5 +1,6 @@ from .chat_cache import get_user_messages, save_user_messages + def invokeMFSkippy(message, identifier): save_user_messages(user_identifier=identifier, message={'content': message, 'role': 'user'}) user_messages = get_user_messages(user_identifier=identifier) -- cgit v1.2.3