Recently, the use of relational database to achieve the user's attention, so think of a different way of thinking, using Redis to achieve the user's attention relationship.
After taking a look at some of the data structures of Redis, I think we can implement them with a set.
Suppose the ID of "I" is 1, and the ID of "others" is 2.
First, add attention
Add attention to two steps: 1. Add the ID to your watchlist and 2. Add your own ID to the other's fan list:
Sadd 1:follow 2SADD 2:fans 1
Ii. cancellation of concerns
The cancellation of attention is also divided into two steps: 1. Remove the ID from your watchlist and 2. Remove your ID from the other's fan list:
Srem 1:follow 2SREM 2:fans 1
Iii. List of concerns
To view my watchlist:
Smembers 1:follow
Check someone else's ID to replace it.
Iv. List of Fans
View a list of my fans:
Smembers 2:fans
Check someone else's ID to replace it.
V. Character Relations 5.1 I pay attention to him.
I paid attention to him one way, to同时满足
Two conditions: 1, my watchlist有
He (or his fan list有
Me) 2. In my fan list没有
He (or his list of concerns没有
Me).
Sismember 1:follow 2 #trueSISMEMBER 1:fans 2 #false
5.2 He pays attention to me one way
He was concerned about me one way, to同时满足
Two conditions: 1, my watchlist没有
He (or his fan list没有
Me) 2. In my fan list有
He (or his list of concerns有
Me).
Sismember 1:follow 2 #falseSISMEMBER 1:fans 2 #true
5.3 If I have a meal with someone
If I have a meal with someone, I want 同时满足
two conditions: 1, I have him in my watchlist (or his fan list), 2, my fan list has him (or his watchlist has me). At the same time set up for mutual powder.
Sismember 1:follow 2 #trueSISMEMBER 1:fans 2 #true
The relationship between the powders is mutual and can be reversed.
Six, my mutual powder
The people who inquire and I have the powder, are actually interested in me and my fans are asking for the intersection
SINTER 1:follow 1:fans
Vii. common concern
Query 1 and 2 of the common concern, is actually 1 of the attention and 2 of the attention to seek intersection
SINTER 1:follow 2:follow
Viii. number of related 8.1 My number of concerns
SCard 1:follow
8.2 Number of my fans
SCard 1:fans
Ix. problems
The problem is that my watchlist & my fan list can't be sorted by attention time, and the results are listed in positive order by ID.
The solution to consider is to add an ordered set of concerns while keeping an eye on the time stamp that is score.
Zadd 1:follow 1457871625 2ZADD 2:fans 1457871625 1
So my list of concerns is:
Zrevrange 1:follow 0-1
At the same time, the index of Zrevrange query can be used as a paging cursor, which basically solves the current problem.
Redis implementations focus on relationships