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
7 [ "QUIT\r\n" ] [ [ quit ] with-string-writer ] unit-test
9 [ "PING\r\n" ] [ [ ping ] with-string-writer ] unit-test
11 [ "AUTH password\r\n" ] [ [ "password" auth ] with-string-writer ] unit-test
14 [ "SET key 3\r\nfoo\r\n" ] [ [ "foo" "key" set ] with-string-writer ] unit-test
16 [ "GET key\r\n" ] [ [ "key" get ] with-string-writer ] unit-test
18 [ "GETSET key 3\r\nfoo\r\n" ] [
19 [ "foo" "key" getset ] with-string-writer
22 [ "MGET key1 key2 key3\r\n" ] [
23 [ { "key1" "key2" "key3" } mget ] with-string-writer
26 [ "SETNX key 3\r\nfoo\r\n" ] [
27 [ "foo" "key" setnx ] with-string-writer
30 [ "INCR key\r\n" ] [ [ "key" incr ] with-string-writer ] unit-test
32 [ "INCRBY key 7\r\n" ] [ [ 7 "key" incrby ] with-string-writer ] unit-test
34 [ "DECR key\r\n" ] [ [ "key" decr ] with-string-writer ] unit-test
36 [ "DECRBY key 7\r\n" ] [ [ 7 "key" decrby ] with-string-writer ] unit-test
38 [ "EXISTS key\r\n" ] [ [ "key" exists ] with-string-writer ] unit-test
40 [ "DEL key\r\n" ] [ [ "key" del ] with-string-writer ] unit-test
42 [ "TYPE key\r\n" ] [ [ "key" type ] with-string-writer ] unit-test
45 [ "KEYS pat*\r\n" ] [ [ "pat*" keys ] with-string-writer ] unit-test
47 [ "RANDOMKEY\r\n" ] [ [ randomkey ] with-string-writer ] unit-test
49 [ "RENAME key newkey\r\n" ] [
50 [ "newkey" "key" rename ] with-string-writer
53 [ "RENAMENX key newkey\r\n" ] [
54 [ "newkey" "key" renamenx ] with-string-writer
57 [ "DBSIZE\r\n" ] [ [ dbsize ] with-string-writer ] unit-test
59 [ "EXPIRE key 7\r\n" ] [ [ 7 "key" expire ] with-string-writer ] unit-test
62 [ "RPUSH key 3\r\nfoo\r\n" ] [ [ "foo" "key" rpush ] with-string-writer ] unit-test
64 [ "LPUSH key 3\r\nfoo\r\n" ] [ [ "foo" "key" lpush ] with-string-writer ] unit-test
66 [ "LLEN key\r\n" ] [ [ "key" llen ] with-string-writer ] unit-test
68 [ "LRANGE key 5 9\r\n" ] [ [ 5 9 "key" lrange ] with-string-writer ] unit-test
70 [ "LTRIM key 5 9\r\n" ] [ [ 5 9 "key" ltrim ] with-string-writer ] unit-test
72 [ "LINDEX key 7\r\n" ] [ [ 7 "key" lindex ] with-string-writer ] unit-test
74 [ "LSET key 0 3\r\nfoo\r\n" ] [ [ "foo" 0 "key" lset ] with-string-writer ] unit-test
76 [ "LREM key 1 3\r\nfoo\r\n" ] [ [ "foo" 1 "key" lrem ] with-string-writer ] unit-test
78 [ "LPOP key\r\n" ] [ [ "key" lpop ] with-string-writer ] unit-test
80 [ "RPOP key\r\n" ] [ [ "key" rpop ] with-string-writer ] unit-test
83 [ "SADD key 3\r\nfoo\r\n" ] [ [ "foo" "key" sadd ] with-string-writer ] unit-test
85 [ "SREM key 3\r\nfoo\r\n" ] [ [ "foo" "key" srem ] with-string-writer ] unit-test
87 [ "SMOVE srckey dstkey 3\r\nfoo\r\n" ] [
88 [ "foo" "dstkey" "srckey" smove ] with-string-writer
91 [ "SCARD key\r\n" ] [ [ "key" scard ] with-string-writer ] unit-test
93 [ "SISMEMBER key 3\r\nfoo\r\n" ] [
94 [ "foo" "key" sismember ] with-string-writer
97 [ "SINTER key1 key2 key3\r\n" ] [
98 [ { "key1" "key2" "key3" } sinter ] with-string-writer
101 [ "SINTERSTORE dstkey key1 key2 key3\r\n" ] [
102 [ { "key1" "key2" "key3" } "dstkey" sinterstore ] with-string-writer
105 [ "SUNION key1 key2 key3\r\n" ] [
106 [ { "key1" "key2" "key3" } sunion ] with-string-writer
109 [ "SUNIONSTORE dstkey key1 key2 key3\r\n" ] [
110 [ { "key1" "key2" "key3" } "dstkey" sunionstore ] with-string-writer
113 [ "SMEMBERS key\r\n" ] [ [ "key" smembers ] with-string-writer ] unit-test
116 [ "HDEL key field\r\n" ] [
117 [ "field" "key" hdel ] with-string-writer
120 [ "HEXISTS key field\r\n" ] [
121 [ "field" "key" hexists ] with-string-writer
124 [ "HGET key field\r\n" ] [
125 [ "field" "key" hget ] with-string-writer
128 [ "HGETALL key\r\n" ] [
129 [ "key" hgetall ] with-string-writer
132 [ "HINCRBY key field 1\r\n" ] [
133 [ 1 "field" "key" hincrby ] with-string-writer
136 [ "HINCRBYFLOAT key field 1.0\r\n" ] [
137 [ 1.0 "field" "key" hincrbyfloat ] with-string-writer
140 [ "HKEYS key\r\n" ] [
141 [ "key" hkeys ] with-string-writer
145 [ "key" hlen ] with-string-writer
148 [ "HMGET key field1 field2\r\n" ] [
150 { "field1" "field2" }
156 [ "HMSET key field1 value1 field2 value2\r\n" ] [
158 { { "field1" "value1" } { "field2" "value2" } }
164 [ "HSET key field value\r\n" ] [
173 [ "HSETNX key field value\r\n" ] [ [ "value" "field" "key" hsetnx ] with-string-writer ] unit-test
175 [ "HVALS key\r\n" ] [ [ "key" hvals ] with-string-writer ] unit-test
178 [ "SELECT 2\r\n" ] [ [ 2 select ] with-string-writer ] unit-test
180 [ "MOVE key 2\r\n" ] [ [ 2 "key" move ] with-string-writer ] unit-test
182 [ "FLUSHDB\r\n" ] [ [ flushdb ] with-string-writer ] unit-test
184 [ "FLUSHALL\r\n" ] [ [ flushall ] with-string-writer ] unit-test
188 #! Persistence control
189 [ "SAVE\r\n" ] [ [ save ] with-string-writer ] unit-test
191 [ "BGSAVE\r\n" ] [ [ bgsave ] with-string-writer ] unit-test
193 [ "LASTSAVE\r\n" ] [ [ lastsave ] with-string-writer ] unit-test
195 [ "SHUTDOWN\r\n" ] [ [ shutdown ] with-string-writer ] unit-test
197 #! Remote server control
198 [ "INFO\r\n" ] [ [ info ] with-string-writer ] unit-test
200 [ "MONITOR\r\n" ] [ [ monitor ] with-string-writer ] unit-test