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

  • Home
  • SEARCH
  • 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 8686585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:53:18+00:00 2026-06-12T22:53:18+00:00

I’m trying to figure out how to handle my data structure within Redis. What

  • 0

I’m trying to figure out how to handle my data structure within Redis. What I am trying to accomplish is how I can count events with two parameters, and then query Redis for that data by date. Here’s an example: events come in with two different parameters, let’s call them site and event type, and also with the time that event occurred. From there, I will need to be able to query Redis for how many events occurred over a span of dates, grouped together by site and event type.

Here’s a brief example data set:

Oct 3, 2012:
   site A / event A
   site A / event A
   Site B / event A

Oct 4, 2012:
   site B / event B
   site A / event A
   Site B / event A

… and so on.

In my query I would like to know the total number of events over the date span, which will be a span of five weeks. In the example above, this would be something like:

   site A / event A ==> 3 events
   site B / event A ==> 2 events
   site B / event B ==> 1 event

I have looked at using Redis’ Sorted Set feature, Hashes, and so on. It seems Sorted Set is the best way to do it, but querying the data with Redis’ ZUNIONSTORE command seems like not such a great fit because these events will span five weeks. That makes for at least 35 arguments to the ZUNIONSTORE command.

Any hints, thoughts, ideas, etc?

Thanks so much for your help.

  • 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-12T22:53:23+00:00Added an answer on June 12, 2026 at 10:53 pm

    Contrary to a typical RDBMS or MongoDB, Redis has no rich query language you can use. With such stores, you accumulate the raw data in the store, and then you can use a query to calculate statistics. Redis is not adapted to this model.

    With Redis, you are supposed to calculate your statistics on-the-fly and store them directly instead of the raw data.

    For instance, supposing we are only interested in statistics over a range of weeks, I would structure the data as follows:

    • because all the critera are discrete, simple hash objects can be used instead of zsets

    • one hash object per week

    • in each hash object, one counter per couple site,event. Optionally, one counter per site, and/or one counter per event.

    So when an event occurs, I would pipeline the following commands to Redis:

    hincrby W32 site_A:event_A 1 
    hincrby W32 site_A:* 1 
    hincrby W32 *:event_A 1 
    

    Please note there is no need to initialize those counters. HINCRBY will create them (and the hash object) if they do not exist.

    To retrieve the statistics for one week:

    hgetall W32
    

    In the statistics, you have the counters per site/event, per site only, per event only.

    To retrieve the statistics for several weeks, pipeline the following commands:

    hgetall W32
    hgetall W33
    hgetall W34
    hgetall W35
    hgetall W36
    

    and perform the aggregation on client-side (quite simple if the language supports associative arrays such as map, dictionary, etc …).

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I would like to count the length of a string with PHP. The string

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.