You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Redisson在DragonFlyDB设置长TTL(10天+)报错问题求助

Redisson + DragonFlyDB 设置10天以上TTL触发PSETEX报错的问题与临时解决办法

问题现象

使用Redisson为键值对设置10天以上的长TTL时,Redisson会将TTL转换为毫秒后向DragonFlyDB发送PSETEX命令,触发如下报错:

org.redisson.client.RedisException: ERR value is not an integer or out of range. channel: [id: 0xfa05de9e, L:/127.0.0.1:32812 - R:localhost/127.0.0.1:32773] command: (PSETEX), promise: java.util.concurrent.CompletableFuture@67330d28[Not completed], params: [hello, 864000000, PooledUnsafeDirectByteBuf(ridx: 0, widx: 8, cap: 256)]

其中864000000(10天对应的毫秒数)并未超出Integer的最大值,但设置3天TTL时执行正常。切换到RedisCluster环境后,该TTL值可正常使用,说明问题仅存在于DragonFlyDB环境。

相关代码

override fun cacheString(key: String, value: String, ttl: Duration): RFuture<Void> {
       val result = redisClient.getBucket<String>(key).setAsync(value, ttl.seconds, TimeUnit.SECONDS)
       return result
}

val failResult = cacheMangerService.cacheString("hello", "world", Duration.ofDays(10)) // 抛出异常

val succesResult = cacheMangerService.cacheString("hello", "world", Duration.ofDays(3)) // 执行成功

临时解决方案

避免使用Redisson的setAsync方法直接携带TTL参数,改为先设置键值对,再手动调用expire()方法单独设置TTL:

override fun cacheString(key: String, value: String, ttl: Duration): RFuture<Boolean> {
    val bucket = redisClient.getBucket<String>(key)
    // 先设置值,再异步设置TTL
    return bucket.setAsync(value)
        .thenCompose { bucket.expireAsync(ttl) }
}

内容的提问来源于stack exchange,提问作者NhatHo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 11:07:38