SET OK MEMORY USAGE (integer) 51
memory usage 命令返回key和value占用内存的bytes
--stat持续输出stats模式 在测试上可以做测试
redis-cli -a password -p 6379 -h hostname --stat------- data ------ --------------------- load -------------------- - child -keys mem clients blocked requests connections 35768376 6.98G 2021 0 2600414876 ( 3) 3121642 35768376 6.98G 2021 0 2600414879 ( 3) 3121642 35768376 6.98G 2021 0 2600414884 ( 5) 3121642 35768376 6.98G 2021 0 2600414887 ( 3) 3121642 35768376 6.98G 2021 0 2600414890 ( 3) 3121642 35768376 6.98G 2021 0 2600414894 ( 4) 3121642 35768376 6.98G 2021 0 2600414898 ( 4) 3121642 35768376 6.98G 2021 0 2600414901 ( 3) 3121642 35768376 6.98G 2021 0 2600414905 ( 4) 3121642 35768376 6.98G 2021 0 2600414909 ( 4) 3121642 35768376 6.98G 2021 0 2600414912 ( 3) 3121642通过第三方工具rdbtools来计算key大小
安装pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py# 用相对应版本python安装对应版本sudo python get-pip.pysudo python3 get-pip.py安装rdbtools
pip install rdbtools查看指定key大小
redis-memory-for-key -s hostname [-a password] -p 6379 -d 0 key1
# rdb --helpusage: usage: rdb [options] /path/to/dump.rdb
Example : rdb --command json -k user.* /var/redis/6379/dump.rdb
positional arguments: dump_file RDB Dump file to process
optional arguments: -h, --help show this help message and exit -c CMD, --command CMD Command to execute. Valid commands are json, diff, justkeys, justkeyvals, memory and protocol -f FILE, --file FILE Output file -n DBS, --db DBS Database Number. Multiple databases can be provided. If not specified, all databases will be included. -k KEYS, --key KEYS Keys to export. This can be a regular expression -o NOT_KEYS, --not-key NOT_KEYS Keys Not to export. This can be a regular expression -t TYPES, --type TYPES Data types to include. Possible values are string, hash, set, sortedset, list. Multiple typees can be provided. If not specified, all data types will be returned -b BYTES, --bytes BYTES Limit memory output to keys greater to or equal to this value (in bytes) -l LARGEST, --largest LARGEST Limit memory output to only the top N keys (by size) -e {raw,print,utf8,base64}, --escape {raw,print,utf8,base64} Escape strings to encoding: raw (default), print, utf8, or base64. -x, --no-expire With protocol command, remove expiry from all keys -a N, --amend-expire N With protocol command, add N seconds to key expiry time
redis-cli --bigkeys
redis-cli -a password -p 6379 -h hostname --bigkeys # Scanning the entire keyspace to find biggest keys as well as# average sizes per key type. You can use -i 0.1 to sleep 0.1 sec# per 100 SCAN commands (not usually needed). [00.00%] Biggest string found so far 100000004602269 with 156 bytes[00.00%] Biggest string found so far 100000006251981 with 225 bytes[00.00%] Biggest string found so far 100000011594328 with 226 bytes[00.00%] Biggest string found so far 100000000095649 with 227 bytes[00.01%] Biggest string found so far 100000003257493 with 228 bytes...
在这种特殊的模式下 redis-cli会对key进行空间分析 扫描出占用空间大的key的集 并且提供关于数据类型和数组组成构造



