【发布时间】:2021-10-18 01:05:32
【问题描述】:
我正在使用这个 Flink Redis sink 版本依赖:
<dependency>
<groupId>org.apache.bahir</groupId>
<artifactId>flink-connector-redis_2.11</artifactId>
<version>1.1-SNAPSHOT</version>
</dependency>
这是我当前的代码:
public static class MyRedisMapper implements RedisMapper<Tuple2<String, String>>{
@Override
public RedisCommandDescription getCommandDescription() {
return new RedisCommandDescription(RedisCommand.HSET, "MY_REDIS_KEY");
}
@Override
public String getKeyFromData(Tuple2<String, String> data) {
return data.f0;
}
@Override
public String getValueFromData(Tuple2<String, String> data) {
return data.f1;
}
}
FlinkJedisPoolConfig conf = new FlinkJedisPoolConfig.Builder().setHost("127.0.0.1").build();
DataStream<String> myStream = ...;
myStream.addSink(new RedisSink<Tuple2<String, String>>(conf, new MyRedisMapper());
目前向Redis写入数据后,数据会一直留在那里,不会过期。
我希望设置Redis TTL 使密钥过期。
official doc 很简单。
看完还是没头绪。
如何设置 TTL 以使我的 Redis 密钥过期?谢谢!
更新:
当我检查我正在使用的 Java 类时,我只有
public RedisCommandDescription(org.apache.flink.streaming.connectors.redis.common.mapper.RedisCommand redisCommand, java.lang.String additionalKey) { /* compiled code */ }
public RedisCommandDescription(org.apache.flink.streaming.connectors.redis.common.mapper.RedisCommand redisCommand) { /* compiled code */ }
但是,我发现了一个 pull request 将 TTL 添加到 HSET 以及一个新的 SETEX 命令,已于 2019 年 10 月合并。
我没有看到 SETEX 被添加到文档中 https://bahir.apache.org/docs/flink/current/flink-streaming-redis/
另外,我在拉取请求部分没有找到this line:
public RedisCommandDescription(RedisCommand redisCommand, String additionalKey, Integer additionalTTL)
在我当前的版本依赖中。
我在Maven中没有找到新的flink-connector-redis版本。
在哪里可以找到和使用最新版本的 flink-connector-redis?
【问题讨论】:
标签: java maven redis apache-flink