1.首先导出redis的rdb文件 redis-cli -h 127.0.0.1 -p 3306 -a 密码 --rdb xxhTest.rdb 2.安装pip install rdbtools 3.导出所有的key存储到文件 rdb -c memory --key "xxh:test:.*" xxhTest.rdb | awk -F "," '{print $3}' > keys.csv 4.新建数据库表: CREATE TABLE `redis_keys` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键', `redis_key` varchar(128) COLLATE utf8mb4_bin NOT NULL COMMENT 'redisKey', PRIMARY KEY (`id`), KEY `inx_rediskey` (`redis_key`) ) ; 5. mysql -h127.0.0.1 -u root -p 6.load data local infile "/root/keys.csv" into table redis_keys lines terminated by '\n' (redis_key); 7. 拼接出DB中的Key create table db_keys( `_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',PRIMARY KEY (`_id`) ) as select concat('xxh:test:',store_code,':',item_code,':',store_type) dbkeys from xxh_01.xxh_stock ss union all select concat('xxh:test:',store_code,':',item_code,':',store_type) dbkeys from xxh_02.xxh_stock ss 8. alter table db_keys add index inx_dbkey(dbkeys) 9. select r.redis_key from redis_keys r left join db_keys k on r.redis_key=k.dbkeys where k.dbkeys is null
如何查找Redis中有但是DB没有的Key
最新推荐文章于 2023-04-11 11:33:44 发布