Storm存储结果至Redis
sudo bin/redis-server conf/redis.6388.conf
<dependency>
<groupId>org.apache.storm</groupId>
<artifactId>storm-redis</artifactId>
<version>${storm.version}</version>
</dependency>

@Override
public void execute(Tuple input) {
String key = lookupMapper.getKeyFromTuple(input);
Object lookupValue; JedisCommands jedisCommand = null;
try {
jedisCommand = getInstance(); switch (dataType) {
case STRING:
lookupValue = jedisCommand.get(key);
break; case LIST:
lookupValue = jedisCommand.lpop(key);
break; case HASH:
lookupValue = jedisCommand.hget(additionalKey, key);
break; case SET:
lookupValue = jedisCommand.scard(key);
break; case SORTED_SET:
lookupValue = jedisCommand.zscore(additionalKey, key);
break; case HYPER_LOG_LOG:
lookupValue = jedisCommand.pfcount(key);
break; default:
throw new IllegalArgumentException("Cannot process such data type: " + dataType);
} List<Values> values = lookupMapper.toTuple(input, lookupValue);
for (Values value : values) {
collector.emit(input, value);
} collector.ack(input);
} catch (Exception e) {
this.collector.reportError(e);
this.collector.fail(input);
} finally {
returnInstance(jedisCommand);
}
RedisState and RedisMapState, which provide Jedis interface just for single redis. RedisClusterState and RedisClusterMapState, which provide JedisCluster interface, just for redis cluster.

Options<Object> fiveMinitesOptions = new Options<>();
fiveMinitesOptions.dataTypeDescription = new RedisDataTypeDescription(RedisDataTypeDescription.RedisDataType.HASH,
"controller:5min");
logStream.each(new Fields("logObject"), new Log5MinGroupFunction(), new Fields("key"))
.groupBy(new Fields("key"))
.persistentAggregate(RedisMapState.nonTransactional(poolConfig, fiveMinitesOptions), new Fields("logObject"),
new LogCombinerAggregator(), new Fields("statistic"));
controller:5min
Log5MinGroupFunction生成的key,LogCombinerAggregator合并完成后的value;
@Override public List<T> multiGet(List<List<Object>> keys) {
if (keys.size() == 0) {
return Collections.emptyList();
}
List<String> stringKeys = buildKeys(keys);
List<String> values = retrieveValuesFromRedis(stringKeys);
return deserializeValues(keys, values);
}
private List<String> buildKeys(List<List<Object>> keys) {
List<String> stringKeys = new ArrayList<String>();
for (List<Object> key : keys) {
stringKeys.add(getKeyFactory().build(key));
}
return stringKeys;
}
@Override
public void multiPut(List<List<Object>> keys, List<T> vals) {
if (keys.size() == 0) {
return;
}
Map<String, String> keyValues = new HashMap<String, String>();
for (int i = 0; i < keys.size(); i++) {
String val = new String(getSerializer().serialize(vals.get(i)));
String redisKey = getKeyFactory().build(keys.get(i));
keyValues.put(redisKey, val);
}
updateStatesToRedis(keyValues);
}
@Override
protected List<String> retrieveValuesFromRedis(List<String> keys) {
String[] stringKeys = keys.toArray(new String[keys.size()]); Jedis jedis = null;
try {
jedis = jedisPool.getResource(); RedisDataTypeDescription description = this.options.dataTypeDescription;
switch (description.getDataType()) {
case STRING:
return jedis.mget(stringKeys); case HASH:
return jedis.hmget(description.getAdditionalKey(), stringKeys);
protected void updateStatesToRedis(Map<String, String> keyValues) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
RedisDataTypeDescription description = this.options.dataTypeDescription;
switch (description.getDataType()) {
case STRING:
String[] keyValue = buildKeyValuesList(keyValues);
jedis.mset(keyValue);
if(this.options.expireIntervalSec > 0){
Pipeline pipe = jedis.pipelined();
for(int i = 0; i < keyValue.length; i += 2){
pipe.expire(keyValue[i], this.options.expireIntervalSec);
}
pipe.sync();
}
break;
case HASH:
jedis.hmset(description.getAdditionalKey(), keyValues);
if (this.options.expireIntervalSec > 0) {
jedis.expire(description.getAdditionalKey(), this.options.expireIntervalSec);
}
break;
Storm存储结果至Redis的更多相关文章
- C# Azure 存储-分布式缓存Redis工具类 RedisHelper
using System; using System.Collections.Generic; using Newtonsoft.Json; using StackExchange.Redis; na ...
- C# Azure 存储-分布式缓存Redis在session中的配置
1. 开始 对于分布式的缓存,平常的session的处理是一个用户对应一台分布式的机器,如果这台机器中途挂机或者不能处理这个用户session的情况发生,则此用户的session会丢失,会发生不可预知 ...
- C# Azure 存储-分布式缓存Redis的新建&配置&查看
1. 介绍 Redis 是一款开源的,基于 BSD 许可的,高级键值 (key-value) 缓存 (cache) 和存储 (store) 系统.由于 Redis 的键包括 string,hash,l ...
- 一些应该使用mongodb或者其他文档存储而不是redis或mysql、oracle json的情形(最近更新场景)
通常来说,我们应该使用应用的特性而不是自己的爱好或者规定而去选择一种合适的组件,选择的标准应该是这个组件最适合或者本身其设计就是为了解决这个问题,而不是这个组件能够做这事情为标准.就拿存储来说,任何时 ...
- PHP 更改session存储方式为Redis
前言: 服务器默认的session存放方式是file.当客户端发送请求带有PHPSESSID时是顺序的去比对session存储文件,如果有5000个session文件,那就有可能需要比对4998次那么 ...
- 服务端指南 数据存储篇 | 聊聊 Redis 使用场景(转)
作者:梁桂钊 本文,是升级版,补充部分实战案例.梳理几个场景下利用 Redis 的特性可以大大提高效率. 随着数据量的增长,MySQL 已经满足不了大型互联网类应用的需求.因此,Redis 基于内存存 ...
- 爬虫文件存储-3:Redis
前提条件: 安装并运行redis服务端程序,安装RedisPy库 说明:Redis 是 StrictRedis 的子类,它的主要功能是用于向后兼容旧版本库里的几个方法,官方推荐使用 StrictRed ...
- 【原】thinkphp实现存储session至redis
Thinkphp\Library\Think\Session\Driver中新建redis缓存文件:Redis.class.php Thinkphp\Common\function.php 中 fun ...
- redis数据存储--C++连接redis
一.下载的是Redis Windows版本:下载地址:https://github.com/microsoftarchive/redis:解压到:E:\Software\redis-3.0: 二.用V ...
随机推荐
- 使用Inno Setup Compiler制作安装软件包
前言 项目开发完成之后,需要程序打包发行,本文使用Inno Setup工具制作安装软件包. 系统环境 系统:win7_x64 工具:Inno Setup Complier 实现步骤 1.下载安装Inn ...
- cloneNode
- Linux系统部署Web项目
首先,需要有java环境和tomcat服务器,至于这个怎么安装,可以参考:云服务器 java+tomcat 部署与配置 项目部署 有两个大步骤: Step1 将已经写好的web项目打包成war包,在I ...
- Codeforces123E. Maze【树形dp】【概率dp】【证明题】
LINK 题目大意 一棵树,上面的每个点都有一定概率成为起点和终点 从起点出发,随机游走,并按照下列规则统计count: DFS(x) if x == exit vertex then finish ...
- The Suspects 并查集
Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recognized ...
- 《DSP using MATLAB》Problem 4.2
用matlab不会证,惭愧.
- 《DSP using MATLAB》 Problem 3.22
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- LeetCode Majority Element Python
Given an array of size n, find the majority element. The majority element is the element that appear ...
- $.inArray方法
- 笔记本设置 2K 显示屏 Intel HD Graphics 3000
收了一台 32英寸的显示器,接到笔记 本只有 1920x1080,心想没得救了,要换笔记本才能用了. 在网上找了一圈,找到一篇说 Intel HD Graphics 3000 可以支持到 2560x1 ...