]> gitweb.factorcode.org Git - factor.git/blob - extra/redis/redis-tests.factor
feature(redis): lua script words
[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 IN: redis.tests
8
9 : with-redis-test ( quot -- )
10     [ redis-flushdb ] prepose
11     <redis> swap with-redis ; inline
12
13 { -1 } [ [ "foo" redis-decr ] with-redis-test ] unit-test
14
15 { 1 } [ [ "foo" redis-incr ] with-redis-test ] unit-test
16
17 { -2 } [
18     [ 2 "foo" redis-decrby ] with-redis-test
19 ] unit-test
20
21 { 2 } [ [ 2 "foo" redis-incrby ] with-redis-test ] unit-test
22
23 { "hello" } [
24     [
25         "hello" "foo" redis-set
26         "foo" redis-get
27     ] with-redis-test
28 ] unit-test
29
30 { { "aa" "ab" "ac" } } [
31     [
32         { "aa" "ab" "ac" "bd" } [ "hello" swap redis-set ] each
33         "a*" redis-keys natural-sort
34     ] with-redis-test
35 ] unit-test
36
37 { "hello" } [
38     [
39         "world" "hello" redis-set redis-randomkey
40     ] with-redis-test
41 ] unit-test
42
43 { { "3" "2" "1" } "1" "5" "3" } [
44     [
45         { 1 2 3 } [
46             number>string "list" redis-lpush drop
47         ] each
48         0 -1 "list" redis-lrange
49         "5" 1 "list" redis-lset
50         3 [ "list" redis-rpop ] times
51     ] with-redis-test
52 ] unit-test
53
54 { { "world" } "1" 2 } [
55     [
56         "1" "world" "hello" redis-hset drop
57         "hello" redis-hkeys
58         "world" "hello" redis-hget
59         1 "world" "hello" redis-hincrby
60     ] with-redis-test
61 ] unit-test
62
63 { t } [
64     [
65         "world" "hello" redis-set
66         [ "hello" redis-incr ] [ drop t ] recover
67     ] with-redis-test
68 ] unit-test
69
70 { "e0e1f9fabfc9d4800c877a703b823ac0578ff8db" } [
71     [ "return 1" redis-script-load ] with-redis-test
72 ] unit-test
73
74 { { 0 0 } } [
75     [ { "foo" "bar" } redis-script-exists ] with-redis-test
76 ] unit-test
77
78 { } [ [ redis-script-flush ] with-redis-test ] unit-test
79
80 { { "foo" } } [
81     [ "return { ARGV[1] }" { } { "foo" } redis-script-eval ] with-redis-test
82 ] unit-test