D
D
dim4ik2013-12-15 10:13:11
PHP
dim4ik, 2013-12-15 10:13:11

Redis storing subscriptions to news categories

I want to store user subscriptions to sections of the site (news categories) in a separate set, or rather two:
the first set 1 user_id => array( cat_id ) - in order to know all user subscriptions the
second set 1 cat_id => array( user_id ) - in order to to know all subscribed users to the category
Is this the correct solution?
The second question follows from the first:
It is necessary for the user to show the number of updates since he viewed this category, i.e. show him +3 new news since his absence. Only here I can not solve the problem, and understand how to solve it. In the case of news comments, it can be compared by date (the user subscribed to the news/article/question and we remembered the date of his last viewing, then when new comments were written, we simply compared how many new comments were added since the moment he saw it, and when the user came to the article, then we update the date and all comments become read - everything is simple here).
But I don't understand how to do this with posts. Let me describe the misunderstanding:
+5 new articles have been added to the section, +5 can be indicated opposite the category. But now the user has entered the category and he has 5 articles marked as new in it, he looked at one, it should be now +4, then another one and he is shown +3, etc. here one update of the date, as with the comments, will not work. Here, apparently, it is necessary to store the id of all new articles in a separate set for the user.
Please tell me how to solve this issue?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Sundukov, 2013-12-15
@alekciy

Is this the right decision?

As a spherical problem in a vacuum, no, not correct, because data is duplicated twice. Potentially, the schema contains data inconsistency (for example, in the first set there is a certain cat_id, in the cat_id set itself there is such a user_id). In practice, it is different.
As I already said in the topic " How the tracker works on Habré ", the meaning is absolutely the same. Only in the role of a post we have a news feed (and in the form of comments
No, it should be 0. +4 would mean that the user should watch all posts, which of course is not required.

A
Alexey Sundukov, 2013-12-15
@alekciy

And yes. No need to mix the algorithm for solving the problem, and the implementation of this algorithm. Since we have a problem with the algorithm, it is too early to solve the implementation problem and it makes no sense to talk about Redis. Moreover, I see no reason to do this at the Redis level when there is an RDBMS within which it's all great to go.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question