summaryrefslogtreecommitdiff
path: root/lua-resty-redis-0.31/t/module.t
blob: 4c3806063efad060b2c3524a30d1f8c40f98e7e5 (plain)
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
# vim:set ft= ts=4 sw=4 et:

use t::Test;

repeat_each(2);

plan tests => repeat_each() * (3 * blocks());

run_tests();

__DATA__

=== TEST 1: sanity
--- global_config eval: $::GlobalConfig
--- server_config
        content_by_lua_block {
            local cjson = require "cjson"
            local redis = require "resty.redis"
            redis.register_module_prefix("bf")
            redis.register_module_prefix("test")

            local red = redis:new()

            local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
            if not ok then
                ngx.say("failed to connect: ", err)
                return
            end

            local res, err = red:del("module_1")
            if not res then
                ngx.say(err)
                return
            end

            res, err = red:bf():add("module_1", 1)
            if not res then
                ngx.say(err)
                return
            end
            ngx.say("receive: ", cjson.encode(res))

            res, err = red:bf():exists("module_1", 1)
            if not res then
                ngx.say(err)
                return
            end
            ngx.say("receive: ", cjson.encode(res))

            -- call normal command
            res, err = red:del("module_1")
            if not res then
                ngx.say(err)
                return
            end
            ngx.say("receive: ", cjson.encode(res))

            -- call cached 'exists' again
            res, err = red:exists("module_1")
            if not res then
                ngx.say(err)
                return
            end
            ngx.say("receive: ", cjson.encode(res))

            -- call pre-created 'get' method
            res, err = red:test():get()
            if not res then
                ngx.say(err)
            end

            red:close()
        }
--- response_body eval
qr/receive: 1
receive: 1
receive: 1
receive: 0
ERR unknown command [`']test.get['`].+
/ms
--- no_error_log
[error]