Memory usage per key pattern

Total memory consumed by keys matching 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

    Safely scan-delete matching keys without KEYS command

  • redis-cli SET mykey 'value' EX 3600

    Set key with 1-hour expiry (EX = seconds)

  • redis-cli INCRBY counter:hits 1

    Atomically increment 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 and listen to messages on a channel

all 32 redis commands