flink-connector-redis如何设置TTL让Redis key过期?

How to set TTL to make Redis keys expire in flink-connector-redis?

我正在使用这个 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 class时,我只有

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

不幸的是版本 1.0 is the latest release 因此您需要从源构建连接器

最好的, D.