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