From 5e810d712f362c097d19b37107a37a2067e8097a Mon Sep 17 00:00:00 2001 From: ayue Date: Tue, 3 Sep 2024 12:38:28 +0800 Subject: [PATCH] fix: store heartbeat use redis setex with wrong timeunit Signed-off-by: ayue --- .../io/sermant/backend/dao/redis/RedisClientImpl.java | 2 +- .../backend/dao/redis/RedisClusterOperationImpl.java | 5 +++++ .../io/sermant/backend/dao/redis/RedisOperation.java | 10 ++++++++++ .../dao/redis/RedisStandAloneOperationImpl.java | 7 +++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/sermant-backend/src/main/java/io/sermant/backend/dao/redis/RedisClientImpl.java b/sermant-backend/src/main/java/io/sermant/backend/dao/redis/RedisClientImpl.java index 2e9a56a41e..488fdf3470 100644 --- a/sermant-backend/src/main/java/io/sermant/backend/dao/redis/RedisClientImpl.java +++ b/sermant-backend/src/main/java/io/sermant/backend/dao/redis/RedisClientImpl.java @@ -105,7 +105,7 @@ public boolean addEvent(Event event) { @Override public boolean addInstanceMeta(InstanceMeta instanceMeta) { - redisOperation.setex(instanceMeta.getMetaHash(), backendConfig.getHeartbeatEffectiveTime() / 1000, + redisOperation.psetex(instanceMeta.getMetaHash(), backendConfig.getHeartbeatEffectiveTime(), JSONObject.toJSONString(instanceMeta)); return true; } diff --git a/sermant-backend/src/main/java/io/sermant/backend/dao/redis/RedisClusterOperationImpl.java b/sermant-backend/src/main/java/io/sermant/backend/dao/redis/RedisClusterOperationImpl.java index 1879770798..1cfc142904 100644 --- a/sermant-backend/src/main/java/io/sermant/backend/dao/redis/RedisClusterOperationImpl.java +++ b/sermant-backend/src/main/java/io/sermant/backend/dao/redis/RedisClusterOperationImpl.java @@ -110,6 +110,11 @@ public String setex(String key, long seconds, String value) { return jedisCluster.setex(key, seconds, value); } + @Override + public String psetex(String key, long milliseconds, String value) { + return jedisCluster.psetex(key, milliseconds, value); + } + @Override public long hset(String key, String field, String value) { return jedisCluster.hset(key, field, value); diff --git a/sermant-backend/src/main/java/io/sermant/backend/dao/redis/RedisOperation.java b/sermant-backend/src/main/java/io/sermant/backend/dao/redis/RedisOperation.java index 09440b62a2..1aa1d39ae7 100644 --- a/sermant-backend/src/main/java/io/sermant/backend/dao/redis/RedisOperation.java +++ b/sermant-backend/src/main/java/io/sermant/backend/dao/redis/RedisOperation.java @@ -46,6 +46,16 @@ public interface RedisOperation { */ String setex(String key, long seconds, String value); + /** + * Store key values and specify expiration time + * + * @param key Data stored in Redis key + * @param milliseconds expiration time + * @param value Stored values + * @return Return execution result + */ + String psetex(String key, long milliseconds, String value); + /** * Set the specified hash field to the specified value. * diff --git a/sermant-backend/src/main/java/io/sermant/backend/dao/redis/RedisStandAloneOperationImpl.java b/sermant-backend/src/main/java/io/sermant/backend/dao/redis/RedisStandAloneOperationImpl.java index 312474b78f..110f6faecb 100644 --- a/sermant-backend/src/main/java/io/sermant/backend/dao/redis/RedisStandAloneOperationImpl.java +++ b/sermant-backend/src/main/java/io/sermant/backend/dao/redis/RedisStandAloneOperationImpl.java @@ -74,6 +74,13 @@ public String setex(String key, long seconds, String value) { } } + @Override + public String psetex(String key, long milliseconds, String value) { + try (Jedis jedis = jedisPool.getResource()) { + return jedis.psetex(key, milliseconds, value); + } + } + @Override public long hset(String key, String field, String value) { try (Jedis jedis = jedisPool.getResource()) {