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 4bc871d637..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(), + 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()) {