Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed doc typos; added Redis hashes

  • Loading branch information...
commit 35b1b3fdcbca4811156f4b8fdd900f9ed00809a0 1 parent 2f28b2e
B. W. Lewis authored
View
64 R/hashCMD.R
@@ -0,0 +1,64 @@
+# This file contains functions that operate on Redis 'hash' values.
+
+redisHGet <- function(key, field) {
+ .redisCmd(.raw('HGET'), .raw(key), .raw(field))
+}
+
+redisHSet <- function(key, field, value, NX=FALSE) {
+ value <- .cerealize(value)
+ cmd <- 'HSET'
+ if(NX) cmd <- 'HSETNX'
+ 1 == .redisCmd(.raw(cmd), .raw(key), .raw(field), value)
+}
+
+redisHMSet <- function(key, values) {
+ a <- c(alist(),list(.raw('HMSET')))
+ fieldnames <- lapply(as.list(names(values)),charToRaw)
+ for(j in 1:length(values))
+ a <- c(a,list(fieldnames[[j]],values[[j]]))
+ retval <- do.call('.redisCmd', a)
+ 'OK' == retval
+}
+
+redisHIncrBy <- function(key, field, value)
+{
+ .redisCmd(.raw('HINCRBY'),.raw(key),.raw(field),.raw(as.character(value)))
+}
+
+redisHExists <- function(key, field)
+{
+ .redisCmd(.raw('HEXISTS'), .raw(key), .raw(field)) == 1
+}
+
+redisHDel <- function(key, field)
+{
+ .redisCmd(.raw('HDEL'), .raw(key), .raw(field))
+}
+
+redisHLen <- function(key)
+{
+ .redisCmd(.raw('HDEL'), .raw(key))
+}
+
+redisHFields <- function(key)
+{
+ .redisCmd(.raw('HKEYS'), .raw(key))
+}
+
+redisHKeys <- function(key)
+{
+ redisHFields(key)
+}
+
+redisHVals <- function(key)
+{
+ .redisCmd(.raw('HVALS'), .raw(key))
+}
+
+redisHGetAll <- function(key)
+{
+ all <- .redisCmd(.raw('HGETALL'), .raw(key))
+ retval <- all[seq(2,length(all),by=2)]
+ names(retval) <- all[seq(1,length(all),by=2)]
+ retval
+}
View
2  man/redisDecr.Rd
@@ -31,7 +31,7 @@ B. W. Lewis
}
\examples{
\dontrun{
-redisStore('x',runif(5))
+redisSet('x',5)
redisDecr('x')
}
}
View
2  man/redisDecrBy.Rd
@@ -30,7 +30,7 @@ B. W. Lewis
}
\examples{
\dontrun{
-redisStore('x',runif(5))
+redisSet('x',5)
redisDecrBy('x',3)
}
}
View
2  man/redisDelete.Rd
@@ -31,7 +31,7 @@ B. W. Lewis
}
\examples{
\dontrun{
-redisStore('x',runif(5))
+redisSet('x',runif(5))
redisDelete('x')
}
}
View
2  man/redisExists.Rd
@@ -31,7 +31,7 @@ B. W. Lewis
}
\examples{
\dontrun{
-redisStore('x',runif(5))
+redisSet('x',runif(5))
redisExists('x')
}
}
View
2  man/redisGet.Rd
@@ -31,7 +31,7 @@ B. W. Lewis
}
\examples{
\dontrun{
-redisStore('x',runif(5))
+redisSet('x',runif(5))
redisGet('x')
}
}
View
32 man/redisHDel.Rd
@@ -0,0 +1,32 @@
+\name{redisHDel}
+\alias{redisHDel}
+\title{Delete a hash value.}
+\description{
+Delete the value associated with the given key/field combination.
+}
+\usage{
+redisHDel(key, field)
+}
+\arguments{
+ \item{key}{ A key name. }
+ \item{field}{ A field name. }
+}
+\value{
+Nothing is returned if the key/value pair is successfully deleted.
+A warning is thrown if the they key could not be found.
+}
+\references{
+http://code.google.com/p/redis/HdelCommand
+}
+\author{
+B. W. Lewis
+}
+\seealso{
+\code{\link{redisHSet}}
+}
+\examples{
+\dontrun{
+redisHMSet('A',list(x=1,y=2,z=3))
+redisHDel('A','x')
+}
+}
View
32 man/redisHExists.Rd
@@ -0,0 +1,32 @@
+\name{redisHExists}
+\alias{redisHExists}
+\title{Test the existence of a hash.}
+\description{
+Test the existence of a hash combination in the Redis database.
+}
+\usage{
+redisHExists(key, field)
+}
+\arguments{
+ \item{key}{ A key name. }
+ \item{field}{ A field name. }
+}
+\value{
+Returns FALSE if no matching key/field combination,
+TRUE if matching entry exists, and NULL if an error occured.
+}
+\references{
+http://code.google.com/p/redis/HexistsCommand
+}
+\author{
+B. W. Lewis
+}
+\seealso{
+\code{\link{redisHSet}}
+}
+\examples{
+\dontrun{
+redisHSet('A','x',runif(5))
+redisHExists('A','x')
+}
+}
View
26 man/redisHFields.Rd
@@ -0,0 +1,26 @@
+\name{redisHFields}
+\alias{redisHFields}
+\title{Redis hash fields.}
+\description{Return the fields associated with the given key.}
+\usage{
+redisHFields(key)
+}
+\arguments{
+ \item{key}{The key to look up.}
+}
+\details{Returns the fields in the Redis hash
+associated with \code{key}.
+If the key is not found, or if the hash is empty, NULL is returned. If the
+key is associated with a value of type other than 'hash,' an error is
+thrown.
+}
+\value{A list of fields defined for the given key. }
+\references{ http://code.google.com/p/redis/wiki/HfieldsCommand }
+\author{ B. W. Lewis }
+\seealso{ \code{\link{redisHSet}} }
+\examples{
+\dontrun{
+redisHMSet('A',list(x=1,y=2,z=3))
+redisHFields('A')
+}
+}
View
42 man/redisHGet.Rd
@@ -0,0 +1,42 @@
+\name{redisHGet}
+\alias{redisHGet}
+\title{Retrieve a hased value from Redis.}
+\description{Retrieve a value identified by a key and field
+from the Redis database.
+}
+\usage{
+redisHGet(key, field)
+}
+\arguments{
+ \item{key}{
+A key name.
+}
+ \item{field}{
+A field name.
+}
+}
+\details{
+Redis hash values store values in one or more fields associated with a single
+key name.
+}
+\value{
+The value corresponding to the specified key/field,
+or NULL if the matching key/field hash contained no value
+or if no matching key or field was found.
+}
+\references{
+http://code.google.com/p/redis/wiki/HgetCommand
+}
+\author{
+B. W. Lewis
+}
+
+\seealso{
+\code{\link{redisHSet}}
+}
+\examples{
+\dontrun{
+redisHSet('A','x',runif(5))
+redisHGet('A','x')
+}
+}
View
26 man/redisHGetAll.Rd
@@ -0,0 +1,26 @@
+\name{redisHGetAll}
+\alias{redisHGetAll}
+\title{Redis hash fields and values.}
+\description{Return all fields and values associated with the given key.}
+\usage{
+redisHGetAll(key)
+}
+\arguments{
+ \item{key}{The key to look up.}
+}
+\details{Returns all the fields and their values in the Redis hash
+associated with \code{key}.
+If the key is not found, or if the hash is empty, NULL is returned. If the
+key is associated with a value of type other than 'hash,' an error is
+thrown.
+}
+\value{A list of values defined for the given key, named by the field names.}
+\references{ http://code.google.com/p/redis/wiki/HgetallCommand }
+\author{ B. W. Lewis }
+\seealso{ \code{\link{redisHSet}} }
+\examples{
+\dontrun{
+redisHMSet('A',list(x=1,y=2,z=3))
+redisHGetAll('A')
+}
+}
View
40 man/redisHIncrBy.Rd
@@ -0,0 +1,40 @@
+\name{redisHIncrBy}
+\alias{redisHIncrBy}
+\title{Increment a value.}
+\description{Increment the value corresponding to the given key/field
+combination by the specified value.
+}
+\usage{
+redisHIncrBy(key, field, value)
+}
+\arguments{
+ \item{key}{A key name.}
+ \item{field}{A field name.}
+ \item{value}{The value to increment by (integer, numeric, or character).}
+}
+\details{
+The value should be a character representation of an integer.
+If the key/field value does not exist or contains a
+value of a wrong type, set the
+key to the value of "0" before to perform the operation.
+}
+\value{
+The new value of key after the increment, returned as a character
+string.
+}
+\references{
+http://code.google.com/p/redis/wiki/HincrbyCommand
+}
+\author{
+B. W. Lewis
+}
+
+\seealso{
+\code{\link{redisHSet}}
+}
+\examples{
+\dontrun{
+redisHSet('A','x',5)
+redisHIncrBy('A','x',3)
+}
+}
View
26 man/redisHKeys.Rd
@@ -0,0 +1,26 @@
+\name{redisHKeys}
+\alias{redisHKeys}
+\title{Redis hash fields.}
+\description{Return the fields associated with the given key.}
+\usage{
+redisHKeys(key)
+}
+\arguments{
+ \item{key}{The key to look up.}
+}
+\details{Returns the fields in the Redis hash
+associated with \code{key}.
+If the key is not found, or if the hash is empty, NULL is returned. If the
+key is associated with a value of type other than 'hash,' an error is
+thrown.
+}
+\value{A list of fields defined for the given key. }
+\references{ http://code.google.com/p/redis/wiki/HfieldsCommand }
+\author{ B. W. Lewis }
+\seealso{ \code{\link{redisHSet}} }
+\examples{
+\dontrun{
+redisHMSet('A',list(x=1,y=2,z=3))
+redisHKeys('A')
+}
+}
View
26 man/redisHLen.Rd
@@ -0,0 +1,26 @@
+\name{redisHLen}
+\alias{redisHLen}
+\title{Redis hash length.}
+\description{Return the number of fields associated with the given key.}
+\usage{
+redisHLen(key)
+}
+\arguments{
+ \item{key}{The key to look up.}
+}
+\details{Returns the number of fields in the Redis hash
+associated with \code{key}.
+If the key is not found, or if the hash is empty, 0 is returned. If the
+key is associated with a value of type other than 'hash,' an error is
+thrown.
+}
+\value{The number of fields defined for the given key. }
+\references{ http://code.google.com/p/redis/wiki/HlenCommand }
+\author{ B. W. Lewis }
+\seealso{ \code{\link{redisHSet}} }
+\examples{
+\dontrun{
+redisHMSet('A',list(x=1,y=2,z=3))
+redisHLen('A')
+}
+}
View
41 man/redisHMSet.Rd
@@ -0,0 +1,41 @@
+\name{redisHMSet}
+\alias{redisHMSet}
+\title{Store a list of hash values.}
+\description{Store a list of hash values at once.
+}
+\usage{
+redisHMSet(key, values)
+}
+\arguments{
+ \item{key}{
+The (required) character identifier for the key name.
+}
+ \item{values}{
+An R list of values to be stored. The list names are used as field names and
+must be nonempty.
+}
+}
+\details{
+Redis hash values store values in one or more fields associated with a single
+key name. The redisHMSet function stores several fields associated with one
+key at once. Values already occupying any specified field slots are replaced.
+}
+\value{
+TRUE is returned on success.
+}
+\references{
+http://code.google.com/p/redis/wiki/HmsetCommand
+}
+\author{
+B. W. Lewis
+}
+
+\seealso{
+\code{\link{redisHGet}}
+}
+\examples{
+\dontrun{
+redisHMSet('A', list(x=1,y=2,z=3))
+redisHGet('A','y')
+}
+}
View
59 man/redisHSet.Rd
@@ -0,0 +1,59 @@
+\name{redisHSet}
+\alias{redisHSet}
+\title{Store a hash value in Redis.}
+\description{Store a value identified by a character key name and field
+in the Redis database. Any existing value with the same key/field
+will be replaced by the new value unless NX is set to TRUE.
+}
+\usage{
+redisHSet(key, field, value, NX = FALSE)
+}
+\arguments{
+ \item{key}{
+The (required) character identifier for the key name.
+}
+ \item{field}{
+The (required) character identifier for the field name.
+}
+ \item{value}{
+The (required) object to associate with the key/field.
+}
+ \item{NX}{
+If NX = TRUE, existing values will not be replaced.
+}
+}
+\details{
+Redis hash values store values in one or more fields associated with a single
+key name.
+
+The value to be stored can be any
+serializable R object up to the Redis maximum object size
+(excluding, for example, external pointer references).
+References to other R objects or environments inside the value are not
+guaranteed to be preserved.
+
+In order to store strings that can easily be read by other clients, first
+convert the character object using the
+\code{\link{charToRaw}} function as shown in the
+examples.
+}
+\value{
+TRUE is returned on success.
+If NX = FALSE and a value already exists, the value will not be replaced
+and FALSE will be returned.
+}
+\references{
+http://code.google.com/p/redis/wiki/HsetCommand
+}
+\author{
+B. W. Lewis
+}
+
+\seealso{
+\code{\link{redisHGet}}
+}
+\examples{
+\dontrun{
+redisHSet('A', 'x',runif(5))
+}
+}
View
26 man/redisHVals.Rd
@@ -0,0 +1,26 @@
+\name{redisHVals}
+\alias{redisHVals}
+\title{Redis hash values.}
+\description{Return all the values associated with the given hash key.}
+\usage{
+redisHVals(key)
+}
+\arguments{
+ \item{key}{The key to look up.}
+}
+\details{Returns the values in the Redis hash
+associated with \code{key}.
+If the key is not found, or if the list is empty, NULL is returned. If the
+key is associated with a value of type other than 'hash,' an error is
+thrown.
+}
+\value{A list of values defined for the given key. }
+\references{ http://code.google.com/p/redis/wiki/HfieldsCommand }
+\author{ B. W. Lewis }
+\seealso{ \code{\link{redisHSet}} }
+\examples{
+\dontrun{
+redisHMSet('A',list(x=1,y=2,z=3))
+redisHVals('A')
+}
+}
View
2  man/redisIncr.Rd
@@ -31,7 +31,7 @@ B. W. Lewis
}
\examples{
\dontrun{
-redisStore('x',runif(5))
+redisSet('x',5)
redisIncr('x')
}
}
View
2  man/redisIncrBy.Rd
@@ -31,7 +31,7 @@ B. W. Lewis
}
\examples{
\dontrun{
-redisStore('x',runif(5))
+redisSet('x',5)
redisIncrBy('x',3)
}
}
View
4 man/redisMGet.Rd
@@ -27,8 +27,8 @@ B. W. Lewis
}
\examples{
\dontrun{
-redisStore('x',runif(5))
-redisStore('y',runif(5))
+redisSet('x',runif(5))
+redisSet('y',runif(5))
redisMGet(c('x','y'))
}
}
View
2  man/redisSet.Rd
@@ -3,7 +3,7 @@
\title{Store a value in Redis.}
\description{Store a value identified by a character key name
in the Redis database. Any existing value with the same key will be replaced
-by the new value.
+by the new value unless NX is set to TRUE.
}
\usage{
redisSet(key, value, NX = FALSE)
Please sign in to comment.
Something went wrong with that request. Please try again.