Binary U test on SortedSets ...
This commit is contained in:
@@ -1574,14 +1574,14 @@ public class BinaryJedis implements BinaryJedisCommands {
|
||||
public Set<Tuple> zrangeWithScores(final byte[] key, final int start, final int end) {
|
||||
checkIsInMulti();
|
||||
client.zrangeWithScores(key, start, end);
|
||||
Set<Tuple> set = getTupledSet();
|
||||
Set<Tuple> set = getBinaryTupledSet();
|
||||
return set;
|
||||
}
|
||||
|
||||
public Set<Tuple> zrevrangeWithScores(final byte[] key, final int start, final int end) {
|
||||
checkIsInMulti();
|
||||
client.zrevrangeWithScores(key, start, end);
|
||||
Set<Tuple> set = getTupledSet();
|
||||
Set<Tuple> set = getBinaryTupledSet();
|
||||
return set;
|
||||
}
|
||||
|
||||
@@ -2225,7 +2225,7 @@ public class BinaryJedis implements BinaryJedisCommands {
|
||||
public Set<Tuple> zrangeByScoreWithScores(final byte[] key, final double min, final double max) {
|
||||
checkIsInMulti();
|
||||
client.zrangeByScoreWithScores(key, min, max);
|
||||
Set<Tuple> set = getTupledSet();
|
||||
Set<Tuple> set = getBinaryTupledSet();
|
||||
return set;
|
||||
}
|
||||
|
||||
@@ -2289,19 +2289,22 @@ public class BinaryJedis implements BinaryJedisCommands {
|
||||
final double max, final int offset, final int count) {
|
||||
checkIsInMulti();
|
||||
client.zrangeByScoreWithScores(key, min, max, offset, count);
|
||||
Set<Tuple> set = getTupledSet();
|
||||
Set<Tuple> set = getBinaryTupledSet();
|
||||
return set;
|
||||
}
|
||||
|
||||
private Set<Tuple> getTupledSet() {
|
||||
private Set<Tuple> getBinaryTupledSet() {
|
||||
checkIsInMulti();
|
||||
List<String> membersWithScores = client.getMultiBulkReply();
|
||||
List<byte[]> membersWithScores = client.getBinaryMultiBulkReply();
|
||||
Set<Tuple> set = new LinkedHashSet<Tuple>();
|
||||
Iterator<String> iterator = membersWithScores.iterator();
|
||||
Iterator<byte[]> iterator = membersWithScores.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
set
|
||||
.add(new Tuple(iterator.next(), Double.valueOf(iterator
|
||||
.next())));
|
||||
set.add(
|
||||
new Tuple(
|
||||
iterator.next(),
|
||||
Double.valueOf(new String(iterator.next(), Protocol.UTF8))
|
||||
)
|
||||
);
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Tuple {
|
||||
private String element;
|
||||
private byte[] element;
|
||||
private Double score;
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((element == null) ? 0 : element.hashCode());
|
||||
result = prime * result;
|
||||
if (null != element) {
|
||||
for(final byte b : element) {
|
||||
result = prime * result + b;
|
||||
}
|
||||
}
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(score);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
@@ -27,7 +34,7 @@ public class Tuple {
|
||||
if (element == null) {
|
||||
if (other.element != null)
|
||||
return false;
|
||||
} else if (!element.equals(other.element))
|
||||
} else if (!Arrays.equals(element, other.element))
|
||||
return false;
|
||||
if (Double.doubleToLongBits(score) != Double
|
||||
.doubleToLongBits(other.score))
|
||||
@@ -37,15 +44,33 @@ public class Tuple {
|
||||
|
||||
public Tuple(String element, Double score) {
|
||||
super();
|
||||
this.element = element;
|
||||
this.element = element.getBytes(Protocol.UTF8);
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public Tuple(byte[] element, Double score) {
|
||||
super();
|
||||
this.element = element;
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public String getElement() {
|
||||
return element;
|
||||
if(null != element) {
|
||||
return new String(element, Protocol.UTF8);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getBinaryElement() {
|
||||
return element;
|
||||
}
|
||||
|
||||
public double getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return '['+Arrays.toString(element)+','+score+']';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user