/test/basicTest.R

http://github.com/bwlewis/rredis · R · 133 lines · 81 code · 19 blank · 33 comment · 0 complexity · eaf7b9a671985de7f0e278ff3777cdce MD5 · raw file

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