]> gitweb.factorcode.org Git - factor.git/blob - extra/redis/redis-tests.factor
Update redis vocabulary to use the modern protocol
[factor.git] / extra / redis / redis-tests.factor
1 ! Copyright (C) 2014 Benjamin Pollack
2 ! See http://factorcode.org/license.txt for BSD license
3
4 USING: continuations kernel redis math math.parser sequences
5 sorting tools.test ;
6
7 QUALIFIED: redis
8
9 IN: redis.tests
10
11 : with-redis ( quot -- )
12     [ redis-flushdb ] prepose
13     <redis> swap redis:with-redis ; inline
14
15 { -1 } [ [ "foo" redis-decr ] with-redis ] unit-test
16
17 { 1 } [ [ "foo" redis-incr ] with-redis ] unit-test
18
19 { -2 } [
20     [ 2 "foo" redis-decrby ] with-redis
21 ] unit-test
22
23 { 2 } [ [ 2 "foo" redis-incrby ] with-redis ] unit-test
24
25 { "hello" } [
26     [
27         "hello" "foo" redis-set
28         "foo" redis-get
29     ] with-redis
30 ] unit-test
31
32 { { "aa" "ab" "ac" } } [
33     [
34         { "aa" "ab" "ac" "bd" } [ "hello" swap redis-set ] each
35         "a*" redis-keys natural-sort
36     ] with-redis
37 ] unit-test
38
39 { "hello" } [
40     [
41         "world" "hello" redis-set redis-randomkey
42     ] with-redis
43 ] unit-test
44
45 { { "3" "2" "1" } "1" "5" "3" } [
46     [
47         { 1 2 3 } [
48             number>string "list" redis-lpush drop
49         ] each
50         0 -1 "list" redis-lrange
51         "5" 1 "list" redis-lset
52         3 [ "list" redis-rpop ] times
53     ] with-redis
54 ] unit-test
55
56 { { "world" } "1" 2 } [
57     [
58         "1" "world" "hello" redis-hset drop
59         "hello" redis-hkeys
60         "world" "hello" redis-hget
61         1 "world" "hello" redis-hincrby
62     ] with-redis
63 ] unit-test
64
65 { t } [
66     [
67         "world" "hello" redis-set
68         [ "hello" redis-incr ] [ drop t ] recover
69     ] with-redis
70 ] unit-test