如何通过使用Redisson客户端获取当前时间

huangapple go评论68阅读模式
英文:

how to get the current time by use redisson client

问题

如果我有几台服务器,可能这些服务器的当前系统时间是不同的。如何使用Redisson来获取统一的当前时间?

我已经阅读了RedissonClient的API,但是我还没有找到获取统一当前时间的方法。

英文:

if i have several servers, maybe servers's current system time are different. how can i all use redisson to get current time?

I've read the RedissonClient api, but I haven't found the way to get this yet

答案1

得分: 1

假设你的应用中有一个 RestTemplate bean,你可以尝试以下代码:

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

Assuming you have a RestTemplate bean in your app, you can try this:

Long redisServerTimestamp = redisTemplate.execute(
                    (RedisCallback&lt;Long&gt;) conn -&gt; conn.serverCommands().time());

答案2

得分: 0

你可以这样做:

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

You can do it like this:

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

huangapple
  • 本文由 发表于 2020年8月26日 15:16:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/63592402.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定