Skip to content

Instantly share code, notes, and snippets.

@brachi-wernick
Last active February 7, 2020 11:58
Show Gist options
  • Save brachi-wernick/7f9f53adb73a122cf9c8bdab730fb11c to your computer and use it in GitHub Desktop.
Save brachi-wernick/7f9f53adb73a122cf9c8bdab730fb11c to your computer and use it in GitHub Desktop.
MyFn
public class MyFn extends DoFn<String, String> {
private static RedissonClient redisClient;
private final static Object lock = new Object();
private String redisHost;
private int redisPort;
MyFn(String redisHost, Integer redisPort) {
this.redisHost = redisHost;
this.redisPort = redisPort;
}
private RedissonClient getRedisClient() {
if (redisClient == null) {
synchronized (lock) {
if (redisClient == null) {
Config config = new Config();
String password = decryptRedisPassword();
config.useSingleServer()
.setAddress("redis://" + redisHost + ":" + redisPort);
redisClient = Redisson.create(config);
}
}
}
return redisClient;
}
@ProcessElement
public void processElement(ProcessContext context) {
RedissonClient redis = getRedisClient();
//some logic enrichment
redis.get()
// output
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment