zoukankan      html  css  js  c++  java
  • 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)
    }
    })

  • 相关阅读:
    对于global的介绍
    elang和python互通的例子
    gen_server的一些心得
    erlang分布式例子
    erlang热部署
    erlang配置三方库
    opencv学习之PyImageSearch
    雅克比矩阵
    罗德里格斯公式的证明
    opencv学习网站
  • 原文地址:https://www.cnblogs.com/maoxiangyi/p/11065897.html
Copyright © 2011-2022 走看看