【问题标题】:How to set TTL to make Redis keys expire in flink-connector-redis?flink-connector-redis 中如何设置 TTL 使 Redis 的 key 过期?
【发布时间】: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


    【解决方案1】:

    不幸的是版本 1.0 is the latest release 所以你需要从源代码构建连接器

    最好, D.

    【讨论】:

    • 谢谢大卫!我跟进GitHub 并创建了一个JIRA ticket 以查看团队是否可以帮助发布新版本。
    猜你喜欢
    • 1970-01-01
    • 2023-01-31
    • 2018-12-06
    • 2013-01-10
    • 1970-01-01
    • 2018-10-08
    • 1970-01-01
    • 2014-12-11
    • 2022-10-05
    相关资源
    最近更新 更多