DATAREDIS-469 - Throw DataRetrievalFailureException for atomic numbers when key is removed.

We now throw DataRetrievalFailureException in case of get() when the underlying key storing the value of an AtomicInteger, AtomicLong or AtomicDouble is removed from Redis.

Original pull request: #182.
This commit is contained in:
Christoph Strobl
2016-03-24 12:40:09 +01:00
committed by Mark Paluch
parent d097a64bc6
commit 20cfd3e76c
6 changed files with 110 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import java.util.Collections;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.BoundKeyOperations;
@@ -38,6 +39,7 @@ import org.springframework.util.Assert;
*
* @author Jennifer Hickey
* @author Thomas Darimont
* @author Christoph Strobl
*/
public class RedisAtomicDouble extends Number implements Serializable, BoundKeyOperations<String> {
@@ -143,7 +145,13 @@ public class RedisAtomicDouble extends Number implements Serializable, BoundKeyO
* @return the current value
*/
public double get() {
return operations.get(key);
Double value = operations.get(key);
if (value != null) {
return value.doubleValue();
}
throw new DataRetrievalFailureException(String.format("The key '%s' seems to no longer exist.", key));
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2014 the original author or authors.
* Copyright 2011-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import java.util.Collections;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.BoundKeyOperations;
@@ -39,6 +40,7 @@ import org.springframework.util.Assert;
* @see java.util.concurrent.atomic.AtomicInteger
* @author Costin Leau
* @author Thomas Darimont
* @author Christoph Strobl
*/
public class RedisAtomicInteger extends Number implements Serializable, BoundKeyOperations<String> {
@@ -141,7 +143,13 @@ public class RedisAtomicInteger extends Number implements Serializable, BoundKey
* @return the current value
*/
public int get() {
return Integer.valueOf(operations.get(key));
Integer value = operations.get(key);
if (value != null) {
return value.intValue();
}
throw new DataRetrievalFailureException(String.format("The key '%s' seems to no longer exist.", key));
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2014 the original author or authors.
* Copyright 2011-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@ import java.util.Collections;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.BoundKeyOperations;
@@ -39,6 +40,7 @@ import org.springframework.util.Assert;
* @see java.util.concurrent.atomic.AtomicLong
* @author Costin Leau
* @author Thomas Darimont
* @author Christoph Strobl
*/
public class RedisAtomicLong extends Number implements Serializable, BoundKeyOperations<String> {
@@ -149,7 +151,13 @@ public class RedisAtomicLong extends Number implements Serializable, BoundKeyOpe
* @return the current value
*/
public long get() {
return operations.get(key);
Long value = operations.get(key);
if (value != null) {
return value.longValue();
}
throw new DataRetrievalFailureException(String.format("The key '%s' seems to no longer exist.", key));
}
/**