Support LPOS command via Jedis.
This commit introduces support for the LPOS command when using the Jedis Redis driver. Closes #1957. Original pull request: #1962.
This commit is contained in:
committed by
Mark Paluch
parent
7e7197b087
commit
19eb0930cd
@@ -15,12 +15,13 @@
|
||||
*/
|
||||
package org.springframework.data.redis.connection.jedis;
|
||||
|
||||
import redis.clients.jedis.params.LPosParams;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.redis.connection.ClusterSlotHashUtil;
|
||||
import org.springframework.data.redis.connection.RedisListCommands;
|
||||
import org.springframework.data.redis.connection.jedis.JedisClusterConnection.JedisMultiKeyClusterCommandCallback;
|
||||
@@ -68,7 +69,22 @@ class JedisClusterListCommands implements RedisListCommands {
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(element, "Element must not be null!");
|
||||
|
||||
throw new InvalidDataAccessApiUsageException("LPOS is not supported by jedis.");
|
||||
LPosParams params = new LPosParams();
|
||||
if (rank != null) {
|
||||
params.rank(rank);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
if (count != null) {
|
||||
return connection.getCluster().lpos(key, element, params, count);
|
||||
}
|
||||
|
||||
Long value = connection.getCluster().lpos(key, element, params);
|
||||
return value != null ? Collections.singletonList(value) : Collections.emptyList();
|
||||
} catch (Exception ex) {
|
||||
throw convertJedisAccessException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -19,12 +19,14 @@ import redis.clients.jedis.BinaryJedis;
|
||||
import redis.clients.jedis.MultiKeyPipelineBase;
|
||||
import redis.clients.jedis.Protocol;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.redis.connection.RedisListCommands;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import redis.clients.jedis.params.LPosParams;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
@@ -61,7 +63,16 @@ class JedisListCommands implements RedisListCommands {
|
||||
Assert.notNull(key, "Key must not be null!");
|
||||
Assert.notNull(element, "Element must not be null!");
|
||||
|
||||
throw new InvalidDataAccessApiUsageException("LPOS is not supported by jedis.");
|
||||
LPosParams params = new LPosParams();
|
||||
if(rank != null) {
|
||||
params.rank(rank);
|
||||
}
|
||||
|
||||
if(count != null) {
|
||||
return connection.invoke().just(BinaryJedis::lpos, MultiKeyPipelineBase::lpos, key, element, params, count);
|
||||
}
|
||||
|
||||
return connection.invoke().from(BinaryJedis::lpos, MultiKeyPipelineBase::lpos, key, element, params).get(Collections::singletonList);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user