Skip to content
This repository has been archived by the owner on Apr 8, 2023. It is now read-only.

Commit

Permalink
Fixed a bug in redisLIndex, added list tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bwlewis committed Nov 22, 2015
1 parent 5908aaa commit f10ce09
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion R/listCMD.R
Expand Up @@ -41,7 +41,7 @@ redisLTrim <- function(key, start, end)

redisLIndex <- function(key, index, ...)
{
.redisCmd(.raw('LINDEX'), .raw(key), index, ...)
.redisCmd(.raw('LINDEX'), .raw(key), .raw(as.character(index)), ...)
}

redisLSet <- function(key, index, value)
Expand Down
7 changes: 2 additions & 5 deletions R/redis-internal.R
Expand Up @@ -19,10 +19,7 @@
stopifnot(is.numeric(port))
stopifnot(is.logical(nodelay))
con <- envir$con
if(!is.null(con))
{
.closeConnection(con)
}
if(!is.null(con)) tryCatch(.closeConnection(con), error=invisible)
# We track the file descriptor of the new connection in a crude way
# fds <- rownames(showConnections(all=TRUE)) # this doesn't work FYI
fd = NULL
Expand Down Expand Up @@ -168,7 +165,7 @@ redisCmd <- function(CMD, ..., raw=FALSE)
writeBin(.raw(hdr), con)
tryCatch({
for(j in seq_len(n)) {
if(j==1)
if(j == 1)
v <- .renameCommand(eval(f[[j+1]],envir=sys.frame(-1)), rep)
else
v <- eval(f[[j+1]],envir=sys.frame(-1))
Expand Down
22 changes: 22 additions & 0 deletions tests/list.R
@@ -0,0 +1,22 @@
library(rredis)
checkEquals <- function(x, y) if(!isTRUE(all.equal(x, y, check.attributes=FALSE))) stop()

if(Sys.getenv("RunRRedisTests") == "yes")
{
redisConnect()
redisFlushAll()

redisLPush("x", 1)
redisRPush("x", 2)
checkEquals("2", redisLLen("x"))
checkEquals(list(1,2), redisLRange("x", 0, 2))
redisLSet("x", 0, pi)
checkEquals(pi, redisLPop("x"))
redisRPush("x", 2)
redisLTrim("x", 0, 0)
checkEquals("1", redisLLen("x"))
checkEquals(2, redisLIndex("x", 0))


redisFlushAll()
}

0 comments on commit f10ce09

Please sign in to comment.