- List
- Sorted set.
List
Key : user-id
Values: timestamp
Store the timestamps into the list Redis will reply with the size of the list.
When size hits the threshold you have configured manually check for validity of timestamps. Truncate unwanted entries using ltrim.
Additionally you can also set expiry to the list key. There might be cases where frequent attempts occur between the provided window which will be handled in you server code.
Sorted Set
Key: user-id
values: timestamp, rank 0
Store all the timestamps with rank zero. You can use zcard to check for size or write a Lua script that stores and returns zcard size for each add.
Since all ranks are zero you can try using Redis lexical support for sorted set.
You can set expiry to this key also.
Regards,
Abijith Krishna