Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added sorted sets (finally\!)

  • Loading branch information...
commit d20b1e1a301192e6c517f00a2323662a6b17c350 1 parent 35b1b3f
B. W. Lewis authored
View
120 R/zsetVal.R
@@ -0,0 +1,120 @@
+# Redis ordered set functions
+
+redisZAdd <- function(key, score, member)
+{
+ .redisCmd(.raw('ZADD'),.raw(set), .raw(score), member)
+}
+
+redisZRem <- function(key, member)
+{
+ .redisCmd(.raw('ZREM'),.raw(key), member)
+}
+
+redisZIncrBy <- function(key, member, increment)
+{
+ .redisCmd(.raw('ZREM'),.raw(key), .raw(increment), member)
+}
+
+redisZRank <- function(key, member)
+{
+ .redisCmd(.raw('ZRANK'),.raw(key), member)
+}
+
+redisZRevRank <- function(key, member)
+{
+ .redisCmd(.raw('ZREVRANK'),.raw(key), member)
+}
+
+redisZRange <- function(key, start, end, withscores=FALSE)
+{
+ if(withscores)
+ .redisCmd(.raw('ZRANGE'),.raw(key),.raw(start),.raw(end),.raw('WITHSCORES'))
+ else
+ .redisCmd(.raw('ZRANGE'),.raw(key),.raw(start),.raw(end))
+}
+
+redisZRevRange <- function(key, start, end, withscores=FALSE)
+{
+ if(withscores)
+ .redisCmd(.raw('ZREVRANGE'),.raw(key),.raw(start),.raw(end),.raw('WITHSCORES'))
+ else
+ .redisCmd(.raw('ZREVRANGE'),.raw(key),.raw(start),.raw(end))
+}
+
+redisZRangeByScore <- function(key, min, max, offset=NULL, count=NULL, withscores=FALSE)
+{
+ a <- c(alist(), list(.raw('ZRANGEBYSCORE'), .raw(key), .raw(min), .raw(max)))
+ if(!is.null(offset) && !is.null(count)) {
+ a <- c(a, list(.raw('LIMIT'), .raw(offset), .raw(count)))
+ }
+ if(withscores)
+ a <- c(a, as.list(.raw('WITHSCORES')))
+ do.call('.redisCmd', a)
+}
+
+redisZRemRangeByRank <- function(key, start, end)
+{
+ .redisCmd(.raw('ZREMRANGEBYRANK'), .raw(key), .raw(start), .raw(end))
+}
+
+redisZRemRangeByScore <- function(key, min, max)
+{
+ .redisCmd(.raw('ZREMRANGEBYRANK'), .raw(key), .raw(min), .raw(max))
+}
+
+redisZCard <- function(key)
+{
+ .redisCmd(.raw('ZCARD'), .raw(key))
+}
+
+redisZScore <- function(key, element)
+{
+ ret <- .redisCmd(.raw('ZSCORE'), .raw(key), .raw(element))
+ if(!is.null(ret)) ret <- as.numeric(ret)
+ ret
+}
+
+.zinu <- function(type, dstkey, keys, weights=c(), aggregate=NULL)
+{
+ a <- c(alist(), list(.raw(type), .raw(dstkey)))
+ sets <- lapply(as.list(keys),charToRaw)
+ a <- c(a, sets)
+ if(!is.null(weights)) {
+ a <- c(a, .raw('WEIGHTS'), lapply(as.list(weights), charToRaw))
+ }
+ if(!is.null(aggregate)) {
+ a <- c(a, .raw('AGGREGATE'), .raw(aggregate))
+ }
+ do.call('.redisCmd', a)
+}
+
+redisZInter <- function(dstkey, keys, weights=c(), aggregate=NULL)
+{
+ .zinu('ZINTER', dstkey, keys, weights, aggregate)
+}
+
+redisZUnion <- function(dstkey, keys, weights=c(), aggregate=NULL)
+{
+ .zinu('ZUNION', dstkey, keys, weights, aggregate)
+}
+
+redisSort <- function(key, decreasing=FALSE, alpha=FALSE, by=NULL, start=NULL,
+ count=NULL, get=NULL, store=NULL)
+{
+ a <- c(alist(), list(.raw(key)))
+ if(!is.null(by))
+ a <- c(a, as.list(.raw('BY'), .raw(by)))
+ if(!is.null(start) && !is.null(count))
+ a <- c(a, as.list(.raw('LIMIT'), .raw(start), .raw(count)))
+ if(!is.null(get))
+ a <- c(a, as.list(.raw('GET'), .raw(get)))
+ if(decreasing)
+ a <- c(a, as.list(.raw('DESC')))
+ else
+ a <- c(a, as.list(.raw('ASC')))
+ if(alpha)
+ a <- c(a, as.list(.raw('ALPHA')))
+ if(store)
+ a <- c(a, as.list(.raw('STORE'), .raw(store)))
+ do.call('.redisCmd', a)
+}
View
8 README
@@ -1,6 +1,12 @@
rredis: An R client for Redis
-example:
+NOTE
+
+1. Redis is evolving rapidly. The rredis client supports many commands that are
+only available in Redis versions 1.3 and higher.
+
+EXAMPLE
+
> library(rredis)
> redisConnect()
> redisSet('foo', runif(10))
View
56 man/redisSort.Rd
@@ -0,0 +1,56 @@
+\name{redisSort}
+\alias{redisSort}
+\title{
+redisSort
+}
+\description{
+Sort a list, set or sorted set (zset).
+}
+\usage{
+redisSort(key, decreasing = FALSE, alpha = FALSE, by = NULL, start = NULL, count = NULL, get = NULL, store = NULL)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+ \item{key}{
+The key name of the list, set or zset to be sorted.
+}
+ \item{decreasing}{
+Set the direction of the sort.
+}
+ \item{alpha}{
+Lexicographically sort if true, otherwise try numeric sorting.
+}
+ \item{by}{
+The BY option takes a pattern that is used in order
+to generate the key names of the weights used for sorting. Weight key names are
+obtained substituting the first occurrence of * with the actual value of the
+elements on the list. See the Redis documentation for examples.
+}
+ \item{start}{
+Starting index of the sort.
+}
+ \item{count}{
+Number of entries past start to use for the sort.
+}
+ \item{get}{
+Retrieve external keys. See the Redis documentation.
+}
+ \item{store}{
+Store the results in the specified key.
+}
+}
+\details{
+Sort the elements contained in the List, Set, or Sorted Set value at key. By
+default sorting is numeric with elements being compared as double precision
+floating point numbers.
+}
+\value{
+A list of sorted values, unless \code{store} is specified in which case
+the results are stored in the specified key and TRUE is returned.
+}
+\references{
+http://code.google.com/p/redis/SortCommand
+}
+\author{
+B. W. Lewis
+}
View
28 man/redisZAdd.Rd
@@ -0,0 +1,28 @@
+\name{redisZAdd}
+\alias{redisZAdd}
+\title{
+redisZAdd
+}
+\description{
+redisZAdd
+}
+\usage{
+redisZAdd(key, score, member)
+}
+\arguments{
+ \item{key}{
+%% ~~Describe \code{key} here~~
+}
+ \item{score}{
+%% ~~Describe \code{score} here~~
+}
+ \item{member}{
+%% ~~Describe \code{member} here~~
+}
+}
+\references{
+http://code.google.com/p/redis/
+}
+\author{
+B. W. Lewis
+}
View
33 man/redisZCard.Rd
@@ -0,0 +1,33 @@
+\name{redisZCard}
+\alias{redisZCard}
+\title{
+redisZCard.Rd
+}
+\description{
+redisZCard.Rd
+}
+\usage{
+redisZCard(key)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+ \item{key}{
+%% ~~Describe \code{key} here~~
+}
+}
+\details{
+See the Redis documentation for details.
+}
+\value{
+See the Redis documentation for more information.
+%% If it is a LIST, use
+%% \item{comp1 }{Description of 'comp1'}
+%% \item{comp2 }{Description of 'comp2'}
+%% ...
+}
+\references{
+http://code.google.com/p/redis/
+}
+\author{
+B. W. Lewis
+}
View
40 man/redisZIncrBy.Rd
@@ -0,0 +1,40 @@
+\name{redisZIncrBy}
+\alias{redisZIncrBy}
+%- Also NEED an '\alias' for EACH other topic documented here.
+\title{
+redisZIncrBy.Rd
+}
+\description{
+redisZIncrBy.Rd
+}
+\usage{
+redisZIncrBy(key, member, increment)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+ \item{key}{
+%% ~~Describe \code{key} here~~
+}
+ \item{member}{
+%% ~~Describe \code{member} here~~
+}
+ \item{increment}{
+%% ~~Describe \code{increment} here~~
+}
+}
+\details{
+See the Redis documentation for details.
+}
+\value{
+See the Redis documentation for more information.
+%% If it is a LIST, use
+%% \item{comp1 }{Description of 'comp1'}
+%% \item{comp2 }{Description of 'comp2'}
+%% ...
+}
+\references{
+http://code.google.com/p/redis/
+}
+\author{
+B. W. Lewis
+}
View
43 man/redisZInter.Rd
@@ -0,0 +1,43 @@
+\name{redisZInter}
+\alias{redisZInter}
+%- Also NEED an '\alias' for EACH other topic documented here.
+\title{
+redisZInter.Rd
+}
+\description{
+redisZInter.Rd
+}
+\usage{
+redisZInter(dstkey, keys, weights = c(), aggregate = NULL)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+ \item{dstkey}{
+%% ~~Describe \code{dstkey} here~~
+}
+ \item{keys}{
+%% ~~Describe \code{keys} here~~
+}
+ \item{weights}{
+%% ~~Describe \code{weights} here~~
+}
+ \item{aggregate}{
+%% ~~Describe \code{aggregate} here~~
+}
+}
+\details{
+See the Redis documentation for details.
+}
+\value{
+See the Redis documentation for more information.
+%% If it is a LIST, use
+%% \item{comp1 }{Description of 'comp1'}
+%% \item{comp2 }{Description of 'comp2'}
+%% ...
+}
+\references{
+http://code.google.com/p/redis/
+}
+\author{
+B. W. Lewis
+}
View
43 man/redisZRange.Rd
@@ -0,0 +1,43 @@
+\name{redisZRange}
+\alias{redisZRange}
+%- Also NEED an '\alias' for EACH other topic documented here.
+\title{
+redisZRange.Rd
+}
+\description{
+redisZRange.Rd
+}
+\usage{
+redisZRange(key, start, end, withscores = FALSE)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+ \item{key}{
+%% ~~Describe \code{key} here~~
+}
+ \item{start}{
+%% ~~Describe \code{start} here~~
+}
+ \item{end}{
+%% ~~Describe \code{end} here~~
+}
+ \item{withscores}{
+%% ~~Describe \code{withscores} here~~
+}
+}
+\details{
+See the Redis documentation for details.
+}
+\value{
+See the Redis documentation for more information.
+%% If it is a LIST, use
+%% \item{comp1 }{Description of 'comp1'}
+%% \item{comp2 }{Description of 'comp2'}
+%% ...
+}
+\references{
+http://code.google.com/p/redis/
+}
+\author{
+B. W. Lewis
+}
View
49 man/redisZRangeByScore.Rd
@@ -0,0 +1,49 @@
+\name{redisZRangeByScore}
+\alias{redisZRangeByScore}
+%- Also NEED an '\alias' for EACH other topic documented here.
+\title{
+redisZRangeByScore.Rd
+}
+\description{
+redisZRangeByScore.Rd
+}
+\usage{
+redisZRangeByScore(key, min, max, offset = NULL, count = NULL, withscores = FALSE)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+ \item{key}{
+%% ~~Describe \code{key} here~~
+}
+ \item{min}{
+%% ~~Describe \code{min} here~~
+}
+ \item{max}{
+%% ~~Describe \code{max} here~~
+}
+ \item{offset}{
+%% ~~Describe \code{offset} here~~
+}
+ \item{count}{
+%% ~~Describe \code{count} here~~
+}
+ \item{withscores}{
+%% ~~Describe \code{withscores} here~~
+}
+}
+\details{
+See the Redis documentation for details.
+}
+\value{
+See the Redis documentation for more information.
+%% If it is a LIST, use
+%% \item{comp1 }{Description of 'comp1'}
+%% \item{comp2 }{Description of 'comp2'}
+%% ...
+}
+\references{
+http://code.google.com/p/redis/
+}
+\author{
+B. W. Lewis
+}
View
37 man/redisZRank.Rd
@@ -0,0 +1,37 @@
+\name{redisZRank}
+\alias{redisZRank}
+%- Also NEED an '\alias' for EACH other topic documented here.
+\title{
+redisZRank.Rd
+}
+\description{
+redisZRank.Rd
+}
+\usage{
+redisZRank(key, member)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+ \item{key}{
+%% ~~Describe \code{key} here~~
+}
+ \item{member}{
+%% ~~Describe \code{member} here~~
+}
+}
+\details{
+See the Redis documentation for details.
+}
+\value{
+See the Redis documentation for more information.
+%% If it is a LIST, use
+%% \item{comp1 }{Description of 'comp1'}
+%% \item{comp2 }{Description of 'comp2'}
+%% ...
+}
+\references{
+http://code.google.com/p/redis/
+}
+\author{
+B. W. Lewis
+}
View
37 man/redisZRem.Rd
@@ -0,0 +1,37 @@
+\name{redisZRem}
+\alias{redisZRem}
+%- Also NEED an '\alias' for EACH other topic documented here.
+\title{
+redisZRem.Rd
+}
+\description{
+redisZRem.Rd
+}
+\usage{
+redisZRem(key, member)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+ \item{key}{
+%% ~~Describe \code{key} here~~
+}
+ \item{member}{
+%% ~~Describe \code{member} here~~
+}
+}
+\details{
+See the Redis documentation for details.
+}
+\value{
+See the Redis documentation for more information.
+%% If it is a LIST, use
+%% \item{comp1 }{Description of 'comp1'}
+%% \item{comp2 }{Description of 'comp2'}
+%% ...
+}
+\references{
+http://code.google.com/p/redis/
+}
+\author{
+B. W. Lewis
+}
View
40 man/redisZRemRangeByRank.Rd
@@ -0,0 +1,40 @@
+\name{redisZRemRangeByRank}
+\alias{redisZRemRangeByRank}
+%- Also NEED an '\alias' for EACH other topic documented here.
+\title{
+redisZRemRangeByRank.Rd
+}
+\description{
+redisZRemRangeByRank.Rd
+}
+\usage{
+redisZRemRangeByRank(key, start, end)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+ \item{key}{
+%% ~~Describe \code{key} here~~
+}
+ \item{start}{
+%% ~~Describe \code{start} here~~
+}
+ \item{end}{
+%% ~~Describe \code{end} here~~
+}
+}
+\details{
+See the Redis documentation for details.
+}
+\value{
+See the Redis documentation for more information.
+%% If it is a LIST, use
+%% \item{comp1 }{Description of 'comp1'}
+%% \item{comp2 }{Description of 'comp2'}
+%% ...
+}
+\references{
+http://code.google.com/p/redis/
+}
+\author{
+B. W. Lewis
+}
View
40 man/redisZRemRangeByScore.Rd
@@ -0,0 +1,40 @@
+\name{redisZRemRangeByScore}
+\alias{redisZRemRangeByScore}
+%- Also NEED an '\alias' for EACH other topic documented here.
+\title{
+redisZRemRangeByScore.Rd
+}
+\description{
+redisZRemRangeByScore.Rd
+}
+\usage{
+redisZRemRangeByScore(key, min, max)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+ \item{key}{
+%% ~~Describe \code{key} here~~
+}
+ \item{min}{
+%% ~~Describe \code{min} here~~
+}
+ \item{max}{
+%% ~~Describe \code{max} here~~
+}
+}
+\details{
+See the Redis documentation for details.
+}
+\value{
+See the Redis documentation for more information.
+%% If it is a LIST, use
+%% \item{comp1 }{Description of 'comp1'}
+%% \item{comp2 }{Description of 'comp2'}
+%% ...
+}
+\references{
+http://code.google.com/p/redis/
+}
+\author{
+B. W. Lewis
+}
View
43 man/redisZRevRange.Rd
@@ -0,0 +1,43 @@
+\name{redisZRevRange}
+\alias{redisZRevRange}
+%- Also NEED an '\alias' for EACH other topic documented here.
+\title{
+redisZRevRange.Rd
+}
+\description{
+redisZRevRange.Rd
+}
+\usage{
+redisZRevRange(key, start, end, withscores = FALSE)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+ \item{key}{
+%% ~~Describe \code{key} here~~
+}
+ \item{start}{
+%% ~~Describe \code{start} here~~
+}
+ \item{end}{
+%% ~~Describe \code{end} here~~
+}
+ \item{withscores}{
+%% ~~Describe \code{withscores} here~~
+}
+}
+\details{
+See the Redis documentation for details.
+}
+\value{
+See the Redis documentation for more information.
+%% If it is a LIST, use
+%% \item{comp1 }{Description of 'comp1'}
+%% \item{comp2 }{Description of 'comp2'}
+%% ...
+}
+\references{
+http://code.google.com/p/redis/
+}
+\author{
+B. W. Lewis
+}
View
37 man/redisZRevRank.Rd
@@ -0,0 +1,37 @@
+\name{redisZRevRank}
+\alias{redisZRevRank}
+%- Also NEED an '\alias' for EACH other topic documented here.
+\title{
+redisZRevRank.Rd
+}
+\description{
+redisZRevRank.Rd
+}
+\usage{
+redisZRevRank(key, member)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+ \item{key}{
+%% ~~Describe \code{key} here~~
+}
+ \item{member}{
+%% ~~Describe \code{member} here~~
+}
+}
+\details{
+See the Redis documentation for details.
+}
+\value{
+See the Redis documentation for more information.
+%% If it is a LIST, use
+%% \item{comp1 }{Description of 'comp1'}
+%% \item{comp2 }{Description of 'comp2'}
+%% ...
+}
+\references{
+http://code.google.com/p/redis/
+}
+\author{
+B. W. Lewis
+}
View
37 man/redisZScore.Rd
@@ -0,0 +1,37 @@
+\name{redisZScore}
+\alias{redisZScore}
+%- Also NEED an '\alias' for EACH other topic documented here.
+\title{
+redisZScore.Rd
+}
+\description{
+redisZScore.Rd
+}
+\usage{
+redisZScore(key, element)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+ \item{key}{
+%% ~~Describe \code{key} here~~
+}
+ \item{element}{
+%% ~~Describe \code{element} here~~
+}
+}
+\details{
+See the Redis documentation for details.
+}
+\value{
+See the Redis documentation for more information.
+%% If it is a LIST, use
+%% \item{comp1 }{Description of 'comp1'}
+%% \item{comp2 }{Description of 'comp2'}
+%% ...
+}
+\references{
+http://code.google.com/p/redis/
+}
+\author{
+B. W. Lewis
+}
View
43 man/redisZUnion.Rd
@@ -0,0 +1,43 @@
+\name{redisZUnion}
+\alias{redisZUnion}
+%- Also NEED an '\alias' for EACH other topic documented here.
+\title{
+redisZUnion.Rd
+}
+\description{
+redisZUnion.Rd
+}
+\usage{
+redisZUnion(dstkey, keys, weights = c(), aggregate = NULL)
+}
+%- maybe also 'usage' for other objects documented here.
+\arguments{
+ \item{dstkey}{
+%% ~~Describe \code{dstkey} here~~
+}
+ \item{keys}{
+%% ~~Describe \code{keys} here~~
+}
+ \item{weights}{
+%% ~~Describe \code{weights} here~~
+}
+ \item{aggregate}{
+%% ~~Describe \code{aggregate} here~~
+}
+}
+\details{
+See the Redis documentation for details.
+}
+\value{
+See the Redis documentation for more information.
+%% If it is a LIST, use
+%% \item{comp1 }{Description of 'comp1'}
+%% \item{comp2 }{Description of 'comp2'}
+%% ...
+}
+\references{
+http://code.google.com/p/redis/
+}
+\author{
+B. W. Lewis
+}
Please sign in to comment.
Something went wrong with that request. Please try again.