Change zadd parameter order to allow duplicated scoremembers but not members
This commit is contained in:
@@ -376,23 +376,22 @@ public class BinaryClient extends Connection {
|
|||||||
public void zadd(final byte[] key, final double score, final byte[] member) {
|
public void zadd(final byte[] key, final double score, final byte[] member) {
|
||||||
sendCommand(ZADD, key, toByteArray(score), member);
|
sendCommand(ZADD, key, toByteArray(score), member);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void zaddBinary(final byte[] key, final Map< byte[], Double> scoreMembers) {
|
||||||
|
|
||||||
|
ArrayList<byte[]> args = new ArrayList<byte[]>(scoreMembers.size() * 2 + 1);
|
||||||
|
args.add(key);
|
||||||
|
|
||||||
public void zaddBinary(final byte[] key, Map<Double, byte[]> scoreMembers) {
|
for (Map.Entry<byte[],Double > entry : scoreMembers.entrySet()) {
|
||||||
ArrayList<byte[]> args = new ArrayList<byte[]>(
|
args.add(toByteArray(entry.getValue()));
|
||||||
scoreMembers.size() * 2 + 1);
|
args.add(entry.getKey());
|
||||||
|
}
|
||||||
|
|
||||||
args.add(key);
|
byte[][] argsArray = new byte[args.size()][];
|
||||||
|
args.toArray(argsArray);
|
||||||
|
|
||||||
for (Map.Entry<Double, byte[]> entry : scoreMembers.entrySet()) {
|
sendCommand(ZADD, argsArray);
|
||||||
args.add(toByteArray(entry.getKey()));
|
}
|
||||||
args.add(entry.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[][] argsArray = new byte[args.size()][];
|
|
||||||
args.toArray(argsArray);
|
|
||||||
|
|
||||||
sendCommand(ZADD, argsArray);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void zrange(final byte[] key, final long start, final long end) {
|
public void zrange(final byte[] key, final long start, final long end) {
|
||||||
sendCommand(ZRANGE, key, toByteArray(start), toByteArray(end));
|
sendCommand(ZRANGE, key, toByteArray(start), toByteArray(end));
|
||||||
|
|||||||
@@ -1502,7 +1502,7 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands, MultiKey
|
|||||||
return client.getIntegerReply();
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long zadd(final byte[] key, final Map<Double, byte[]> scoreMembers) {
|
public Long zadd(final byte[] key, final Map<byte[], Double> scoreMembers) {
|
||||||
checkIsInMulti();
|
checkIsInMulti();
|
||||||
client.zaddBinary(key, scoreMembers);
|
client.zaddBinary(key, scoreMembers);
|
||||||
return client.getIntegerReply();
|
return client.getIntegerReply();
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common interface for sharded and non-sharded BinaryJedis
|
* Common interface for sharded and non-sharded BinaryJedis
|
||||||
*/
|
*/
|
||||||
@@ -114,8 +116,8 @@ public interface BinaryJedisCommands {
|
|||||||
Long strlen(byte[] key);
|
Long strlen(byte[] key);
|
||||||
|
|
||||||
Long zadd(byte[] key, double score, byte[] member);
|
Long zadd(byte[] key, double score, byte[] member);
|
||||||
|
|
||||||
Long zadd(byte[] key, Map<Double, byte[]> scoreMembers);
|
Long zadd(byte[] key, Map<byte[], Double> scoreMembers);
|
||||||
|
|
||||||
Set<byte[]> zrange(byte[] key, long start, long end);
|
Set<byte[]> zrange(byte[] key, long start, long end);
|
||||||
|
|
||||||
@@ -157,45 +159,45 @@ public interface BinaryJedisCommands {
|
|||||||
Set<byte[]> zrevrangeByScore(byte[] key, byte[] max, byte[] min);
|
Set<byte[]> zrevrangeByScore(byte[] key, byte[] max, byte[] min);
|
||||||
|
|
||||||
Set<byte[]> zrangeByScore(byte[] key, byte[] min, byte[] max, int offset,
|
Set<byte[]> zrangeByScore(byte[] key, byte[] min, byte[] max, int offset,
|
||||||
int count);
|
int count);
|
||||||
|
|
||||||
Set<byte[]> zrevrangeByScore(byte[] key, double max, double min,
|
Set<byte[]> zrevrangeByScore(byte[] key, double max, double min,
|
||||||
int offset, int count);
|
int offset, int count);
|
||||||
|
|
||||||
Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max);
|
Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max);
|
||||||
|
|
||||||
Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min);
|
Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min);
|
||||||
|
|
||||||
Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max,
|
Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max,
|
||||||
int offset, int count);
|
int offset, int count);
|
||||||
|
|
||||||
Set<byte[]> zrevrangeByScore(byte[] key, byte[] max, byte[] min,
|
Set<byte[]> zrevrangeByScore(byte[] key, byte[] max, byte[] min,
|
||||||
int offset, int count);
|
int offset, int count);
|
||||||
|
|
||||||
Set<Tuple> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max);
|
Set<Tuple> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max);
|
||||||
|
|
||||||
Set<Tuple> zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min);
|
Set<Tuple> zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min);
|
||||||
|
|
||||||
Set<Tuple> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max,
|
Set<Tuple> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max,
|
||||||
int offset, int count);
|
int offset, int count);
|
||||||
|
|
||||||
Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min,
|
Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min,
|
||||||
int offset, int count);
|
int offset, int count);
|
||||||
|
|
||||||
Set<Tuple> zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min,
|
Set<Tuple> zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min,
|
||||||
int offset, int count);
|
int offset, int count);
|
||||||
|
|
||||||
Long zremrangeByRank(byte[] key, long start, long end);
|
Long zremrangeByRank(byte[] key, long start, long end);
|
||||||
|
|
||||||
Long zremrangeByScore(byte[] key, double start, double end);
|
Long zremrangeByScore(byte[] key, double start, double end);
|
||||||
|
|
||||||
Long zremrangeByScore(byte[] key, byte[] start, byte[] end);
|
Long zremrangeByScore(byte[] key, byte[] start, byte[] end);
|
||||||
|
|
||||||
Long linsert(byte[] key, Client.LIST_POSITION where, byte[] pivot,
|
Long linsert(byte[] key, Client.LIST_POSITION where, byte[] pivot,
|
||||||
byte[] value);
|
byte[] value);
|
||||||
|
|
||||||
Long lpushx(byte[] key, byte[]... arg);
|
Long lpushx(byte[] key, byte[]... arg);
|
||||||
|
|
||||||
Long rpushx(byte[] key, byte[]... arg);
|
Long rpushx(byte[] key, byte[]... arg);
|
||||||
|
|
||||||
List<byte[]> blpop(byte[] arg);
|
List<byte[]> blpop(byte[] arg);
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ public class BinaryShardedJedis extends Sharded<Jedis, JedisShardInfo>
|
|||||||
return j.zadd(key, score, member);
|
return j.zadd(key, score, member);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long zadd(byte[] key, Map<Double, byte[]> scoreMembers) {
|
public Long zadd(byte[] key, Map<byte[], Double> scoreMembers) {
|
||||||
Jedis j = getShard(key);
|
Jedis j = getShard(key);
|
||||||
return j.zadd(key, scoreMembers);
|
return j.zadd(key, scoreMembers);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -709,17 +709,19 @@ public class Client extends BinaryClient implements Commands {
|
|||||||
public void scriptLoad(String script) {
|
public void scriptLoad(String script) {
|
||||||
scriptLoad(SafeEncoder.encode(script));
|
scriptLoad(SafeEncoder.encode(script));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void zadd(String key, Map<String, Double> scoreMembers) {
|
||||||
|
|
||||||
|
HashMap<byte[], Double> binaryScoreMembers = new HashMap<byte[], Double>();
|
||||||
|
|
||||||
public void zadd(String key, Map<Double, String> scoreMembers) {
|
for (Map.Entry<String, Double> entry : scoreMembers.entrySet()) {
|
||||||
HashMap<Double, byte[]> binaryScoreMembers = new HashMap<Double, byte[]>();
|
|
||||||
|
binaryScoreMembers.put(SafeEncoder.encode(entry.getKey()), entry.getValue());
|
||||||
for (Map.Entry<Double, String> entry : scoreMembers.entrySet()) {
|
}
|
||||||
binaryScoreMembers.put(entry.getKey(),
|
|
||||||
SafeEncoder.encode(entry.getValue()));
|
zaddBinary(SafeEncoder.encode(key), binaryScoreMembers);
|
||||||
}
|
}
|
||||||
|
|
||||||
zaddBinary(SafeEncoder.encode(key), binaryScoreMembers);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void objectRefcount(String key) {
|
public void objectRefcount(String key) {
|
||||||
objectRefcount(SafeEncoder.encode(key));
|
objectRefcount(SafeEncoder.encode(key));
|
||||||
|
|||||||
@@ -143,8 +143,8 @@ public interface Commands {
|
|||||||
public void srandmember(final String key);
|
public void srandmember(final String key);
|
||||||
|
|
||||||
public void zadd(final String key, final double score, final String member);
|
public void zadd(final String key, final double score, final String member);
|
||||||
|
|
||||||
public void zadd(final String key, final Map<Double, String> scoreMembers);
|
public void zadd(final String key, final Map<String, Double > scoreMembers);
|
||||||
|
|
||||||
public void zrange(final String key, final long start, final long end);
|
public void zrange(final String key, final long start, final long end);
|
||||||
|
|
||||||
|
|||||||
@@ -1415,10 +1415,10 @@ public class Jedis extends BinaryJedis implements JedisCommands, MultiKeyCommand
|
|||||||
return client.getIntegerReply();
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long zadd(final String key, final Map<Double, String> scoreMembers) {
|
public Long zadd(final String key, final Map<String, Double> scoreMembers) {
|
||||||
checkIsInMulti();
|
checkIsInMulti();
|
||||||
client.zadd(key, scoreMembers);
|
client.zadd(key, scoreMembers);
|
||||||
return client.getIntegerReply();
|
return client.getIntegerReply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> zrange(final String key, final long start, final long end) {
|
public Set<String> zrange(final String key, final long start, final long end) {
|
||||||
|
|||||||
@@ -635,7 +635,7 @@ public class JedisCluster implements JedisCommands, BasicCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long zadd(final String key, final Map<Double, String> scoreMembers) {
|
public Long zadd(final String key, final Map<String, Double> scoreMembers) {
|
||||||
return new JedisClusterCommand<Long>(connectionHandler, timeout,
|
return new JedisClusterCommand<Long>(connectionHandler, timeout,
|
||||||
maxRedirections) {
|
maxRedirections) {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ public interface
|
|||||||
|
|
||||||
Long zadd(String key, double score, String member);
|
Long zadd(String key, double score, String member);
|
||||||
|
|
||||||
Long zadd(String key, Map<Double, String> scoreMembers);
|
Long zadd(String key, Map<String, Double > scoreMembers);
|
||||||
|
|
||||||
Set<String> zrange(String key, long start, long end);
|
Set<String> zrange(String key, long start, long end);
|
||||||
|
|
||||||
|
|||||||
@@ -654,7 +654,7 @@ abstract class PipelineBase extends Queable implements
|
|||||||
return getResponse(BuilderFactory.LONG);
|
return getResponse(BuilderFactory.LONG);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response<Long> zadd(String key, Map<Double, String> scoreMembers) {
|
public Response<Long> zadd(String key, Map<String, Double> scoreMembers) {
|
||||||
getClient(key).zadd(key, scoreMembers);
|
getClient(key).zadd(key, scoreMembers);
|
||||||
return getResponse(BuilderFactory.LONG);
|
return getResponse(BuilderFactory.LONG);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -326,10 +326,10 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
|
|||||||
Jedis j = getShard(key);
|
Jedis j = getShard(key);
|
||||||
return j.zadd(key, score, member);
|
return j.zadd(key, score, member);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long zadd(String key, Map<Double, String> scoreMembers) {
|
public Long zadd(String key, Map<String, Double> scoreMembers) {
|
||||||
Jedis j = getShard(key);
|
Jedis j = getShard(key);
|
||||||
return j.zadd(key, scoreMembers);
|
return j.zadd(key, scoreMembers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> zrange(String key, long start, long end) {
|
public Set<String> zrange(String key, long start, long end) {
|
||||||
|
|||||||
@@ -117,30 +117,30 @@ public class VariadicCommandsTest extends JedisCommandTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void zadd() {
|
public void zadd() {
|
||||||
Map<Double, String> scoreMembers = new HashMap<Double, String>();
|
Map<String, Double> scoreMembers = new HashMap<String, Double>();
|
||||||
scoreMembers.put(1d, "bar");
|
scoreMembers.put("bar", 1d);
|
||||||
scoreMembers.put(10d, "foo");
|
scoreMembers.put("foo", 10d);
|
||||||
|
|
||||||
long status = jedis.zadd("foo", scoreMembers);
|
long status = jedis.zadd("foo", scoreMembers);
|
||||||
assertEquals(2, status);
|
assertEquals(2, status);
|
||||||
|
|
||||||
scoreMembers.clear();
|
scoreMembers.clear();
|
||||||
scoreMembers.put(0.1d, "car");
|
scoreMembers.put("car", 0.1d);
|
||||||
scoreMembers.put(2d, "bar");
|
scoreMembers.put("bar", 2d);
|
||||||
|
|
||||||
status = jedis.zadd("foo", scoreMembers);
|
status = jedis.zadd("foo", scoreMembers);
|
||||||
assertEquals(1, status);
|
assertEquals(1, status);
|
||||||
|
|
||||||
Map<Double, byte[]> bscoreMembers = new HashMap<Double, byte[]>();
|
Map<byte[], Double> bscoreMembers = new HashMap<byte[], Double>();
|
||||||
bscoreMembers.put(1d, bbar);
|
bscoreMembers.put(bbar, 1d);
|
||||||
bscoreMembers.put(10d, bfoo);
|
bscoreMembers.put(bfoo, 10d);
|
||||||
|
|
||||||
status = jedis.zadd(bfoo, bscoreMembers);
|
status = jedis.zadd(bfoo, bscoreMembers);
|
||||||
assertEquals(2, status);
|
assertEquals(2, status);
|
||||||
|
|
||||||
bscoreMembers.clear();
|
bscoreMembers.clear();
|
||||||
bscoreMembers.put(0.1d, bcar);
|
bscoreMembers.put(bcar, 0.1d);
|
||||||
bscoreMembers.put(2d, bbar);
|
bscoreMembers.put(bbar, 2d);
|
||||||
|
|
||||||
status = jedis.zadd(bfoo, bscoreMembers);
|
status = jedis.zadd(bfoo, bscoreMembers);
|
||||||
assertEquals(1, status);
|
assertEquals(1, status);
|
||||||
|
|||||||
Reference in New Issue
Block a user