Skip to content

Commit

Permalink
fix: store heartbeat use redis setex with wrong timeunit
Browse files Browse the repository at this point in the history
Signed-off-by: ayue <[email protected]>
  • Loading branch information
AYue-94 committed Sep 3, 2024
1 parent 14909d0 commit 5e810d7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit 5e810d7

Please sign in to comment.