1. 程式人生 > >redis之批量導入key值數據到redis庫

redis之批量導入key值數據到redis庫

found lin data 文件 from linu not 繼續 errors

簡單說明介紹:

腳本中的data.txt文件是php程序那邊在linux服務器上生成的,內容如下:

[root@localhost ~]# tail -5 /data/www/e456tadd/data.txt
SET 447a70c342e677ac 1,1
SET 6ec81c6c460038ae 9,1
SET 121a61e082c3cd67 1,1
SET 91d08ae6d6ff27e0 11,1

直接導入data.txt文件數據到redis報錯提示ET Not Found ,於是懷疑文件格式不對,所以安裝dos2unix命令格式轉換data.txt文件。格式轉換完繼續導入data.txt數據到redis,但是依舊提示報錯提示ET Not Found

於是安裝unix2dos,繼續格式轉化data.txt文件,再次導入redis,成功導入了

添加腳本到定時任務,結果腳本執行失敗
於是腳本中加入source /etc/profile 。
唉,媽呀,終於成功了。

導入記錄日誌:
[root@localhost ~]# cat /data/www/getqd/redis-load.log

2018-10-11 12:15:01
All data transferred. Waiting for the last reply...
Last reply received from server.
errors: 0, replies: 1014
2018-10-12 02:30:01
All data transferred. Waiting for the last reply...
Last reply received from server.
errors: 0, replies: 1167

腳本內容如下:

[root@localhost ~]# cat /data/scripts/redis-load.sh 
#!/bin/bash
source /etc/profile
/usr/bin/unix2dos /data/www/e456tadd/data.txt  >>/data/www/e456tadd/redis-load.log
echo $(date "+%Y-%m-%d %H:%M:%S") >>/data/www/e456tadd/redis-load.log
cat /data/www/getqd/data.txt |redis-cli -h 127.0.0.1 -p 20004 -a ‘YH345667tuEq‘ --pipe >>/data/www/e456tadd/redis-load.log

redis之批量導入key值數據到redis庫