Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8122915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:59:14+00:00 2026-06-06T05:59:14+00:00

Seems, it’s common task, but I haven’t found solution. I need to calculate number

  • 0

Seems, it’s common task, but I haven’t found solution.

I need to calculate number of user’s events (for example, how many comments he left) per last 24 hours. Older data is not interesting for me, so information about comments added month ago should be removed from Redis.

Now I see only one solution. We can make keys that includes ID of user and hour of day, increment it value. Then we will get 24 values and calculate their sum. Each key has 24 hours expiration.

For example,

  1. Event at Jun 22, 13:27 -> creating key _22_13 = 1
  2. Event at Jun 22, 13:40 -> incrementing key _22_13 = 2
  3. Event at Jun 22, 18:45 -> creating key _22_18 = 1
  4. Event at Jun 23, 16:00 -> creating key _23_16 = 1
  5. Getting sum of event at Jun 23, 16:02 -> sum of keys _22_17 – _22_23, _23_00 – _23_16: in our keys it’s only _22_18 and _23_16, result is 2. Keys _22_13 and _22_13 are expired.

This method is not accurate (it calculates count of events per 24+0..1 hour) and not so universal (what key will I choose if I need number of events per last 768 minutes or 2.5 month?).

Do you have better solution with Redis data types?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:59:16+00:00Added an answer on June 6, 2026 at 5:59 am

    Your model seems fine. Of course, it’s not universal, but it’s what you have to sacrifice in order to be performant.

    I suggest you keep doing this. If you will need another timespan for reporting (768 minutes), you can always get this from mysql where your comments are stored (you do this, right?). This will be slower, but at least the query will be served.

    If you need faster response or higher precision, you can store counters in redis with minute resolution (one counter per minute).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seems like it should be simple, but cant find a solution anywhere. I need
Seems like a simple problem, but can't get this to work. In the example
Seems to be a problem that many people have, but all the answers I
Seems everyone recommends virtualenv for multiple python versions (on osx), but does it even
Seems like this should be obvious, but how do I send arrow key presses
Seems like this should be simple, but powershell is winning another battle with me.
I want to count how many characters a certain string has in PHP, but
Seems simple but users have no internet access. The application will be hosted internally
Seems like this might be easy, but from reading other SO answers there are
Seems to be a fairly hit issue, but I've not yet been able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.