redis插入单个较大的键值
1.前言:
在linux的命令行界面或者是进入到redis数据库中,在插入较大的键值时,由于命令行界面对于字符个数的限制,都不能完全将redis的键值粘贴上去,这个时通过shell脚本比较容易实现
2.涉及的文件
redis.sh #执行插入键值的脚本
redis.txt #存放键值数据的文件
3.注意
在复制redis键值数据到redis.txt文件中的时候注意空格
4.执行插入脚本redis.sh
#!/bin/bash #name: redis.sh #Author: lipc #Date: 2019-11-30 #Notes: 此脚本用来执行redis键值插入 #用来将dos命令转换为utf8 dos=`rpm -qa | grep dos2unix` if [ $? -eq 0 ];then dos2unix /app/redis.txt >/dev/null 2>&1 else yum -y install dos2unix sleep 1 dos2unix /app/redis.txt >/dev/null 2>&1 fi data=`cat /app/redis.txt` /usr/bin/redis-cli -h 192.168.180.80 -p 6379 -a 'redispass' -n 1 $data
5.存放redis键值文件redis.txt
cat redis.txt
SETEX wc065|d355b01b418d11e9b4f96c92bf4e95f0#lipc|4DF04C9AD7B172D6C8EEB2BCC96C1C81|64 86400 "{\"groupid\":\"g80000118819486406\",\"senderMsgList\":[{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshzhangyg79\",\"version\":1061,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshyuzhd3\",\"version\":173,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshliuzhd28\",\"version\":367,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshchenyy66\",\"version\":748,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshhuagy\",\"version\":716,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshzhangjw92\",\"version\":790,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshyanjl78\",\"version\":184,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshwangm227\",\"version\":142,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshwangy826\",\"version\":436,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshyuzm3\",\"version\":367,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshguxj9\",\"version\":491,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshchenr63\",\"version\":275,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshzhaoh88\",\"version\":1221,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshwangxy522\",\"version\":196,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshpucx\",\"version\":406,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"groupid\":\"g80000118819486406\",\"senderMsgList\":[{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshanwt\",\"version\":357,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshmengxy668\",\"version\":807,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshhuangyn2\",\"version\":1089,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshdurx2\",\"version\":1258,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshzhengsh7\",\"version\":346,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshyaolg5\",\"version\":404,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshguozhq7\",\"version\":1067,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshlichch7\",\"version\":670,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshyaoqm3\",\"version\":352,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshlil595\",\"version\":124,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshjiwj3\",\"version\":495,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshjinhm30\",\"version\":230,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshwangyx323\",\"version\":559,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshchenfy63\",\"version\":332,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshliangyf8\",\"version\":556,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"groupid\":\"g80000118819486406\",\"senderMsgList\":[{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshwangy938\",\"version\":584,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshxujl520\",\"version\":390,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshchenff5\",\"version\":584,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshzhul206\",\"version\":1151,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshlihh25\",\"version\":204,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshwangq6386\",\"version\":214,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshcheny539\",\"version\":1618,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshdongzh3\",\"version\":770,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshshaoqj\",\"version\":553,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshwangjm226\",\"version\":335,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshwangwm36\",\"version\":158,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"},{\"msgReceiver\":\"d355b01b418d11e9b4f96c92bf4e65f0#zshliy8988\",\"version\":264,\"dateCreated\":\"1575943622000\",\"msgId\":\"4DF04C9AD7B172D6C8EEB2BCC96C1C81|64\",\"deviceNo\":\"00:50:56:80:67:7A\"}]}"