docker-compose.yml文件的内容如下:
version: '3'
services:
redis:
image: redis
ports:
- 6379:6379
docker-compose up -d 启动redis容器
这里我是ubuntu服务器,centos用yum代替apt安装
执行:apt install redis-tools安装
执行redis-cli连接redis服务器,这里没有设置密码。
此处我使用图片转化为base64后的代码,大小为240kb,正常超过10kb的key我们就认为是bigkey。
set testkey "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABbQAAAL4CAYAAACjn3FOAAAMFWlDQ1BJQ0MgUHJvZmlsZQAASImVVwdYU8kWnltSCAktEAEpoTdBinSB0HuRDjZCEiCUCAlBxa4sKrh2EUVR0VURBdcCyFoQUSyIYO8PVFSUdbFgQ+VNCuj62vfO982dP2fOOfOfuedOZgBQtmXn5majKgDkCPKF0YE+zMSkZCapB2BADygCFWDI5ohyvaOiwgCUkf7v8v4mQCT9NWtJrH8d/6+iyuWJOAAgURCnckWcHIiPAIBrcnKF+QAQ2qHeaGZ+rgQPQKwuhAQBIOISnC7DmhKcKsPjpDax0b4QswAgU9lsYToAShLezAJOOoyjJOFoK+DyBRBvgdiTk8HmQnwf4nE5OTMgViZDbJ76Q5z0v8VMHY3JZqePYlkuUiH78UW52ezZ/+dy/G/JyRaPzGEIGzVDGBQtyRmu296sGaESTIX4uCA1IhJiNYjP87lSewm+myEOipPb93NEvnDNAAMAFHDZfqEQ60DMEGfFecuxPVso9YX2aAQ/PzhWjlOFM6Ll8dECQXZEmDzOsgxe8Aiu5In8Y0Zs0vgBwRDDSkOPFGbEJsh4oq0F/PgIiJUg7hRlxYTKfR8WZvhGjNgIxdESzsYQv0sTBkTLbDDNHNFIXpgNhy2dC9YCxsrPiA2S+WKJPFFi2AgHLs/PX8YB4/IEcXJuGKwun2i5b3FudpTcHqvkZQdGy9YZOygqiBnxvZoPC0y2DtijTHZIlHyu97n5UbEybjgKwoAv8ANMIIYtFcwAmYDf0d/QD3/JRgIAGwhBOuABa7lmxCNBOiKAzxhQCP6EiAdEo34+0lEeKID6r6Na2dMapElHC6QeWeApxD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oldYDjy9nIecllcddz+3gevLW8Z2keaWvTnqd7pK9L78vwyijL6Of78jfzX2cGZW7L/JAVmbUnazg7Ibsuh5yTknNMoCbIErTO0Jsxa0ZXrlVucW53nlvehrwBYahwtwgRTRU15qvDY0672Fz8i7inwLOgouDjzPiZh2epzhLMap9tOXv57GeFAYW/zcHncOa0zDWYu2huzzzveTvmI/NT57csMFpQtKB3YeDCvYsoi7IWXV5su3jt4ndLEpY0FekWLSx6/EvgLzXFSsXC4ltL3ZduW4Yv4y/rWO6wfNPybyXckoultqVlpV9WcFZc/NXu1/Jfh1emrexY5bSqcjVxtWD1zTVea/auVV1buPbxuvB19euZ60vWv9swfcOFsgll2zZSNoo3dpeHlTduMt60etOXzRmbb1T4VNRt0dmyfMuHrdytVytZlbXbdLeVbvu8nb/99o7AHfVVplVlO4k7C3Y+3RW/q+03l9+qd2vvLt39dY9gT/fe6L2t1c7V1ft09q2qQWvENX37p+zvPOB3oLHWunZHHaOu9CA4KD744veU328eCj3UctjlcO0RkyNbjtKPltQj9bPrBxoyGrobkxq7joUca2lybzr6h80fe44bHK84oXFi1UnKyaKTw6cKTw025zb3n04//bhlesu9M4lnrrdOau04G3r2/LmAc2favNtOnfc4f/yC24VjF10uNlxyulTf7th+9LLj5aMdTh31V5yvNHa6djZ1Tew6edXr6ulrftfOXQ++fulGxI2um3E3b9+acqv7Nvf28zvZd17fLbg7dG/hfcL9kgcqD8oe6jys+ofFP+q6nbpP9Pj1tD+KeXTvMefxyyeiJ196i57SnpY9039W/dz++fG+gL7OF5Nf9L7MfTnUX/yn6p9bXpm/OvIX66/2gcSB3tfC18NvVrzVervn3YR3LYNRgw/f57wf+lDyUevj3k8un9o+J3x+NjTzC+lL+VeLr03fQr/dH84ZHs5lC9nSowAGG5qWBsCbPQDQkuDZoRMAipLs7iUVRHZflCLwn7DsfiY"
如下图:
执行redis-cli --bigkeys:(在数据多的生产环境要慎用,会扫描redis寻找bigkey造成redis服务卡顿),这个命令会列出Redis中所有的key及其对应的大小,看到我们找到了刚才的bigkey,有4081个byte。
在RMD工具中,连接redis后点击分析内存即可查看key占用的内存大小。