PageRenderTime 23ms CodeModel.GetById 14ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/R/strValCMD.R

http://github.com/bwlewis/rredis
R | 68 lines | 54 code | 10 blank | 4 comment | 7 complexity | 8335d6d2a3d812cecd39d699a558179c MD5 | raw file
 1# This file contains functions that operate on Redis 'string' values.
 2
 3redisGet <- function(key, ...)
 4{
 5  .redisCmd(.raw('GET'), .raw(key), ...)
 6}
 7
 8redisSet <- function(key, value, NX=FALSE)
 9{
10  value <- .cerealize(value)
11  cmd <- 'SET'
12  if(NX) cmd <- 'SETNX'
13  .redisCmd(.raw(cmd), .raw(key), value)
14}
15
16redisGetSet <- function(key, value, ...)
17{
18  .redisCmd(.raw('GETSET'),.raw(key),value, ...)
19}
20
21redisMGet <- function(keys, ...)
22{
23  keylist <- as.list(keys)
24  x <- do.call('.redisCmd',c(lapply(c(list('MGET'),keylist),charToRaw),...))
25# The following may not occur, for example within a transaction block:
26  if(length(x) == length(keylist)) names(x) <- keylist
27  x
28}
29
30redisMSet <- function(keyvalues, NX=FALSE, ...)
31{
32# Includes a significant performance improvement contributed
33# by William Pleasant.
34  if (0L == length(keyvalues))
35      return(NULL)
36  if (NX) cmd <- 'MSETNX' else cmd <- 'MSET'
37  a <- list(.raw(cmd))
38  j <- 2L * seq_along(keyvalues)
39  a[j + 1L] <- keyvalues                # extends a
40  a[j] <- lapply(names(keyvalues), charToRaw)
41  a <- c(a, ...)
42  do.call('.redisCmd', a)
43}
44
45redisIncr <- function(key)
46{
47  .redisCmd(.raw('INCR'),.raw(key))
48}
49
50redisIncrBy <- function(key, value)
51{
52  .redisCmd(.raw('INCRBY'),.raw(key),.raw(as.character(value)))
53}
54
55redisIncrByFloat <- function(key, value)
56{
57  .redisCmd(.raw('INCRBYFLOAT'),.raw(key),.raw(as.character(value)))
58}
59
60redisDecrBy <- function(key, value)
61{
62  .redisCmd(.raw('DECRBY'),.raw(key),.raw(as.character(value)))
63}
64
65redisDecr <- function(key)
66{
67  .redisCmd(.raw('DECR'),.raw(key))
68}