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 7700955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:52:05+00:00 2026-05-31T22:52:05+00:00

I am using python to increment a counter in 5 minute intervals in redis

  • 0

I am using python to increment a counter in 5 minute intervals in redis and speed of the execution code is rather important. I will have a sorted set that will look like this:

1:30 incr 1:35 incr ...

where the incr is the hit count between that 5 minute interval.

Lets say I am at 1:32 pm and I want to place all of the hits between 1:30 and 1:35 in that bucket.

Naively I can just loop through a list and check if minute between 30 and 35 and place in the 1:30 bucket. Is there a more pythonic method to do this?

  • 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-05-31T22:52:06+00:00Added an answer on May 31, 2026 at 10:52 pm
    from redis import Redis
    
    r = Redis(db=1)
    r.flushdb()
    def store(t):
        h, m = map(int, t.split(':'))
        m = m - m % 5
        r.zincrby('tc', '%d:%02d' % (h, m), 1)
    
    store('1:02')
    store('1:30')
    store('1:32')
    store('1:35')
    
    print r.zrange('tc', 0, -1, withscores=True)
    

    Output:

    [('1:00', 1.0), ('1:35', 1.0), ('1:30', 2.0)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a Python program I'm writing I've compared using a for loop and increment
(Using Python 3.2, though I doubt it matters.) I have class Data , class
I have a small project I am doing in Python using web.py. It's a
Following code, using python 2.6.6 and MySQLdb 1.2.2 causes Commands out of sync; you
Is it possible to do something like this in Python using regular expressions? Increment
Using Python I want to be able to draw text at different angles using
Using python 2.4 and the built-in ZipFile library, I cannot read very large zip
Using Python, how would I go about reading in (be from a string, file
Using Python 2.6, is there a way to check if all the items of
Using Python's Imaging Library I want to create a PNG file. I would like

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.