From f9bf94c40894368360201eceb0742b51bd817c70 Mon Sep 17 00:00:00 2001 From: Bill Evans Date: Wed, 18 Nov 2020 09:59:23 -0500 Subject: [PATCH] add zpopmax/min and blocking variants --- NEWS.md | 4 +++ R/redis_api_generated.R | 21 ++++++++++++ tests/testthat/test-zzz-commands-sorted-set.R | 32 +++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/NEWS.md b/NEWS.md index faece56..f41c5ee 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +## redux WIP + +* Adds `ZPOPMAX`, `ZPOPMIN`, and the blocking variants (`BZ*`) + ## redux 1.1.1 * More relaxed, though technically incorrect, URL parsing that allows undercores in the host name - useful for docker containers (#20). diff --git a/R/redis_api_generated.R b/R/redis_api_generated.R index 2b9af72..508b11c 100644 --- a/R/redis_api_generated.R +++ b/R/redis_api_generated.R @@ -55,6 +55,15 @@ redis_commands <- function(command) { assert_scalar2(timeout) command(list("BRPOPLPUSH", source, destination, timeout)) }, + BZPOPMIN = function(key, timeout) { + assert_scalar2(timeout) + command(list("BZPOPMIN", key, timeout)) + }, + BZPOPMAX = function(key, timeout) { + assert_scalar2(key) + assert_scalar2(timeout) + command(list("BZPOPMAX", key, timeout)) + }, CLIENT_KILL = function(ip_port = NULL, ID = NULL, TYPE = NULL, ADDR = NULL, SKIPME = NULL) { assert_scalar_or_null2(ip_port) assert_scalar_or_null2(ID) @@ -810,6 +819,14 @@ redis_commands <- function(command) { assert_scalar2(max) command(list("ZLEXCOUNT", key, min, max)) }, + ZPOPMIN = function(key) { + assert_scalar2(key) + command(list("ZPOPMIN", key)) + }, + ZPOPMAX = function(key) { + assert_scalar2(key) + command(list("ZPOPMAX", key)) + }, ZRANGE = function(key, start, stop, withscores = NULL) { assert_scalar2(key) assert_scalar2(start) @@ -937,6 +954,8 @@ cmd_since <- numeric_version(c( BLPOP = "2.0.0", BRPOP = "2.0.0", BRPOPLPUSH = "2.2.0", + BZPOPMAX = "5.0.0", + BZPOPMIN = "5.0.0", CLIENT_GETNAME = "2.6.9", CLIENT_KILL = "2.4.0", CLIENT_LIST = "2.4.0", @@ -1110,6 +1129,8 @@ cmd_since <- numeric_version(c( ZINCRBY = "1.2.0", ZINTERSTORE = "2.0.0", ZLEXCOUNT = "2.8.9", + ZPOPMAX = "5.0.0", + ZPOPMIN = "5.0.0", ZRANGE = "1.2.0", ZRANGEBYLEX = "2.8.9", ZRANGEBYSCORE = "1.0.5", diff --git a/tests/testthat/test-zzz-commands-sorted-set.R b/tests/testthat/test-zzz-commands-sorted-set.R index 49cf79a..ce05c7e 100644 --- a/tests/testthat/test-zzz-commands-sorted-set.R +++ b/tests/testthat/test-zzz-commands-sorted-set.R @@ -16,6 +16,23 @@ test_that("ZADD", { "two", "2", "three", "3")) }) +test_that("BZPOPMAX/MIN", { + skip_if_cmd_unsupported("BZPOPMAX") + skip_if_cmd_unsupported("BZPOPMIN") + con <- test_hiredis_connection() + key <- rand_str() + on.exit(con$DEL(key)) + + expect_equal(con$ZADD(key, 0:2, c("a", "b", "c")), 3) + expect_equal(con$BZPOPMAX(key, 0), list(key, "c", "2")) + expect_equal(con$BZPOPMIN(key, 0), list(key, "a", "0")) + expect_equal(con$BZPOPMAX(key, 0), list(key, "b", "1")) + + st <- system.time(res <- con$BZPOPMAX(key, 1)) + expect_null(res) + expect_true(abs(st["elapsed"] - 1) < 1) # crude +}) + test_that("ZCARD", { skip_if_cmd_unsupported("ZCARD") con <- test_hiredis_connection() @@ -104,6 +121,21 @@ test_that("ZLEXCOUNT", { expect_equal(con$ZLEXCOUNT(key, "[b", "[f"), 5L) }) +test_that("ZPOPMAX/MIN", { + skip_if_cmd_unsupported("ZPOPMAX") + skip_if_cmd_unsupported("ZPOPMIN") + con <- test_hiredis_connection() + key <- rand_str() + on.exit(con$DEL(key)) + + expect_equal(con$ZADD(key, 1:3, c("one", "two", "three")), 3) + expect_equal(con$ZPOPMAX(key), list("three", "3")) + expect_equal(con$ZPOPMIN(key), list("one", "1")) + expect_equal(con$ZPOPMAX(key), list("two", "2")) + expect_equal(con$ZPOPMAX(key), list()) + expect_equal(con$ZPOPMIN(key), list()) +}) + test_that("ZRANGE", { skip_if_cmd_unsupported("ZRANGE") con <- test_hiredis_connection()