DATAREDIS-688 - Return delete result via RedisOperations.delete(…).

We now return the deletion count for multi-key deletes and whether a single key was deleted for RedisOperations.delete(…).

Original Pull Request: #276
This commit is contained in:
Mark Paluch
2017-09-07 11:03:04 +02:00
committed by Christoph Strobl
parent 50b5bd69af
commit 1e96b8efa9
3 changed files with 12 additions and 16 deletions

View File

@@ -159,10 +159,10 @@ public interface RedisOperations<K, V> {
* Delete given {@code key}.
*
* @param key must not be {@literal null}.
* @return The number of keys that were removed.
* @return {@literal true} if the key was removed.
* @see <a href="http://redis.io/commands/del">Redis Documentation: DEL</a>
*/
void delete(K key);
Boolean delete(K key);
/**
* Delete given {@code keys}.
@@ -171,7 +171,7 @@ public interface RedisOperations<K, V> {
* @return The number of keys that were removed.
* @see <a href="http://redis.io/commands/del">Redis Documentation: DEL</a>
*/
void delete(Collection<K> keys);
Long delete(Collection<K> keys);
/**
* Determine the type stored at {@code key}.

View File

@@ -692,14 +692,13 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
* @see org.springframework.data.redis.core.RedisOperations#delete(java.lang.Object)
*/
@Override
public void delete(K key) {
public Boolean delete(K key) {
byte[] rawKey = rawKey(key);
execute(connection -> {
connection.del(rawKey);
return null;
}, true);
Long result = execute(connection -> connection.del(rawKey), true);
return result != null && result.intValue() == 1;
}
/*
@@ -707,18 +706,15 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
* @see org.springframework.data.redis.core.RedisOperations#delete(java.util.Collection)
*/
@Override
public void delete(Collection<K> keys) {
public Long delete(Collection<K> keys) {
if (CollectionUtils.isEmpty(keys)) {
return;
return 0L;
}
byte[][] rawKeys = rawKeys(keys);
execute(connection -> {
connection.del(rawKeys);
return null;
}, true);
return execute(connection -> connection.del(rawKeys), true);
}
/*