]> gitweb.factorcode.org Git - factor.git/blob - extra/redis/command-writer/command-writer-tests.factor
Add hash commands to extra/redis
[factor.git] / extra / redis / command-writer / command-writer-tests.factor
1 ! Copyright (C) 2009 Bruno Deferrari
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: tools.test redis.command-writer io.streams.string ;
4 IN: redis.command-writer.tests
5
6 #! Connection
7 [ "QUIT\r\n" ] [ [ quit ] with-string-writer ] unit-test
8
9 [ "PING\r\n" ] [ [ ping ] with-string-writer ] unit-test
10
11 [ "AUTH password\r\n" ] [ [ "password" auth ] with-string-writer ] unit-test
12
13 #! String values
14 [ "SET key 3\r\nfoo\r\n" ] [ [ "foo" "key" set ] with-string-writer ] unit-test
15
16 [ "GET key\r\n" ] [ [ "key" get ] with-string-writer ] unit-test
17
18 [ "GETSET key 3\r\nfoo\r\n" ] [
19     [ "foo" "key" getset ] with-string-writer
20 ] unit-test
21
22 [ "MGET key1 key2 key3\r\n" ] [
23     [ { "key1" "key2" "key3" } mget ] with-string-writer
24 ] unit-test
25
26 [ "SETNX key 3\r\nfoo\r\n" ] [
27     [ "foo" "key" setnx ] with-string-writer
28 ] unit-test
29
30 [ "INCR key\r\n" ] [ [ "key" incr ] with-string-writer ] unit-test
31
32 [ "INCRBY key 7\r\n" ] [ [ 7 "key" incrby ] with-string-writer ] unit-test
33
34 [ "DECR key\r\n" ] [ [ "key" decr ] with-string-writer ] unit-test
35
36 [ "DECRBY key 7\r\n" ] [ [ 7 "key" decrby ] with-string-writer ] unit-test
37
38 [ "EXISTS key\r\n" ] [ [ "key" exists ] with-string-writer ] unit-test
39
40 [ "DEL key\r\n" ] [ [ "key" del ] with-string-writer ] unit-test
41
42 [ "TYPE key\r\n" ] [ [ "key" type ] with-string-writer ] unit-test
43
44 #! Key space
45 [ "KEYS pat*\r\n" ] [ [ "pat*" keys ] with-string-writer ] unit-test
46
47 [ "RANDOMKEY\r\n" ] [ [ randomkey ] with-string-writer ] unit-test
48
49 [ "RENAME key newkey\r\n" ] [
50     [ "newkey" "key" rename ] with-string-writer
51 ] unit-test
52
53 [ "RENAMENX key newkey\r\n" ] [
54     [ "newkey" "key" renamenx ] with-string-writer
55 ] unit-test
56
57 [ "DBSIZE\r\n" ] [ [ dbsize ] with-string-writer ] unit-test
58
59 [ "EXPIRE key 7\r\n" ] [ [ 7 "key" expire ] with-string-writer ] unit-test
60
61 #! Lists
62 [ "RPUSH key 3\r\nfoo\r\n" ] [ [ "foo" "key" rpush ] with-string-writer ] unit-test
63
64 [ "LPUSH key 3\r\nfoo\r\n" ] [ [ "foo" "key" lpush ] with-string-writer ] unit-test
65
66 [ "LLEN key\r\n" ] [ [ "key" llen ] with-string-writer ] unit-test
67
68 [ "LRANGE key 5 9\r\n" ] [ [ 5 9 "key" lrange ] with-string-writer ] unit-test
69
70 [ "LTRIM key 5 9\r\n" ] [ [ 5 9 "key" ltrim ] with-string-writer ] unit-test
71
72 [ "LINDEX key 7\r\n" ] [ [ 7 "key" lindex ] with-string-writer ] unit-test
73
74 [ "LSET key 0 3\r\nfoo\r\n" ] [ [ "foo" 0 "key" lset ] with-string-writer ] unit-test
75
76 [ "LREM key 1 3\r\nfoo\r\n" ] [ [ "foo" 1 "key" lrem ] with-string-writer ] unit-test
77
78 [ "LPOP key\r\n" ] [ [ "key" lpop ] with-string-writer ] unit-test
79
80 [ "RPOP key\r\n" ] [ [ "key" rpop ] with-string-writer ] unit-test
81
82 #! Sets
83 [ "SADD key 3\r\nfoo\r\n" ] [ [ "foo" "key" sadd ] with-string-writer ] unit-test
84
85 [ "SREM key 3\r\nfoo\r\n" ] [ [ "foo" "key" srem ] with-string-writer ] unit-test
86
87 [ "SMOVE srckey dstkey 3\r\nfoo\r\n" ] [
88     [ "foo" "dstkey" "srckey" smove ] with-string-writer
89 ] unit-test
90
91 [ "SCARD key\r\n" ] [ [ "key" scard ] with-string-writer ] unit-test
92
93 [ "SISMEMBER key 3\r\nfoo\r\n" ] [
94     [ "foo" "key" sismember ] with-string-writer
95 ] unit-test
96
97 [ "SINTER key1 key2 key3\r\n" ] [
98     [ { "key1" "key2" "key3" } sinter ] with-string-writer
99 ] unit-test
100
101 [ "SINTERSTORE dstkey key1 key2 key3\r\n" ] [
102     [ { "key1" "key2" "key3" } "dstkey" sinterstore ] with-string-writer
103 ] unit-test
104
105 [ "SUNION key1 key2 key3\r\n" ] [
106     [ { "key1" "key2" "key3" } sunion ] with-string-writer
107 ] unit-test
108
109 [ "SUNIONSTORE dstkey key1 key2 key3\r\n" ] [
110     [ { "key1" "key2" "key3" } "dstkey" sunionstore ] with-string-writer
111 ] unit-test
112
113 [ "SMEMBERS key\r\n" ] [ [ "key" smembers ] with-string-writer ] unit-test
114
115 #! Hashes
116 [ "HDEL key field\r\n" ] [
117     [ "field" "key" hdel ] with-string-writer
118 ] unit-test
119
120 [ "HEXISTS key field\r\n" ] [
121     [ "field" "key" hexists ] with-string-writer
122 ] unit-test
123
124 [ "HGET key field\r\n" ] [
125     [ "field" "key" hget ] with-string-writer
126 ] unit-test
127
128 [ "HGETALL key\r\n" ] [
129     [ "key" hgetall ] with-string-writer
130 ] unit-test
131
132 [ "HINCRBY key field 1\r\n" ] [
133     [ 1 "field" "key" hincrby ] with-string-writer
134 ] unit-test
135
136 [ "HINCRBYFLOAT key field 1.0\r\n" ] [
137     [ 1.0 "field" "key" hincrbyfloat ] with-string-writer
138 ] unit-test
139
140 [ "HKEYS key\r\n" ] [
141     [ "key" hkeys ] with-string-writer
142 ] unit-test
143
144 [ "HLEN key\r\n" ] [
145     [ "key" hlen ] with-string-writer
146 ] unit-test
147
148 [ "HMGET key field1 field2\r\n" ] [
149     [
150         { "field1" "field2" }
151         "key"
152         hmget
153     ] with-string-writer
154 ] unit-test
155
156 [ "HMSET key field1 value1 field2 value2\r\n" ] [
157     [
158         { { "field1" "value1" } { "field2" "value2" } }
159         "key"
160         hmset
161     ] with-string-writer
162 ] unit-test
163
164 [ "HSET key field value\r\n" ] [
165     [
166         "value"
167         "field"
168         "key"
169         hset
170     ] with-string-writer
171 ] unit-test
172
173 [ "HSETNX key field value\r\n" ] [ [ "value" "field" "key" hsetnx ] with-string-writer ] unit-test
174
175 [ "HVALS key\r\n" ] [ [ "key" hvals ] with-string-writer ] unit-test
176
177 #! Multiple db
178 [ "SELECT 2\r\n" ] [ [ 2 select ] with-string-writer ] unit-test
179
180 [ "MOVE key 2\r\n" ] [ [ 2 "key" move ] with-string-writer ] unit-test
181
182 [ "FLUSHDB\r\n" ] [ [ flushdb ] with-string-writer ] unit-test
183
184 [ "FLUSHALL\r\n" ] [ [ flushall ] with-string-writer ] unit-test
185
186 #! Sorting
187
188 #! Persistence control
189 [ "SAVE\r\n" ] [ [ save ] with-string-writer ] unit-test
190
191 [ "BGSAVE\r\n" ] [ [ bgsave ] with-string-writer ] unit-test
192
193 [ "LASTSAVE\r\n" ] [ [ lastsave ] with-string-writer ] unit-test
194
195 [ "SHUTDOWN\r\n" ] [ [ shutdown ] with-string-writer ] unit-test
196
197 #! Remote server control
198 [ "INFO\r\n" ] [ [ info ] with-string-writer ] unit-test
199
200 [ "MONITOR\r\n" ] [ [ monitor ] with-string-writer ] unit-test