Skip to content

Commit

Permalink
GEODE-9379: Implement ZREVRANGEBYSCORE (apache#6715)
Browse files Browse the repository at this point in the history
Adds support for ZREVRANGEBYSCORE. Also refactors some RedisSortedSet code to extract helper methods for other range commands.
  • Loading branch information
ringles authored Aug 12, 2021
1 parent 88860d0 commit 8d455b4
Show file tree
Hide file tree
Showing 20 changed files with 792 additions and 569 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package org.apache.geode.redis.internal.executor.sortedset;

import org.junit.ClassRule;

import org.apache.geode.redis.NativeRedisClusterTestRule;

public class ZRevRangeByScoreNativeRedisAcceptanceTest
extends AbstractZRevRangeByScoreIntegrationTest {

@ClassRule
public static NativeRedisClusterTestRule server = new NativeRedisClusterTestRule();

@Override
public int getPort() {
return server.getExposedPorts().get(0);
}

@Override
public void flushAll() {
server.flushAll();
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ public void testZscore() {
runCommandAndAssertHitsAndMisses(SORTED_SET_KEY, (k, v) -> jedis.zscore(k, v));
}

@Test
public void testZrevrangeByScore() {
runCommandAndAssertHitsAndMisses(SORTED_SET_KEY, k -> jedis.zrevrangeByScore(k, 1, 0));
}

/************* Set related commands *************/
@Test
public void testSadd() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,21 @@ public void shouldError_givenInvalidMinOrMax() {
.hasMessageContaining(ERROR_MIN_MAX_NOT_A_FLOAT);
assertThatThrownBy(() -> jedis.zrangeByScore("fakeKey", "(a", "(b"))
.hasMessageContaining(ERROR_MIN_MAX_NOT_A_FLOAT);
assertThatThrownBy(() -> jedis.zrangeByScore("fakeKey", "str", "1"))
.hasMessageContaining(ERROR_MIN_MAX_NOT_A_FLOAT);
assertThatThrownBy(() -> jedis.zrangeByScore("fakeKey", "1", "str"))
.hasMessageContaining(ERROR_MIN_MAX_NOT_A_FLOAT);
assertThatThrownBy(() -> jedis.zrangeByScore("fakeKey", "1", "NaN"))
.hasMessageContaining(ERROR_MIN_MAX_NOT_A_FLOAT);
}

@Test
public void shouldReturnZero_givenNonExistentKey() {
public void shouldReturnEmptyList_givenNonExistentKey() {
assertThat(jedis.zrangeByScore("fakeKey", "-inf", "inf")).isEmpty();
}

@Test
public void shouldReturnZero_givenMinGreaterThanMax() {
public void shouldReturnEmptyList_givenMinGreaterThanMax() {
jedis.zadd(KEY, 1, "member");

// Range +inf <= score <= -inf
Expand Down Expand Up @@ -200,7 +206,6 @@ public void shouldReturnRange_givenExclusiveMinAndMax() {
assertThat(jedis.zrangeByScore(KEY, "(-inf", "(+inf")).containsExactly("member2");
}


private Map<String, Double> getExclusiveTestMap() {
Map<String, Double> map = new HashMap<>();

Expand All @@ -211,7 +216,7 @@ private Map<String, Double> getExclusiveTestMap() {
}

@Test
public void shouldReturnZero_givenExclusiveMinAndMaxEqualToScore() {
public void shouldReturnEmptyList_givenExclusiveMinAndMaxEqualToScore() {
double score = 1;
jedis.zadd(KEY, score, "member");

Expand Down
Loading

0 comments on commit 8d455b4

Please sign in to comment.