Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Significantly improved redisGet performance for large objects; improv…

…ed code inspired by the Rbig/networkspaces server of Steve Weston and Pat Shields
  • Loading branch information...
commit fb812f348139d78f72d5a74a1c48256f4a8e4047 1 parent 195afdd
B. W. Lewis authored
View
2  DESCRIPTION
@@ -1,7 +1,7 @@
Package: rredis
Type: Package
Title: Redis client for R
-Version: 1.0
+Version: 1.1
Date: 2010-01-26
Author: B. W. Lewis
Maintainer: B. W. Lewis <blewis@illposed.net>
View
27 R/redis-internal.R
@@ -64,17 +64,34 @@
dat <- tryCatch(readBin(con, 'raw', n=n),
error=function(e) .redisError(e$message))
m <- length(dat)
+ if(m>=n) return(tryCatch(unserialize(dat),
+ error=function(e) rawToChar(dat)))
+# The message was not fully recieved in one pass.
+# We allocate a list to hold incremental messages and then concatenate it.
+# This perfromance enhancement was adapted from the Rbig server package,
+# written by Steve Weston and Pat Shields.
+ rlen <- 50
+ j <- 1
+ r <- vector('list',rlen)
+ r[j] <- list(dat)
while(m<n) {
# Short read; we need to retrieve the rest of this message.
socketSelect(list(con))
- dat <- c(dat, tryCatch(readBin(con, 'raw', n=(n-m)),
- error=function (e) .redisError(e$message)))
- m <- length(dat)
+ dat <- tryCatch(readBin(con, 'raw', n=(n-m)),
+ error=function (e) .redisError(e$message))
+ j <- j + 1
+ if(j>rlen) {
+ rlen <- 2*rlen
+ length(r) <- rlen
+ }
+ r[j] <- list(dat)
+ m <- m + length(dat)
}
l <- readLines(con,n=1) # Trailing \r\n
+ length(r) <- j
# Try retrieving an R object, otherwise default to character:
- tryCatch(unserialize(dat),
- error=function(e) rawToChar(dat))
+ tryCatch(unserialize(do.call(c,r)),
+ error=function(e) rawToChar(do.call(c,r)))
},
'*' = {
vals <- NULL
View
BIN  inst/doc/rredis.pdf
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.