DATAREDIS-284 - Add support for zCard to ZSetOperations.
'zCard' has been introduced in addition to 'size' as it feels more natural for people using redis. 'size' in 'ZSetOperations' / 'BoundZsetOperations' now delegate to 'zCard'. Original Pull Request: #55
This commit is contained in:
committed by
Thomas Darimont
parent
d35375ec74
commit
f366ffc94e
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2013 the original author or authors.
|
||||
* Copyright 2011-2014 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.
|
||||
@@ -25,6 +25,7 @@ import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
|
||||
* ZSet (or SortedSet) operations bound to a certain key.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public interface BoundZSetOperations<K, V> extends BoundKeyOperations<K> {
|
||||
|
||||
@@ -72,7 +73,21 @@ public interface BoundZSetOperations<K, V> extends BoundKeyOperations<K> {
|
||||
|
||||
Long count(double min, double max);
|
||||
|
||||
/**
|
||||
* Returns the number of elements of the sorted set.
|
||||
*
|
||||
* @return
|
||||
* @see #zCard()
|
||||
*/
|
||||
Long size();
|
||||
|
||||
/**
|
||||
* Returns the number of elements of the sorted set.
|
||||
*
|
||||
* @return
|
||||
* @since 1.3
|
||||
*/
|
||||
Long zCard();
|
||||
|
||||
Double score(Object o);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2013 the original author or authors.
|
||||
* Copyright 2011-2014 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.
|
||||
@@ -26,6 +26,7 @@ import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
|
||||
* Default implementation for {@link BoundZSetOperations}.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
class DefaultBoundZSetOperations<K, V> extends DefaultBoundKeyOperations<K> implements BoundZSetOperations<K, V> {
|
||||
|
||||
@@ -126,8 +127,22 @@ class DefaultBoundZSetOperations<K, V> extends DefaultBoundKeyOperations<K> impl
|
||||
return ops.count(getKey(), min, max);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#size()
|
||||
*/
|
||||
@Override
|
||||
public Long size() {
|
||||
return ops.size(getKey());
|
||||
return zCard();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.BoundZSetOperations#zCard()
|
||||
*/
|
||||
@Override
|
||||
public Long zCard() {
|
||||
return ops.zCard(getKey());
|
||||
}
|
||||
|
||||
public void unionAndStore(K otherKey, K destKey) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2013 the original author or authors.
|
||||
* Copyright 2011-2014 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.
|
||||
@@ -26,6 +26,7 @@ import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
* Default implementation of {@link ZSetOperations}.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZSetOperations<K, V> {
|
||||
|
||||
@@ -325,9 +326,23 @@ class DefaultZSetOperations<K, V> extends AbstractOperations<K, V> implements ZS
|
||||
}, true);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ZSetOperations#size(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Long size(K key) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
return zCard(key);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.redis.core.ZSetOperations#zCard(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Long zCard(K key) {
|
||||
|
||||
final byte[] rawKey = rawKey(key);
|
||||
return execute(new RedisCallback<Long>() {
|
||||
|
||||
public Long doInRedis(RedisConnection connection) {
|
||||
|
||||
@@ -87,7 +87,23 @@ public interface ZSetOperations<K, V> {
|
||||
|
||||
Long count(K key, double min, double max);
|
||||
|
||||
/**
|
||||
* Returns the number of elements of the sorted set stored with given {@code key}.
|
||||
*
|
||||
* @see #zCard(Object)
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
Long size(K key);
|
||||
|
||||
/**
|
||||
* Returns the number of elements of the sorted set stored with given {@code key}.
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
* @since 1.3
|
||||
*/
|
||||
Long zCard(K key);
|
||||
|
||||
RedisOperations<K, V> getOperations();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user