How can we get the sum of column entries in the NO-SQL database Redis?
I mean similar as :
Select sum(salary) from Account;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
The short answer is, you can’t. That’s not quite what redis was meant for.
The somewhat longer answer is, you can accomplish this with redis lua scripting, and the EVAL command.
With a redis list such as:
And a script sum.lua:
You could call it from the command line, like this:
Edit: The third answer is @DidierSpezia’s comment, about calculating it when permuting the data. Usually when working with redis, you will structure your data according to how you want to query it, rather than the other way around. Perhaps you would do something like: