redis 批量导入

7 篇文章 0 订阅

redis 官方 方式:http://www.redis.cn/topics/mass-insert.html


sh脚本 执行mysql 语句


#!/bin/sh


date +%s ;


/usr/bin/mysql -h************ -P3306 -uucenter -panzhi <<EOF
use ucenter;
select  "*8",concat('$','5'),"HMSET",concat('$','8'),"testtest",
concat('$',IFNULL(length(login_name),0)),IFNULL(login_name,''),
concat('$',IFNULL(length(id),0)),IFNULL(id,''),
concat('$',IFNULL(length(email),0)),IFNULL(email,''),
concat('$',IFNULL(length(id),0)),IFNULL(id,''),
concat('$',IFNULL(length(telphone),0)),IFNULL(telphone,''),
concat('$',IFNULL(length(id),0)),IFNULL(id,'') 
INTO OUTFILE '/tmp/data.txt' FIELDS TERMINATED BY '\r\n' LINES TERMINATED BY '\r\n'
from u_bbs_passport_manage ;
quit
EOF
date +%s ;
echo 'bigen change'
#cat /tmp/data.txt | /usr/local/bin/redis-cli   --pipe  -h **********

其中

FIELDS TERMINATED BY ',' 字段间分割符
OPTIONALLY ENCLOSED BY 
'"' 将字段包围 对数值型无效
LINES TERMINATED BY 
'\n' 换行符



生成的文件 data.txt

*8\r\n$5\r\nHMSET\r\n$8\r\ntesttest\r\n$5\r\nadmin\r\n$1\r\n1\r\n$0\r\n\r\n$1\r\n1\r\n$0\r\n\r\n$1\r\n1\r\n*8\r\n$5\r\nHMSET\r\n$8\r\ntesttest\r\n$3\r\n��N\r\n$1\r\n2\r\n$0\r\n\r\n$1\r\n2\r\n$0\r\n\r\n$1\r\n2\r\n


其中\r\n在文件中是看不到的被解析成换行了


执行

cat /tmp/data.txt | /usr/local/bin/redis-cli   --pipe  -h **********

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值