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,