redis-cli -h 127.0.0.1 -p 6379 -a 123456 -n 2 keys 'tm_product*' | xargs redis-cli -h 127.0.0.1 -p 6379 -a 123456 -n 2 del;
mysql -h 127.0.0.1 -uroot -p123456 --default-character-set=utf8 -Dwxdis2 --skip-column-names --raw -e "SELECT CONCAT( 'hmset tm_product', ' ', d.spu_id, ' ', CONCAT( '|spuId:', d.spu_id, '|productType:', d.product_type, '|cpType:', d.cp_type, '|province:', province, '|city:', IF(d.city IS NULL OR d.city='', '#', d.city), '|dimension:', d.dimension, '|buyNum:', d.buy_num, '|unitPrice:', d.unit_price, '|supplierId:', d.supplier_id ), '\r' ) FROM tm_product d WHERE d.spu_id is NOT NULL and del_flag = '0' and status = '2' "|redis-cli -h 127.0.0.1 -p 6379 -a 123456 -n 2 --pipe;
查询所有redis 2号库的tm_product key,然后删除
接着 从数据库查询数据拼接成命令,类似下面这样
hmset tm_product 716282922 |spuId:111|productType:4|cpType:03|province:898|city:#|dimension:1024|buyNum:1|unitPrice:500|supplierId:444
hmset tm_product 716284502 |spuId:222|productType:4|cpType:03|province:591|city:#|dimension:1024|buyNum:1|unitPrice:500|supplierId:333
传给redis通过管道执行