Last active
February 7, 2020 11:58
-
-
Save brachi-wernick/7f9f53adb73a122cf9c8bdab730fb11c to your computer and use it in GitHub Desktop.
MyFn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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