I need to design a node.js app in this scenario:
- User requests to /page with a cookie which has a unique
token - Node.js creates a
recordwith this token on redis(?) with a 5 mins TTL.tokens hasntype. So redis(?) should store tokens with types. - If user comes back again before
recordexpire,record's TTL reset to 5 mins again. - If user doesn't come back again and
recordexpires, a function is triggered. - And at last, I also need the count of
records belongs to a specific type (i.e. type 27).
What would be the best way to achieve this problem? Is redis right choice for it? How can I count tokens and trigger 5. step if I use redis?
Using https://github.com/Automattic/kue or something like that would be the nice choice?
Edit: It seems possible duplicate with Event on key expire . In general, I ask, is redis suitable for this problem? If you think it is, could you please give an example pattern I should follow. If not, what are any other solutions maybe even without redis or 3rd party tool.
Also as I said at the 5. item in the list above, redis seems not suitable at querying keys with a pattern as described here:https://redis.io/commands/keys
. Because there seems no way to put expiration on an individual member of a set (TTL for a set member) , I cannot put tokens in a type set or hash . Thus I need to query keys in order to get count of a group (type) and this seems not efficient as described at the link above.
Even if https://redis.io/topics/notifications solves the problem at the 4. item in the list above, I also ask for "Which pattern/algorithm should I go and how" . I don't want you to code for me, but just need a spark. A tutorial, guide, video etc.. would be great. Thanks!