DATAREDIS-316 - Polishing.

Extend JavaDoc documentation. Spelling fixes. Add Expiration.from factory method to create Expiration from all available time units.

Original pull request: #170.
This commit is contained in:
Mark Paluch
2016-02-16 14:29:13 +01:00
parent 0c6c127b5e
commit 1151bcf136
8 changed files with 107 additions and 10 deletions

View File

@@ -75,8 +75,10 @@ public interface RedisStringCommands {
/**
* Set {@code value} for {@code key} applying timeouts from {@code expiration} if set and inserting/updating values
* depending on {@code options}.
*
* depending on {@code option}.
* <p>
* See http://redis.io/commands/set
*
* @param key must not be {@literal null}.
* @param value must not be {@literal null}.
* @param expiration can be {@literal null}. Defaulted to {@link Expiration#persistent()}.

View File

@@ -98,7 +98,9 @@ public interface StringRedisConnection extends RedisConnection {
/**
* Set {@code value} for {@code key} applying timeouts from {@code expiration} if set and inserting/updating values
* depending on {@code options}.
* depending on {@code option}.
* <p>
* See http://redis.io/commands/set
*
* @param key must not be {@literal null}.
* @param value must not be {@literal null}.

View File

@@ -604,7 +604,7 @@ public class JedisClusterConnection implements RedisClusterConnection {
@Override
public void set(byte[] key, byte[] value, Expiration expiration, SetOption option) {
if (expiration == null || expiration.isPersitent()) {
if (expiration == null || expiration.isPersistent()) {
if (option == null || ObjectUtils.nullSafeEquals(SetOption.UPSERT, option)) {
set(key, value);

View File

@@ -1147,7 +1147,7 @@ public class JedisConnection extends AbstractRedisConnection {
@Override
public void set(byte[] key, byte[] value, Expiration expiration, SetOption option) {
if (expiration == null || expiration.isPersitent()) {
if (expiration == null || expiration.isPersistent()) {
if (option == null || ObjectUtils.nullSafeEquals(SetOption.UPSERT, option)) {
set(key, value);
@@ -1194,7 +1194,7 @@ public class JedisConnection extends AbstractRedisConnection {
if (expiration.getExpirationTime() > Integer.MAX_VALUE) {
throw new IllegalArgumentException(
"Expiration.exprirationTime must be less than equals Integer.MAX_VALUE for pipeline in Jedis.");
"Expiration.expirationTime must be less than Integer.MAX_VALUE for pipeline in Jedis.");
}
pipeline(new JedisStatusResult(pipeline.set(key, value, nxxx, expx, (int) expiration.getExpirationTime())));
@@ -1204,7 +1204,7 @@ public class JedisConnection extends AbstractRedisConnection {
if (expiration.getExpirationTime() > Integer.MAX_VALUE) {
throw new IllegalArgumentException(
"Expiration.exprirationTime must be less than equals Integer.MAX_VALUE for transactions in Jedis.");
"Expiration.expirationTime must be less than Integer.MAX_VALUE for transactions in Jedis.");
}
transaction(new JedisStatusResult(transaction.set(key, value, nxxx, expx,

View File

@@ -131,7 +131,7 @@ abstract public class JedisConverters extends Converters {
@Override
public byte[] convert(Expiration source) {
if (source == null || source.isPersitent()) {
if (source == null || source.isPersistent()) {
return new byte[0];
}

View File

@@ -628,7 +628,7 @@ abstract public class LettuceConverters extends Converters {
public static SetArgs toSetArgs(Expiration expiration, SetOption option) {
SetArgs args = new SetArgs();
if (expiration != null && !expiration.isPersitent()) {
if (expiration != null && !expiration.isPersistent()) {
switch (expiration.getTimeUnit()) {
case SECONDS:

View File

@@ -18,11 +18,13 @@ package org.springframework.data.redis.core.types;
import java.util.concurrent.TimeUnit;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
/**
* Expiration holds a value with its associated {@link TimeUnit}.
*
* @author Christoph Strobl
* @author Mark Paluch
* @since 1.7
*/
public class Expiration {
@@ -111,6 +113,31 @@ public class Expiration {
return new Expiration(expirationTime, TimeUnit.MILLISECONDS);
}
/**
* Creates new {@link Expiration} with the provided {@link TimeUnit}. Greater units than {@link TimeUnit#SECONDS} are
* converted to {@link TimeUnit#SECONDS}. Units smaller than {@link TimeUnit#MILLISECONDS} are converted to
* {@link TimeUnit#MILLISECONDS} and can lose precision since {@link TimeUnit#MILLISECONDS} is the smallest granularity
* supported by Redis.
*
* @param expirationTime
* @param timeUnit can be {@literal null}. Defaulted to {@link TimeUnit#SECONDS}
* @return
*/
public static Expiration from(long expirationTime, TimeUnit timeUnit) {
if (ObjectUtils.nullSafeEquals(timeUnit, TimeUnit.MICROSECONDS)
|| ObjectUtils.nullSafeEquals(timeUnit, TimeUnit.NANOSECONDS)
|| ObjectUtils.nullSafeEquals(timeUnit, TimeUnit.MILLISECONDS)) {
return new Expiration(timeUnit.toMillis(expirationTime), TimeUnit.MILLISECONDS);
}
if (timeUnit != null) {
return new Expiration(timeUnit.toSeconds(expirationTime), TimeUnit.SECONDS);
}
return new Expiration(expirationTime, TimeUnit.SECONDS);
}
/**
* Creates new persistent {@link Expiration}.
*
@@ -123,7 +150,7 @@ public class Expiration {
/**
* @return {@literal true} if {@link Expiration} is set to persistent.
*/
public boolean isPersitent() {
public boolean isPersistent() {
return expirationTime == -1;
}
}