All Downloads are FREE. Search and download functionalities are using the official Maven repository.

es.moki.ratelimitj.redis.time.RedisTimeSupplier Maven / Gradle / Ivy

There is a newer version: 0.7.0
Show newest version
package es.moki.ratelimitj.redis.time;


import com.lambdaworks.redis.api.StatefulRedisConnection;
import es.moki.ratelimitj.core.time.TimeSupplier;

import javax.annotation.concurrent.ThreadSafe;
import java.util.concurrent.CompletionStage;

import static java.util.Objects.requireNonNull;

/**
 * A Redis based time supplier.
 * 

* It may be desirable to use a Redis based time supplier if the software is running on a group of servers with * different clocks or unreliable clocks. A disadvantage of the Redis based time supplier is that it introduces * an additional network round trip. */ @ThreadSafe public class RedisTimeSupplier implements TimeSupplier { private final StatefulRedisConnection connection; public RedisTimeSupplier(StatefulRedisConnection connection) { this.connection = requireNonNull(connection); } @Override public CompletionStage getAsync() { return connection.async().time().thenApply(strings -> Long.parseLong(strings.get(0))); } @Override public long get() { return Long.parseLong(connection.sync().time().get(0)); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy