批量導入txt數(shù)據(jù)到的redis過程
更新時間:2025年08月02日 08:40:01 作者:mteng59101
用戶通過將Redis命令逐行寫入txt文件,利用管道模式運行客戶端,成功執(zhí)行批量刪除以"Product*"匹配的Key操作,提高了數(shù)據(jù)清理效率
批量導入txt數(shù)據(jù)到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
總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
Redis+自定義注解+AOP實現(xiàn)聲明式注解緩存查詢的示例
實際項目中,會遇到很多查詢數(shù)據(jù)的場景,這些數(shù)據(jù)更新頻率也不是很高,一般我們在業(yè)務處理時,會對這些數(shù)據(jù)進行緩存,本文主要介紹了Redis+自定義注解+AOP實現(xiàn)聲明式注解緩存查詢的示例,文中通過示例代碼介紹的非常詳細,需要的朋友們下面隨著小編來一起學習學習吧2025-04-04

