Permalink
Browse files

Added required Makevars.win file; modified most commands that return …

…values to use the new ... raw=TRUE/FALSE scheme. This still needs doc and unit tests
  • Loading branch information...
1 parent 9830f52 commit def26f141376a9c67cb95053a3d1100c1e026ea4 @bwlewis committed Sep 10, 2013
Showing with 154 additions and 112 deletions.
  1. +4 −4 R/bitops.R
  2. +17 −19 R/hashCMD.R
  3. +36 −22 R/listCMD.R
  4. +7 −7 R/redis-internal.R
  5. +46 −18 R/setVal.R
  6. +23 −22 R/strValCMD.R
  7. +20 −20 R/zsetVal.R
  8. +1 −0 src/Makevars.win
View
@@ -17,9 +17,9 @@ redisSetBit <- function(key, offset, bit)
#' @param offset integer index
#' @return bit binary integer
#' @detail Official redis documentation: http://redis.io/commands/getbit
-redisGetBit <- function(key, offset)
+redisGetBit <- function(key, offset,...)
{
- .redisCmd(.raw('GETBIT'), .raw(key), .raw(as.character(offset)))
+ .redisCmd(.raw('GETBIT'), .raw(key), .raw(as.character(offset)),...)
}
@@ -41,8 +41,8 @@ redisBitCount <- function(key)
#' @param sourcekeys one or more source keys subject to the bit operations
#' @return the counted bits as an integer value
#' @detail Official redis documentation: http://redis.io/commands/bitop
-redisBitOp <- function(operation, destkey, sourcekeys)
+redisBitOp <- function(operation, destkey, sourcekeys,...)
{
sets <- c(as.list(sourcekeys))
- do.call('.redisCmd',lapply(c(list('BITOP'),operation, destkey, sets),charToRaw))
+ do.call('.redisCmd',c(lapply(c(list('BITOP'),operation, destkey, sets),charToRaw),...))
}
View
@@ -1,23 +1,21 @@
# This file contains functions that operate on Redis 'hash' values.
-redisHGet <- function(key, field, raw=FALSE) {
- if(raw){
- .redisRawCmd(.raw('HGET'), .raw(key), .raw(field))
- }else{
- .redisCmd(.raw('HGET'), .raw(key), .raw(field))
- }
+redisHGet <- function(key, field, ...)
+{
+ .redisCmd(.raw('HGET'), .raw(key), .raw(field),...)
}
-redisHSet <- function(key, field, value, NX=FALSE) {
+redisHSet <- function(key, field, value, NX=FALSE)
+{
value <- .cerealize(value)
cmd <- 'HSET'
if(NX) cmd <- 'HSETNX'
.redisCmd(.raw(cmd), .raw(key), .raw(field), value)
}
-redisHIncrBy <- function(key, field, value)
+redisHIncrBy <- function(key, field, value, ...)
{
- .redisCmd(.raw('HINCRBY'),.raw(key),.raw(field),.raw(as.character(value)))
+ .redisCmd(.raw('HINCRBY'),.raw(key),.raw(field),.raw(as.character(value)),...)
}
redisHExists <- function(key, field)
@@ -35,34 +33,34 @@ redisHLen <- function(key)
.redisCmd(.raw('HLEN'), .raw(key))
}
-redisHFields <- function(key)
+redisHFields <- function(key,...)
{
- .redisCmd(.raw('HKEYS'), .raw(key))
+ .redisCmd(.raw('HKEYS'), .raw(key),...)
}
-redisHKeys <- function(key)
+redisHKeys <- function(key,...)
{
- redisHFields(key)
+ redisHFields(key,...)
}
-redisHVals <- function(key)
+redisHVals <- function(key,...)
{
- .redisCmd(.raw('HVALS'), .raw(key))
+ .redisCmd(.raw('HVALS'), .raw(key),...)
}
-redisHGetAll <- function(key)
+redisHGetAll <- function(key,...)
{
retval <- NULL
- all <- .redisCmd(.raw('HGETALL'), .raw(key))
+ all <- .redisCmd(.raw('HGETALL'), .raw(key),...)
if(!is.null(all) && length(all)>1) {
retval <- all[seq(2,length(all),by=2)]
names(retval) <- all[seq(1,length(all),by=2)]
}
retval
}
-redisHMGet <- function(key, fields) {
- a <- c(alist(),list(.raw('HMGET')))
+redisHMGet <- function(key, fields, ...) {
+ a <- c(alist(),list(.raw('HMGET')),...)
a <- c(a, lapply(c(key,fields), charToRaw))
retval <- do.call('.redisCmd', a)
if(length(retval) == length(fields)) names(retval) <- fields
View
@@ -1,59 +1,71 @@
# This file contains functions that operate on Redis lists.
-redisRPush <- function(key, value) {
+redisRPush <- function(key, value)
+{
.redisCmd(.raw('RPUSH'), .raw(key),value)
}
-redisLPush <- function(key, value) {
+redisLPush <- function(key, value)
+{
.redisCmd(.raw('LPUSH'), .raw(key),value)
}
-redisRPop <- function(key) {
- .redisCmd(.raw('RPOP'), .raw(key))
+redisRPop <- function(key,...)
+{
+ .redisCmd(.raw('RPOP'), .raw(key),...)
}
-redisLPop <- function(key) {
- .redisCmd(.raw('LPOP'), .raw(key))
+redisLPop <- function(key,...)
+{
+ .redisCmd(.raw('LPOP'), .raw(key),...)
}
-redisLLen <- function(key) {
+redisLLen <- function(key)
+{
.redisCmd(.raw('LLEN'), .raw(key))
}
-redisLRange <- function(key, start, end) {
+redisLRange <- function(key, start, end, ...)
+{
start <- charToRaw(as.character(start))
end <- charToRaw(as.character(end))
- .redisCmd(.raw('LRANGE'), .raw(key), start, end)
+ .redisCmd(.raw('LRANGE'), .raw(key), start, end, ...)
}
-redisLTrim <- function(key,start,end) {
+redisLTrim <- function(key,start,end)
+{
start <- charToRaw(as.character(start))
end <- charToRaw(as.character(end))
.redisCmd(.raw('LTRIM'), .raw(key), start, end)
}
-redisLIndex <- function(key, index) {
- .redisCmd(.raw('LINDEX'), .raw(key), index)
+redisLIndex <- function(key, index, ...)
+{
+ .redisCmd(.raw('LINDEX'), .raw(key), index, ...)
}
-redisLSet <- function(key, index, value) {
+redisLSet <- function(key, index, value)
+{
key <- charToRaw(as.character(key))
index <- charToRaw(as.character(index))
.redisCmd(.raw('LSET'), key, index, value)
}
-redisLRem <- function(key, count, value) {
+redisLRem <- function(key, count, value)
+{
.redisCmd(.raw('LREM'), .raw(key), .raw(as.character(count)), value)
}
-redisRPopLPush <- function(src, dest) {
- .redisCmd(.raw('RPOPLPUSH'), .raw(src), .raw(dest))
+redisRPopLPush <- function(src, dest, ...)
+{
+ .redisCmd(.raw('RPOPLPUSH'), .raw(src), .raw(dest), ...)
}
-redisBRPop <- function(keys, timeout=0) {
+redisBRPop <- function(keys, timeout=0, ...)
+{
keylist <- as.list(keys)
tout <- as.character(timeout)
- x <- do.call('.redisCmd',lapply(c(list('BRPOP'),keylist,tout),charToRaw))
+ x <- do.call('.redisCmd',c(lapply(c(list('BRPOP'),keylist,tout),charToRaw),...))
if(length(x)>1) {
n <- x[[1]]
x <- list(x[[2]])
@@ -62,10 +74,11 @@ redisBRPop <- function(keys, timeout=0) {
x
}
-redisBLPop <- function(keys, timeout=0) {
+redisBLPop <- function(keys, timeout=0, ...)
+{
keylist <- as.list(keys)
tout <- as.character(timeout)
- x <- do.call('.redisCmd',lapply(c(list('BLPOP'),keylist,tout),charToRaw))
+ x <- do.call('.redisCmd',c(lapply(c(list('BLPOP'),keylist,tout),charToRaw),...))
if(length(x)>1) {
n <- x[[1]]
x <- list(x[[2]])
@@ -74,7 +87,8 @@ redisBLPop <- function(keys, timeout=0) {
x
}
-redisBRPopLPush <- function(src, dest, timeout=0) {
+redisBRPopLPush <- function(src, dest, timeout=0, ...)
+{
tout <- as.character(timeout)
- .redisCmd(.raw('BRPOPLPUSH'), .raw(src), .raw(dest), .raw(tout))
+ .redisCmd(.raw('BRPOPLPUSH'), .raw(src), .raw(dest), .raw(tout), ...)
}
View
@@ -99,7 +99,7 @@ redisCmd <- function(CMD, ..., raw=FALSE)
if(is.character(x)) charToRaw(x)
else(.cerealize(x))
))
- if(raw) return(do.call('.redisRawCmd',a))
+ if(raw) a <- c(a,raw=TRUE)
do.call('.redisCmd', a)
}
@@ -125,16 +125,16 @@ redisCmd <- function(CMD, ..., raw=FALSE)
# define a little helper function to handle replacing the command.
# The rename list must have the form:
# list(OLDCOMMAND="NEWCOMMAND", SOME_OTHER_CMD="SOME_OTHER_NEW_CMD",...)
- rep = c()
+ rep <- c()
if(exists("rename",envir=.redisEnv)) rep = get("rename",envir=.redisEnv)
f <- match.call()
# Check for raw option (which means don't deserialize returned resuts)
- raw = FALSE
- if(any("raw") %in% names(f))
+ raw <- FALSE
+ if(any("raw" %in% names(f)))
{
- wr = which(names(f)=="homer")
- raw = f[[wr]]
- f = f[-wr]
+ wr <- which(names(f)=="raw")
+ raw <- f[[wr]]
+ f <- f[-wr]
}
n <- length(f) - 1
hdr <- paste('*', as.character(n), '\r\n',sep='')
View
@@ -1,37 +1,65 @@
+# A utility function that strips a named argument 'raw' from the list.
+# This function returns a list with two items:
+# 1. The stripped list without the raw=whatever entry
+# 2. The value of the named raw=whatever entry
+#
+# Use this with functions that have variable length arument lists.
+.redisStripRawArg <- function(List)
+{
+ ir <- which(names(List) %in% "raw")
+ raw <- c()
+ if(length(ir)>0)
+ {
+ raw <- List[[ir]]
+ List <- List[-ir]
+ }
+ list(List=List, raw=raw)
+}
+
redisSInter <- function(keys, ...)
{
- sets <- c(as.list(keys),list(...))
- do.call('.redisCmd',lapply(c(list('SINTER'),sets),charToRaw))
+ L <- .redisStripRawArg(list(...))
+ sets <- c(as.list(keys),L$List)
+ do.call('.redisCmd',c(lapply(c(list('SINTER'),sets),charToRaw),raw=L$raw))
}
redisSUnion <- function(keys, ...)
{
- sets <- c(as.list(keys),list(...))
- do.call('.redisCmd',lapply(c(list('SUNION'),sets),charToRaw))
+ L <- .redisStripRawArg(list(...))
+ sets <- c(as.list(keys),L$List)
+ do.call('.redisCmd',c(lapply(c(list('SUNION'),sets),charToRaw),raw=L$raw))
}
redisSUnionStore <- function(dest, keys, ...)
{
- sets <- c(as.list(dest),as.list(keys),list(...))
- do.call('.redisCmd',lapply(c(list('SUNIONSTORE'),sets),charToRaw))
+ L <- .redisStripRawArg(list(...))
+ sets <- c(as.list(dest),as.list(keys),L$List)
+ do.call('.redisCmd',c(lapply(c(list('SUNIONSTORE'),sets),charToRaw)
+ ,raw=L$raw))
}
redisSInterStore <- function(dest, keys, ...)
{
- sets <- c(as.list(dest),as.list(keys),list(...))
- do.call('.redisCmd',lapply(c(list('SINTERSTORE'),sets),charToRaw))
+ L <- .redisStripRawArg(list(...))
+ sets <- c(as.list(dest),as.list(keys),L$List)
+ do.call('.redisCmd',c(lapply(c(list('SINTERSTORE'),sets),charToRaw),
+ ,raw=L$raw))
}
redisSDiff <- function(keys, ...)
{
- sets <- c(as.list(keys),list(...))
- do.call('.redisCmd',lapply(c(list('SDIFF'),sets),charToRaw))
+ L <- .redisStripRawArg(list(...))
+ sets <- c(as.list(keys),L$List)
+ do.call('.redisCmd',c(lapply(c(list('SDIFF'),sets),charToRaw),
+ ,raw=L$raw))
}
redisSDiffStore <- function(dest, keys, ...)
{
- sets <- c(as.list(dest),as.list(keys),list(...))
- do.call('.redisCmd',lapply(c(list('SDIFFSTORE'),sets),charToRaw))
+ L <- .redisStripRawArg(list(...))
+ sets <- c(as.list(dest),as.list(keys),L$List)
+ do.call('.redisCmd',c(lapply(c(list('SDIFFSTORE'),sets),charToRaw),
+ ,raw=L$raw))
}
redisSIsMember <- function(set, element)
@@ -41,24 +69,24 @@ redisSIsMember <- function(set, element)
1 == .redisCmd(.raw('SISMEMBER'),.raw(set),.raw(element))
}
-redisSRandMember <- function(set)
+redisSRandMember <- function(set,...)
{
- .redisCmd(.raw('SRANDMEMBER'),.raw(set))
+ .redisCmd(.raw('SRANDMEMBER'),.raw(set),...)
}
redisSAdd <- function(set, element)
{
.redisCmd(.raw('SADD'),.raw(set),element)
}
-redisSPop <- function(set)
+redisSPop <- function(set,...)
{
- .redisCmd(.raw('SPOP'),.raw(set))
+ .redisCmd(.raw('SPOP'),.raw(set),...)
}
-redisSMembers <- function(set)
+redisSMembers <- function(set,...)
{
- .redisCmd(.raw('SMEMBERS'),.raw(set))
+ .redisCmd(.raw('SMEMBERS'),.raw(set),...)
}
redisSRem <- function(set, element)
Oops, something went wrong.

0 comments on commit def26f1

Please sign in to comment.