Search code examples
c#redisstackexchange.redis

Is there a way to write Redis.OM query with multiple aggregations?


I'm trying to have multiple aggregations for redis via Redis.OM in one call. Something like this code for EF provider:

var efGroup = from props in efquery
group props by props.State into grp
select new
{
    PriceSum = grp.Sum(cc => cc.Price),
    PriceAvg = grp.Average(c => c.Price),
    SizeAvg = grp.Average(c => c.Size)
};

On the redis tutorial page there is an example how to do aggregation with grouping

var employeeAggregations = provider.AggregationSet<Employee>();
var departments = employeeAggregations.GroupBy(x=>x.RecordShell.Department).Sum(x=>x.RecordShell.Sales);

I tried to add additional calls to that:

var agr = redisAggr.GroupBy(x => x.RecordShell.State)
    .Sum(x => x.RecordShell.Salary)
    .Average(x => x.RecordShell.Age)
    .ToList();

but that just throws the Property 'Age' not present in document or pipeline.

I was also trying to do the similar query as for EF, but that just throws Timeout performing UNKNOWN (5000ms)

Is there a way to have sums/avg/count in one go for many fields?


Solution

  • As slorello wrote, it's fixed since 0.1.6.