Hi Ramya Have you ever tried flink-connector-redis<https://github.com/apache/bahir-flink/tree/master/flink-connector-redis> in bahir [1][2]? I think you could use it or obtain some insights.
[1] http://bahir.apache.org/docs/flink/current/flink-streaming-redis/ [2] https://github.com/apache/bahir-flink Best Yun Tang ________________________________ From: Yangze Guo <karma...@gmail.com> Sent: Tuesday, July 21, 2020 18:50 To: dev <dev@flink.apache.org> Subject: Re: Flink Redis connectivity Hi, I think you could implement `RichMapFunction` and create `redisClient` in the `open` method. Best, Yangze Guo On Tue, Jul 21, 2020 at 6:43 PM Ramya Ramamurthy <hair...@gmail.com> wrote: > > Hi, > > As per the understanding we have from the documentation, I guess its not > possible to take the redis connection within the Data Stream. In that case, > how should i proceed ? How can i access a DB client object within the > stream ?? > > I am using Flink 1.7. any help here would be appreciated. Thanks. > > RedisClient redisClient = new > RedisClient(RedisURI.create("redis://localhost:6379")); > RedisConnection<String, String> client = > redisClient.connect(); > DataStream<String> parsedStream = ipdetailsStream.map((MapFunction<Row, > String>) value -> { > > String ct = value.getField(5).toString(); > > String res = ""; > if (ct.equals("14") || ct.equals("4")) { > > res = client.set("key", "val"); > } > return res; > }); > > Thanks,