+ add putIfAbsent on Hash operations
This commit is contained in:
@@ -36,6 +36,8 @@ public interface BoundHashOperations<H, HK, HV> extends KeyBound<H> {
|
||||
|
||||
void put(HK key, HV value);
|
||||
|
||||
Boolean putIfAbsent(HK key, HV value);
|
||||
|
||||
Collection<HV> multiGet(Collection<HK> keys);
|
||||
|
||||
void putAll(Map<? extends HK, ? extends HV> m);
|
||||
|
||||
@@ -89,6 +89,11 @@ class DefaultBoundHashOperations<H, HK, HV> extends DefaultKeyBound<H> implement
|
||||
ops.put(getKey(), key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean putIfAbsent(HK key, HV value) {
|
||||
return ops.putIfAbsent(getKey(), key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<HV> values() {
|
||||
return ops.values(getKey());
|
||||
|
||||
@@ -44,6 +44,8 @@ public interface HashOperations<H, HK, HV> {
|
||||
|
||||
void put(H key, HK hashKey, HV value);
|
||||
|
||||
Boolean putIfAbsent(H key, HK hashKey, HV value);
|
||||
|
||||
Collection<HV> values(H key);
|
||||
|
||||
Map<HK, HV> entries(H key);
|
||||
|
||||
@@ -1606,6 +1606,21 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
}, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean putIfAbsent(K key, HK hashKey, HV value) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
final byte[] rawHashKey = rawHashKey(hashKey);
|
||||
final byte[] rawHashValue = rawHashValue(value);
|
||||
|
||||
return execute(new RedisCallback<Boolean>() {
|
||||
@Override
|
||||
public Boolean doInRedis(RedisConnection connection) {
|
||||
return connection.hSetNX(rawKey, rawHashKey, rawHashValue);
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<HV> values(K key) {
|
||||
|
||||
Reference in New Issue
Block a user