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\"}]}"

原文地址:https://www.cnblogs.com/Leonardo-li/p/12114504.html

时间: 2024-10-02 10:57:00

redis插入单个较大的键值的相关文章

Mybatis 插入数据后返回主键值

Oracle中获取刚刚插入记录的主键值: <insert id="insertSelective" parameterType="com.jxxx.p2pp.model.UUserInfo">     <selectKey resultType="java.math.BigDecimal" order="BEFORE" keyProperty="id">    SELECT U_US

mybatis在oracle插入对象后返回主键值

在mybatis中默认插入一条记录后,返回值为插入记录的条数. 现在想获取插入记录后,当前被插入的记录的主键值,需在insert方法中添加如下代码: <insert id="insert" parameterType="cn.com.pm.ppm.model.UserInfo" >   <selectKey resultType="java.math.BigDecimal" order="BEFORE" ke

Redis集群环境下的键值空间监听事件实现方案

一直想记录工作中遇到的问题和解决的方法,奈何没有找到一方乐土,最近经常反思,是否需要记录平时的点滴,后台还是决定下定决心记录一些,以便以后用到的时候找不着,实现这样的一个功能主要也是业务所需要的. 需求:要求统计所有会员在线人数,并根据会员在线状态同步改变人数. 之前用户登录使用session去控制,那么可以通过session进行在线用户人数统计,后来实现无状态不在依赖session作为用户在线的标准,使用Redis替换了Session,那么用户直接退出也好做,但是会存在用户直接关闭页面的情况,

[Redis]Redis的五种数据类型与键值/服务器相关命令

-------------------------------------------------------------------------------------- String(字符串):最简单的数据类型. set age 18 ( set age 18 ex 5 ) # 设置过期时间5秒 setex age 5 18   # 效果同上, 使用 ttl age 可以查看剩余有效时间 psetex age 5000 18  # 同上,只是以毫秒为单位设置key的过期时间 ( set ag

Redis学习第七课:键值命令和服务器命令

Redis键值相关命令                                                                                                                                   keys:返回满足给定pattern的所有key.(用法:keys pattern表达式) exists:确认一个key是否存在.(用法:exists key) del:删除一个key.(用法:del key) ex

mybatis中useGeneratedKeys用法--插入数据库后获取主键值

前言:今天无意在mapper文件中看到useGeneratedKeys这个词,好奇就查了下,发现能解决我之前插入有外键表数据时,这个外键获取繁琐的问题,于是学习敲DEMO记录    在项目中经常需要获取到插入数据的主键来保障后续操作,数据库中主键一般我们使用自增或者uuid()的方式自动生成 问题:对于uuid使用Java代码生成的方式还比较容易控制,然而使用数据库生成的主键,这样我们就需要将插入的数据再查询出来得到主键,某些情况下还可能查询到多条情况,这样就比较尴尬了. 那有什么办法来插入数据

MySQL 插入与自增主键值相等的字段 与 高并发下保证数据准确的实验

场景描述: 表t2 中 有 自增主键 id  和 字段v  当插入记录的时候 要求 v与id 的值相等(按理来说这样的字段是需要拆表的,但是业务场景是 只有某些行相等 ) 在网上搜的一种办法是 先获取自增ID SELECT max(id)+1 from t2 然后给v字段插入获取到的值 但是这样的做法在有删除行+调整过自增值的表中是不准确的 于是换个思路 从 information_schema 下手 读取表的信息 INSERT INTO `t2` VALUES ( NULL, ( SELECT

mybatis insert语句 返回插入的记录的主键值

Map<String,Object> paymentMp = new HashMap<String,Object>();        paymentMp.put("amount", 12.0 );        paymentMp.put("pay", Attributes.Payment_Pay_No);        paymentMp.put("status", Attributes.Payment_Status_

mybatis 插入数据并返回主键值

<insert id="insert" parameterType="com.pojo.TSubject" useGeneratedKeys="true" keyProperty="subjectid" > insert into t_subject ( parentid, subjectname, subjecttype, subjectitem, subjectanser, displaytype) value