【问题标题】:how to get the current time by use redisson client如何使用redisson客户端获取当前时间
【发布时间】:2020-12-14 22:40:58
【问题描述】:

如果我有几台服务器,可能服务器的当前系统时间不同。我怎样才能使用 redisson 来获取当前时间?

我已经阅读了 RedissonClient api,但我还没有找到获得它的方法

【问题讨论】:

  • UTC 是时间处理的标准。寻找任何提供 UTC 时间的函数。
  • ...像java.time.ZonedDateTime.now(ZoneId.of("UTC"));,也许...

标签: java redis redis-cluster redisson


【解决方案1】:

你可以这样做:

RedisSingle nodes = redisson.getRedisNodes(RedisNodes.SINGLE);
Time time = nodes.getInstance().time();

【讨论】:

    【解决方案2】:

    假设你的应用中有一个 RestTemplate bean,你可以试试这个:

    Long redisServerTimestamp = redisTemplate.execute(
                        (RedisCallback<Long>) conn -> conn.serverCommands().time());
    

    【讨论】:

      猜你喜欢
      • 2020-08-04
      • 2020-05-06
      • 2018-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多