Check memory for a key pattern

Show the total memory in MB used by keys that match a pattern

redis-cli --scan --pattern 'session:*' | xargs -n1 redis-cli MEMORY USAGE | awk '{sum+=$1} END{print sum/1024/1024" MB"}'

tool
redis32 commands
tags
redismonitoring

More redis commands

  • redis-cli --scan --pattern 'cache:*' | xargs -r redis-cli DEL

    Delete matching keys with SCAN instead of the blocking KEYS command

  • redis-cli SET mykey 'value' EX 3600

    Set a key that expires in 1 hour (EX is in seconds)

  • redis-cli INCRBY counter:hits 1

    Atomically add 1 to an integer counter

  • redis-cli PUBLISH events '{"type":"login","user":"alice"}'

    Publish a message to a Redis pub/sub channel

  • redis-cli SUBSCRIBE events

    Subscribe to a channel and listen for messages

all 32 redis commands