批量导入txt数据到的redis过程
作者:mteng59101
用户通过将Redis命令逐行写入txt文件,利用管道模式运行客户端,成功执行批量删除以"Product*"匹配的Key操作,提高了数据清理效率
批量导入txt数据到redis
把redis命令按一条 一行写到txt中
[root@localhost ~]# cat test_rediscli.txt hset Product_1 CUST_DEGREE 1 hset Product_2 CUST_DEGREE 2 hset Product_3 CUST_DEGREE 3 hset Product_4 CUST_DEGREE 4 hset Product_5 CUST_DEGREE 5
管道命令运行redis客户端
启用pipe模式
cat test_rediscli.txt |./redis-cli -h 192.168.137.137 -p 6379 --pipe
成功了
[root@localhost ~]# ./redis-cli -h 192.168.137.137 -p 6379 192.168.137.137:6379> hgetall Product_1 1) "CUST_DEGREE" 2) "1" 192.168.137.137:6379> hgetall Product_2 1) "CUST_DEGREE" 2) "2" 192.168.137.137:6379> hgetall Product_3 1) "CUST_DEGREE" 2) "3" 192.168.137.137:6379> hgetall Product_4 1) "CUST_DEGREE" 2) "4" 192.168.137.137:6379> hgetall Product_5 1) "CUST_DEGREE" 2) "5"
批量删除key
./redis-cli -h 192.168.137.137 -p 6379 keys "Product*" |xargs ./redis-cli -h 192.168.137.137 -p 6379 del
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。