Redis中PipeLine使用(二)---批量get与批量set
来源:互联网 发布:mac os 哪个版本号 编辑:程序博客网 时间:2024/06/05 22:48
批量查询的相关问题总结
再做测试之前首先向redis中批量插入一组数据
1-->12-->23-->34-->45-->56-->6
现在批量get数据
for (Entry<String,String> entry :map.entrySet()) { pipe.get(entry.getKey().getBytes()); } List<Object> list=pipe.syncAndReturnAll(); for(Object o:list){ byte[] tmp=(byte[])o; System.out.println("---->"+new String(tmp)); }
其打印结果是:
然而这并不是我们想要的,那怎样才能知道打印的这个value对应的key呢?
这样的应用场景很多,我们首先批量从redis get数据出来,然后将get的数据与内存中的数据进行运行在批量写入数据库!
这是需要引入一个HashMap
HashMap<String, String> map=new HashMap<String, String>(); map.put("1","1"); map.put("2","2"); map.put("3","3"); map.put("4","4"); map.put("5","5"); map.put("6","6"); Pipeline pipe=redis.pipelined(); HashMap<byte[], Response<byte[]>> newMap=new HashMap<byte[], Response<byte[]>>(); for (Entry<String,String> entry :map.entrySet()) { newMap.put(entry.getKey().getBytes(), pipe.get(entry.getKey().getBytes())); } pipe.sync(); for (Entry<byte[], Response<byte[]>> entry :newMap.entrySet()) { Response<byte[]> sResponse=(Response<byte[]>)entry.getValue(); System.out.println(new String(entry.getKey())+"-----"+new String(sResponse.get()).toString()); }
批量get之后与内存的数据想加再批量set
HashMap<String, String> map=new HashMap<String, String>(); map.put("1","1"); map.put("2","2"); map.put("3","3"); map.put("4","4"); map.put("5","5"); map.put("6","6"); Pipeline pipe=redis.pipelined(); HashMap<byte[], Response<byte[]>> newMap=new HashMap<byte[], Response<byte[]>>(); for (Entry<String,String> entry :map.entrySet()) { newMap.put(entry.getKey().getBytes(), pipe.get(entry.getKey().getBytes())); } pipe.sync(); for (Entry<byte[], Response<byte[]>> entry :newMap.entrySet()) { Response<byte[]> sResponse=(Response<byte[]>)entry.getValue(); long temp=Long.valueOf(Long.parseLong(map.get(new String(entry.getKey())))+Long.parseLong(new String(sResponse.get()).toString())); map.put(new String(entry.getKey()), Long.toString(temp)); } for (Entry<String,String> entry :map.entrySet()) { pipe.set(entry.getKey().getBytes(), entry.getValue().getBytes()); } pipe.sync();
0 0
- Redis中PipeLine使用(二)---批量get与批量set
- Redis中PipeLine使用(二)---批量get与批量set
- 在Redis集群中使用pipeline批量插入
- Redis使用pipeline批量插入hash数据
- [Redis]RedisCluster使用pipeline批量读取数据
- redis批量上传数据(pipeline
- Java使用Pipeline对Redis批量读写(hmset&hgetall)
- Java使用Pipeline对Redis批量读写(hmset&hgetall)
- Java使用Pipeline对Redis批量读写(hmset&hgetall)
- redis-cluster官方集群模式下使用pipeline批量操作
- Java使用Pipeline对Redis批量读写(10)
- 使用Redis的管道(Pipeline)进行批量操作
- Redis高级特性:Pipeline批量发送请求
- spark 批量写入redis (pipeline + 分批提交)
- Redis中PipeLine使用
- spring-data-redis 使用pipeline批量设置过期时间的bug
- redis大幅性能提升之使用管道(PipeLine)和批量(Batch)操作
- spring-data-redis 使用pipeline批量设置过期时间的bug
- 建立多人协作git仓库/git 仓库权限控制(SSH)
- Android生成签名包以及空白包打签名包
- mac机下切换不同版本的jdk
- java 时间转换
- MongoDB的聚合功能使用
- Redis中PipeLine使用(二)---批量get与批量set
- Java 理论与实践: 非阻塞算法简介--转载
- 常用的机器学习&数据挖掘翻译(转)
- Codevs_P2981 查字典1(BIT)
- 设置video.js多视频连续播放
- yycg之用户身份校验(二)
- Elasticsearch-PHP 索引操作
- 鸟哥的Linux私房菜(基础篇)- 一个简单的 SPFdisk 分割实例
- AS 项目 Gradle DSL method not found: 'runProguard()