+ add support for linsert (as left/right push on RedisTemplate)
This commit is contained in:
@@ -35,8 +35,12 @@ public interface BoundListOperations<K, V> extends KeyBound<K> {
|
||||
|
||||
Long leftPush(V value);
|
||||
|
||||
Long leftPush(V pivot, V value);
|
||||
|
||||
Long rightPush(V value);
|
||||
|
||||
Long rightPush(V pivot, V value);
|
||||
|
||||
V leftPop();
|
||||
|
||||
V leftPop(long timeout, TimeUnit unit);
|
||||
@@ -50,5 +54,4 @@ public interface BoundListOperations<K, V> extends KeyBound<K> {
|
||||
V index(long index);
|
||||
|
||||
void set(long index, V value);
|
||||
|
||||
}
|
||||
|
||||
@@ -65,6 +65,11 @@ class DefaultBoundListOperations<K, V> extends DefaultKeyBound<K> implements Bou
|
||||
return ops.leftPush(getKey(), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long leftPush(V pivot, V value) {
|
||||
return ops.leftPush(getKey(), pivot, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long size() {
|
||||
return ops.size(getKey());
|
||||
@@ -96,6 +101,11 @@ class DefaultBoundListOperations<K, V> extends DefaultKeyBound<K> implements Bou
|
||||
return ops.rightPush(getKey(), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long rightPush(V pivot, V value) {
|
||||
return ops.rightPush(getKey(), pivot, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void trim(long start, long end) {
|
||||
ops.trim(getKey(), start, end);
|
||||
|
||||
@@ -33,8 +33,12 @@ public interface ListOperations<K, V> {
|
||||
|
||||
Long leftPush(K key, V value);
|
||||
|
||||
Long leftPush(K key, V pivot, V value);
|
||||
|
||||
Long rightPush(K key, V value);
|
||||
|
||||
Long rightPush(K key, V pivot, V value);
|
||||
|
||||
void set(K key, long index, V value);
|
||||
|
||||
Long remove(K key, long i, Object value);
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.springframework.data.keyvalue.redis.connection.DataType;
|
||||
import org.springframework.data.keyvalue.redis.connection.RedisConnection;
|
||||
import org.springframework.data.keyvalue.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.keyvalue.redis.connection.SortParameters;
|
||||
import org.springframework.data.keyvalue.redis.connection.RedisListCommands.POSITION;
|
||||
import org.springframework.data.keyvalue.redis.serializer.JdkSerializationRedisSerializer;
|
||||
import org.springframework.data.keyvalue.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.keyvalue.redis.serializer.StringRedisSerializer;
|
||||
@@ -927,7 +928,6 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
}, true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Long leftPush(K key, V value) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
@@ -940,6 +940,19 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
}, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long leftPush(K key, V pivot, V value) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
final byte[] rawPivot = rawValue(pivot);
|
||||
final byte[] rawValue = rawValue(value);
|
||||
return execute(new RedisCallback<Long>() {
|
||||
@Override
|
||||
public Long doInRedis(RedisConnection connection) {
|
||||
return connection.lInsert(rawKey, POSITION.BEFORE, rawPivot, rawValue);
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long size(K key) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
@@ -1008,6 +1021,20 @@ public class RedisTemplate<K, V> extends RedisAccessor implements RedisOperation
|
||||
}, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long rightPush(K key, V pivot, V value) {
|
||||
final byte[] rawKey = rawKey(key);
|
||||
final byte[] rawPivot = rawValue(pivot);
|
||||
final byte[] rawValue = rawValue(value);
|
||||
|
||||
return execute(new RedisCallback<Long>() {
|
||||
@Override
|
||||
public Long doInRedis(RedisConnection connection) {
|
||||
return connection.lInsert(rawKey, POSITION.AFTER, rawPivot, rawValue);
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public V rightPopAndLeftPush(K sourceKey, K destinationKey) {
|
||||
final byte[] rawDestKey = rawKey(destinationKey);
|
||||
|
||||
Reference in New Issue
Block a user