Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I want to setup a script that sums up a bunch of values in a list and then puts down the result in total-count and then removes the entire list, And this all should be repeated once a minute or as soon as the script completes. Is it possible to make a script that does this?

share|improve this question

closed as unclear what you're asking by Mark Storey-Smith, Paul White, RolandoMySQLDBA, Michael - sqlbot, Kin Feb 20 at 14:30

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

up vote 3 down vote accepted

Redis doesn't do scheduling of jobs/scripts - you'll have to use something (e.g. cron) to trigger the script.

The script itself sounds simple enough - LRANGE should be used to iterate the list's elements, sum them up, SET total-count to the result and DEL the list. Lua would be perfect for this but you can also .sh with redis-cli for example.

What bothers me, however, is that LRANGE would be O(N) and you want to run this all the time... that means your Redis will be busy doing this and all that just for an aggregate? Perhaps you should consider an alternative that will save all the work (from Redis) and the need to schedule a script. One possible alternative, for example, would be to add the list's members directly to the total-count key, possibly even without storing them in the list in the first place - unless I missed something, this appears a simpler solution to you request.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.