How to exec batch of commands on our Redis instance

On this repo you'll find a bunch of script I build for moltin written in Lua and Bash, useful to maintain our database and execute commands against batch keys.

Below a resumen of all scripts and hoew to use them:

Bash scripts

Remove all KEYS that match a given pattern without TTL

./clean_up_keys_match_pattern_without_ttl.sh [REDIS_IP] [REDIS_PORT] [PATTERN]

Remove all KEYS that match a given pattern

./clean_up_keys_match_pattern.sh [REDIS_IP] [REDIS_PORT] [PATTERN]

Lua Scripts

DEL KEYS

redis-cli -h [REDIS_IP] -p [REDIS_PORT] EVAL "$(cat ./lua/del_keys.lua)" [COUNT_KEYS] [KEYS]  

It will return some like:

1) "a:2"  
2) "a:3"  
3) "a:1"  

Where the first element is the KEY that have been DEL and the second the number of elements that have been deleted

There is an example of usage in cleanupkeysmatchpatternwithoutttl.sh

SCAN cursor [MATCH pattern] [COUNT count] KEYS without TTL

keys=$(redis-cli -h $1 -p $2 EVAL "$(cat ./lua/scan_match_count_keys_without_ttl.lua)" 0 $cursor $3 $4)  

There is an example of usage in cleanupkeyswithoutttl.sh

SCAN cursor [MATCH pattern] [COUNT count] KEYS

keys=$(redis-cli -h $1 -p $2 EVAL "$(cat ./lua/scan_match_count_keys.lua)" 0 $cursor $3 $4)  

There is an example of usage in cleanupkeysmatchpattern.sh

Resources

Some useful links: