PageRenderTime 23ms CodeModel.GetById 13ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/test/basicTest.R

http://github.com/bwlewis/rredis
R | 133 lines | 81 code | 19 blank | 33 comment | 0 complexity | eaf7b9a671985de7f0e278ff3777cdce MD5 | raw file
  1test01_connect <- function() {
  2  redisConnect()
  3}
  4
  5test02_exists <- function() {
  6  # legacy exists test
  7  redisFlushAll()
  8  checkEquals(FALSE, redisExists('foo'))
  9}
 10
 11test03_delete <- function() {
 12  # delete test
 13  redisFlushAll()
 14  checkEquals(FALSE, suppressWarnings(redisDelete('foo')))
 15}
 16
 17test04_empty_get <- function() {
 18  # empty get test
 19  redisFlushAll()
 20  checkTrue(is.null(redisGet('foo')))
 21}
 22
 23test05_set <- function() {
 24  # simple set test
 25  checkEquals('OK', redisSet('foo', 'bar'))
 26}
 27
 28test06_getset <- function() {
 29  # simple getset test
 30  checkEquals('bar', redisGetSet('foo', 'zip'))
 31}
 32
 33test07_get <- function() {
 34  # getset confirm
 35  checkEquals('zip', redisGet('foo'))
 36}
 37
 38test08_serialization <- function() {
 39  # set/serialize test
 40  foo <- runif(10)
 41  redisSet('foo', foo)
 42  checkEqualsNumeric(foo, redisGet('foo'))
 43}
 44
 45test09_type <- function() {
 46  # simple type check
 47  checkEquals('string', redisType('foo'))
 48}
 49
 50test10_mget <- function() {
 51  # mget test
 52  redisSet('foo', 'bar')
 53  redisSet('bar', 'foo')
 54  checkEquals(list(foo='bar', bar='foo'), redisMGet(c('foo', 'bar')))
 55}
 56
 57test11_mset_simple <- function() {
 58  # simple mset test
 59  checkEquals("OK", redisMSet(list(foo='foo',bar='bar')))
 60}
 61
 62test12_get <- function() {
 63  # simple mset confirm
 64  checkEquals('foo', redisGet('foo'))
 65}
 66
 67test13_mset <- function() {
 68  # real mset test
 69  redisDelete(c('foo', 'bar'))
 70  redisMSet(list(foo='bar',bar='foo'))
 71  checkEquals(list(foo='bar',bar='foo'), redisMGet(c('foo', 'bar')))
 72  redisDelete(c('foo', 'bar'))
 73}
 74
 75test14_exists <- function() {
 76  # real exists test
 77  checkEquals(FALSE, redisExists('foo'))
 78  redisSet('foo', 1)
 79  checkTrue(redisExists('foo'))
 80  redisDelete('foo')
 81}
 82
 83###test15 <- function() {
 84###  # keys test
 85###  redisFlushAll()
 86###  checkEquals(NULL, redisKeys('*'))
 87###  redisSet('foo', 1)
 88###  checkEquals(list('foo'), redisKeys('*'))
 89###  redisDelete('foo')
 90###}
 91
 92###test16 <- function() {
 93###  # randomkey test
 94###  checkEquals('', redisRandomKey())
 95###  redisSet('foo', 1)
 96###  checkEquals('foo', redisRandomKey())
 97###  redisDelete('foo')
 98###}
 99
100test17_expire <- function() {
101  # expire test
102  redisSet('foo', 1)
103  redisExpire('foo', 1)
104  Sys.sleep(2)
105  checkEquals(FALSE, redisExists('foo'))
106  # expireat not tested because I don't know how
107  # to get unix time in R. -PS
108}
109
110test18_rename <- function() {
111  # rename/renamenx test
112  redisSet('foo', 1)
113  redisSet('bar', 2)
114  redisRename('foo', 'bar')
115  checkEquals(1, redisGet('bar'))
116  redisSet('foo', 2)
117  checkEquals(0, redisRename('foo', 'bar', NX=TRUE))
118  redisDelete('bar')
119  redisRename('foo', 'bar', NX=TRUE)
120  checkEquals(2, redisGet('bar'))
121}
122
123test19_setmsetnx <- function() {
124  # set/mset nx mode test
125  redisFlushAll()
126  checkEquals(1, redisSet('foo', 1, NX=TRUE))
127  checkEquals(0, redisSet('foo', 1, NX=TRUE))
128  checkEquals(0, redisMSet(list(foo=1), NX=TRUE))
129  redisDelete('foo')
130  checkEquals(1, redisMSet(list(foo=1,bar=2), NX=TRUE))
131  redisDelete(c('foo','bar'))
132}
133