Question:
How to use Redis Aggregation using NodeJS

Solution

For this process you typically need to use the Redis TS.MRANGE command, which stands for "TimeSeries Multi-Range." With the help of this command you can perform aggregation operations on one or more time series in Redis. Install RedisTimeSeries module and load in your Redis server before using aggregation.


The following code you can use to aggregate data and receive the result:


const result = await redisClient.ft.aggregate(indexName, queryPattern, {

      STEPS: [{

        type: AggregateSteps.FILTER,

        expression: `${userList.map(username => `@username=='${username}'`).join(' || ')}`,

      }, {

        type: AggregateSteps.GROUPBY,

        properties: ['@pids'],

        REDUCE: [{

          type: AggregateGroupByReducers.TOLIST,

          property: '@username',

          AS: 'users',

        }],

      }],

    })

    logger.info('Got result\nSize: ', JSON.stringify(result.total))

    logger.debug('\nData: ' + JSON.stringify(result.results))

  } catch (error) {

    logger.error('Error:', error)

  }


Answered by: >tuxian

Credit: >StackOverflow


Suggested Blogs

>Creating a pivot table by 6 month interval rather than year

>How remove residual lines after merge two regions using Geopandas in python?

>How to mock a constant value in Python?

>Can I call an API to find out the random seed in Python `hash()` function?

>How to configure python in jmeter?

>How to fix routes in Laravel?


Submit
0 Answers

What Our Clients Say About Us

Client satisfaction is our ultimate goal. Here are some kind words of our precious clients they have used to express their satisfaction with our service.

Why Choose Us ?

We endow businesses with flexible engagement models based on their unique needs. Our strength lies in state-of-the-art technology and affordable consulting services. Try us for fast POCs, full-fledged applications, or technology consulting. Always available for your service.