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?
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.