How store users conversation in Redis?

988 views
Skip to first unread message

Oleg P

unread,
Feb 1, 2014, 2:21:16 PM2/1/14
to redi...@googlegroups.com
I write a chat on node.js with support Redis store.
I have two users who can chatting together. Each have an unique ID.
When i logged and click on user name in my contact, i must create private room for two users and display all conversation. What data type use for this? List or Set?

As I think the key to store hash ID of users - which were chatting. This will be a unique value. And this is the key to fill in the data format JSON: {id_from: 145, to: 1, message "Privet", time: 1234589}. Can you say something?
In this case, there is problem, I can not get message separately for each user, i need know id two sides.
Problem is, how store messages between two users and how it display?
Thank you for any replica!

Salvatore Sanfilippo

unread,
Feb 1, 2014, 7:46:35 PM2/1/14
to Redis DB
Hello Oleg, if you want to maintain a limited history (like latest N
lines of chat between every two users) the list can be a good pick.

I would use a more memory efficient storage in which every line is
something like "<id>:<time>:message bla bla bla". You can use the key
itself in order to "tag" the two users chat id.
You can have a rule that if user ID X and Y are chatting, you always
order X and Y so that the minor of the two is the first ID, and then
call the key chat:ID1:ID2 or alike.

Every time the user writes something new to the other user, you just
do an RPUSH on the list. Since lists support blocking ops this is also
a good setup to block and serve the client, but you could also use
Redis Pub/Sub for the delivery.

Salvatore
> --
> You received this message because you are subscribed to the Google Groups
> "Redis DB" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to redis-db+u...@googlegroups.com.
> To post to this group, send email to redi...@googlegroups.com.
> Visit this group at http://groups.google.com/group/redis-db.
> For more options, visit https://groups.google.com/groups/opt_out.



--
Salvatore 'antirez' Sanfilippo
open source developer - GoPivotal
http://invece.org

To "attack a straw man" is to create the illusion of having refuted a
proposition by replacing it with a superficially similar yet
unequivalent proposition (the "straw man"), and to refute it
-- Wikipedia (Straw man page)
Reply all
Reply to author
Forward
0 new messages