Skip to content

Commit 1340fcc

Browse files
committed
Add DEL (closes #56)
1 parent 6e40a04 commit 1340fcc

File tree

8 files changed

+35
-15
lines changed

8 files changed

+35
-15
lines changed

ChangeLog

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2025-03-27 Dirk Eddelbuettel <[email protected]>
2+
3+
* DESCRIPTION (Version, Date): Roll micro version and date
4+
5+
* src/Redis.cpp: Add proper DEL, LREM, LMOVE commands
6+
* inst/tinytest/test_basics.R: Adjust tests
7+
* inst/tinytest/test_exec.R: Idem
8+
* inst/tinytest/test_exists.R: Idem
9+
* inst/tinytest/test_expire.R: Idem
10+
* inst/tinytest/test_list.R: Idem
11+
* inst/tinytest/test_set.R: Idem
12+
113
2025-03-26 Dirk Eddelbuettel <[email protected]>
214

315
* DESCRIPTION (Version, Date): Release 0.2.5

inst/tinytest/test_basics.R

+1-2
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,4 @@ res <- redis$ping()
5656
expect_equal(res, "PONG")
5757

5858
#test_06_cleanup <- function() {
59-
expect_equal(redis$exec("del RcppRedis:test:foo"), 1)
60-
expect_equal(redis$exec("del RcppRedis:test:foo2"), 1)
59+
expect_equal(redis$del(c("RcppRedis:test:foo","RcppRedis:test:foo2")), 2)

inst/tinytest/test_exec.R

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ expect_error(redis$exec("LRANGE mylist 0 elephant"))
1919

2020
#test_04_cleanup <- function() {
2121
## delete set
22-
n <- redis$exec(paste("del", key))
23-
expect_equal(n, 1)
22+
expect_equal(redis$del(key), 1)

inst/tinytest/test_exists.R

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,4 @@ expect_equal(n, 0)
1717

1818
#test_03_cleanup <- function() {
1919
## delete key
20-
n <- redis$exec(paste("del", key))
21-
expect_equal(n, 1)
20+
expect_equal(redis$del(key), 1)

inst/tinytest/test_expire.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ expect_equal(n, 0)
3636

3737
#test_03_cleanup <- function() {
3838
## delete key
39-
redis$exec(paste("del", key))
39+
expect_equal(redis$del(key), 0)
4040
expect_equal(redis$exists(key), 0)

inst/tinytest/test_list.R

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ redis <- new(Redis)
55
exampleNumericElement <- 1.0
66
exampleCharElement <- "a"
77
key <- "RcppRedis:test:mylist"
8-
redis$exec(paste("del", key))
8+
expect_equal(redis$del(key), 0)
99

1010

1111
#test_02_lpush <- function() {
@@ -60,17 +60,16 @@ redis$lpush(key, 3)
6060
redis$ltrim(key, 0, 1)
6161
res <- redis$lrange(key, 0, 100)
6262
expect_equal(res,list(3,2))
63-
redis$exec(paste("del", key))
63+
expect_equal(redis$del(key), 1)
6464

6565

6666
#test_09_cleanup <- function() {
6767
## delete key
68-
n <- redis$exec(paste("del", key))
69-
expect_equal(n, 0)
68+
expect_equal(redis$del(key), 0)
7069

7170

7271
## check lrem
73-
redis$exec(paste("del", key))
72+
redis$del(key)
7473
elem <- "abc"
7574
redis$lpush(key, elem)
7675
redis$lpush(key, elem)
@@ -87,7 +86,7 @@ expect_equal(redis$keys(key), character())
8786

8887
## check lmove
8988
altkey <- "RcppRedis:test:myotherlist"
90-
redis$exec(paste("del", altkey))
89+
redis$del(altkey)
9190
redis$rpush(key, 1)
9291
redis$rpush(key, 2)
9392
redis$rpush(key, 3)

inst/tinytest/test_set.R

+1-2
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,4 @@ expect_identical(y, mem[[1]])
5454

5555
#test_09_cleanup <- function() {
5656
## delete set
57-
n <- redis$exec(paste("del", key))
58-
expect_equal(n, 1)
57+
expect_equal(redis$del(key), 1)

src/Redis.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,18 @@ class Redis {
243243
return(exec("EXPIRE " + key + " " + ms));
244244
}
245245

246+
// redis DEL key1 [key2 key3 ...]
247+
SEXP del(std::vector<std::string> sv) {
248+
std::string cmd = "DEL";
249+
for (auto s: sv) {
250+
cmd += " " + s;
251+
}
252+
redisReply *reply = static_cast<redisReply*>(redisCommandNULLSafe(prc_, cmd.c_str()));
253+
SEXP rep = extract_reply(reply);
254+
freeReplyObject(reply);
255+
return(rep);
256+
}
257+
246258
// redis set -- serializes to R internal format
247259
std::string set(std::string key, SEXP s) {
248260

@@ -981,6 +993,7 @@ RCPP_MODULE(Redis) {
981993
.method("exists", &Redis::exists, "runs 'EXISTS' command to count the number of specified keys present")
982994
.method("expire", &Redis::expire, "runs 'EXPIRE' command to expire the key after a given number of seconds")
983995
.method("pexpire", &Redis::pexpire, "runs 'PEXPIRE' command to expire the key after a given number of milliseconds")
996+
.method("del", &Redis::del, "runs 'DEL key1 [key2 key3 ...]' removing a key")
984997
.method("set", &Redis::set, "runs 'SET key object', serializes internally")
985998
.method("get", &Redis::get, "runs 'GET key', deserializes internally")
986999

0 commit comments

Comments
 (0)