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

Commit

Permalink
Fixed doc typos; added Redis hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
B. W. Lewis committed Apr 30, 2010
1 parent 2f28b2e commit 35b1b3f
Show file tree
Hide file tree
Showing 21 changed files with 450 additions and 10 deletions.
64 changes: 64 additions & 0 deletions 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
}
2 changes: 1 addition & 1 deletion man/redisDecr.Rd
Expand Up @@ -31,7 +31,7 @@ B. W. Lewis
}
\examples{
\dontrun{
redisStore('x',runif(5))
redisSet('x',5)
redisDecr('x')
}
}
Expand Down
2 changes: 1 addition & 1 deletion man/redisDecrBy.Rd
Expand Up @@ -30,7 +30,7 @@ B. W. Lewis
}
\examples{
\dontrun{
redisStore('x',runif(5))
redisSet('x',5)
redisDecrBy('x',3)
}
}
2 changes: 1 addition & 1 deletion man/redisDelete.Rd
Expand Up @@ -31,7 +31,7 @@ B. W. Lewis
}
\examples{
\dontrun{
redisStore('x',runif(5))
redisSet('x',runif(5))
redisDelete('x')
}
}
2 changes: 1 addition & 1 deletion man/redisExists.Rd
Expand Up @@ -31,7 +31,7 @@ B. W. Lewis
}
\examples{
\dontrun{
redisStore('x',runif(5))
redisSet('x',runif(5))
redisExists('x')
}
}
2 changes: 1 addition & 1 deletion man/redisGet.Rd
Expand Up @@ -31,7 +31,7 @@ B. W. Lewis
}
\examples{
\dontrun{
redisStore('x',runif(5))
redisSet('x',runif(5))
redisGet('x')
}
}
32 changes: 32 additions & 0 deletions 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')
}
}
32 changes: 32 additions & 0 deletions 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')
}
}
26 changes: 26 additions & 0 deletions 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')
}
}
42 changes: 42 additions & 0 deletions 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')
}
}
26 changes: 26 additions & 0 deletions 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')
}
}
40 changes: 40 additions & 0 deletions 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)
}
}
26 changes: 26 additions & 0 deletions 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')
}
}
26 changes: 26 additions & 0 deletions 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')
}
}

0 comments on commit 35b1b3f

Please sign in to comment.