jrief / django-websocket-redis

Websockets for Django applications using Redis as message queue
http://django-websocket-redis.awesto.com/
MIT License
897 stars 222 forks source link

Saving messages to database #269

Closed nrgx closed 6 years ago

nrgx commented 6 years ago

I've build chat application, everything works fine. But I want to save those messages and after user reloads the browser they are retrieved from database. Also, where should I proceed save in post function or somewhere else. By the way, when I write several messages to the input and then reload it, only last message shown. I don't understand why I receive this strange behavior.

2DKot commented 6 years ago

I save messages to postgres in POST handler just before redis_publisher.publish_message(redis_message) and it works fine.

By the way, when I write several messages to the input and then reload it, only last message shown.

Do you trying to load old messages from redis? You shouldn't use redis to persist messages. Also, you may receive message after reconnecting because of WS4REDIS_EXPIRE is not 0. You should set WS4REDIS_EXPIRE = 0 to receive only new messages via webscocket. Use GET request to receive old messages from database.

Sorry for my bad English. I hope that my message will help you.

nrgx commented 6 years ago

Thank you very much for your response.

I've overcame that task and now all my messeges are in Postgres DB. Now I need to implement infinite scrolling for message fetching, but I know solution w/ Django's built-in paginator and jQuery, this just matter of time. Now the other problem occurred: after sending some messages by $.post() method they are shown only after reloading the page.

And I can't write messages in Russian or Kazakh, but I know there is ws4redis utf8 validator, but first issue is higher by precedence.

On Mon, Jul 16, 2018, 7:54 PM Konstantin Baydin notifications@github.com wrote:

I save messages to postgres in POST handler just before redis_publisher.publish_message(redis_message) and it works fine.

By the way, when I write several messages to the input and then reload it, only last message shown.

Do you trying to load messages from redis? You shouldn't use redis to persist messages. Also, you may receive message after reconnecting because of WS4REDIS_EXPIRE is not 0. You should set WS4REDIS_EXPIRE = 0 to receive only new messages via webscocket. Use GET request to receive old messages from database.

Sorry for my bad English.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jrief/django-websocket-redis/issues/269#issuecomment-405255114, or mute the thread https://github.com/notifications/unsubscribe-auth/ARTcTCijlKlYS_EOQHWQNMIe-opHpl4Sks5uHJsRgaJpZM4VMq7K .