RedisRichSinkFunction
自定义RedisRichSinkFunction,支持Redis数据库连接池。
定义
public class RedisRichSinkFunction<IN> extends RichSinkFunction<IN> {
private JedisPool pool = null;
@Override
public void open(Configuration parameters) throws Exception {
ParameterTool parameterTool = (ParameterTool) getRuntimeContext().getExecutionConfig().getGlobalJobParameters();
String hostname = parameterTool.get("redis_hostname");
int port = Integer.parseInt(parameterTool.get("redis_port"));
pool = RedisPoolFactory.getPool(hostname, port);
}
public JedisPool getPool() {
return pool;
}
}
使用
.addSink(new RedisRichSinkFunction[util.HashMap[String, (Integer, util.Set[String])]] {
override def invoke(value: util.HashMap[String, (Integer, util.Set[String])], context: SinkFunction.Context[_]): Unit = {
RedisHandler.setPvAndUv(getPool(), value)
}
})
个人网站:shuoyizui.com
公众号:写个框架玩
近期在公众号会发布一系列文章,主要是想完成一个简化的MapReduce框架的编写。实现Mapreduce编程模型、任务远程提交、任务分配、任务执行等功能。设计到了动态代理、反射、网络通信、序列化、消息队列、netty、自定义类加载器、多线程、shell等技术点。