]>
Commit | Line | Data |
---|---|---|
1 | start_server {tags {"scripting"}} { | |
2 | test {EVAL - Does Lua interpreter replies to our requests?} { | |
3 | r eval {return 'hello'} 0 | |
4 | } {hello} | |
5 | ||
6 | test {EVAL - Lua integer -> Redis protocol type conversion} { | |
7 | r eval {return 100.5} 0 | |
8 | } {100} | |
9 | ||
10 | test {EVAL - Lua string -> Redis protocol type conversion} { | |
11 | r eval {return 'hello world'} 0 | |
12 | } {hello world} | |
13 | ||
14 | test {EVAL - Lua true boolean -> Redis protocol type conversion} { | |
15 | r eval {return true} 0 | |
16 | } {1} | |
17 | ||
18 | test {EVAL - Lua false boolean -> Redis protocol type conversion} { | |
19 | r eval {return false} 0 | |
20 | } {} | |
21 | ||
22 | test {EVAL - Lua status code reply -> Redis protocol type conversion} { | |
23 | r eval {return {ok='fine'}} 0 | |
24 | } {fine} | |
25 | ||
26 | test {EVAL - Lua error reply -> Redis protocol type conversion} { | |
27 | catch { | |
28 | r eval {return {err='this is an error'}} 0 | |
29 | } e | |
30 | set _ $e | |
31 | } {this is an error} | |
32 | ||
33 | test {EVAL - Lua table -> Redis protocol type conversion} { | |
34 | r eval {return {1,2,3,'ciao',{1,2}}} 0 | |
35 | } {1 2 3 ciao {1 2}} | |
36 | ||
37 | test {EVAL - Are the KEYS and ARGS arrays populated correctly?} { | |
38 | r eval {return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}} 2 a b c d | |
39 | } {a b c d} | |
40 | ||
41 | test {EVAL - is Lua able to call Redis API?} { | |
42 | r set mykey myval | |
43 | r eval {return redis.call('get','mykey')} 0 | |
44 | } {myval} | |
45 | ||
46 | test {EVALSHA - Can we call a SHA1 if already defined?} { | |
47 | r evalsha 9bd632c7d33e571e9f24556ebed26c3479a87129 0 | |
48 | } {myval} | |
49 | ||
50 | test {EVALSHA - Do we get an error on non defined SHA1?} { | |
51 | catch {r evalsha ffffffffffffffffffffffffffffffffffffffff 0} e | |
52 | set _ $e | |
53 | } {NOSCRIPT*} | |
54 | ||
55 | test {EVAL - Redis integer -> Lua type conversion} { | |
56 | r eval { | |
57 | local foo = redis.call('incr','x') | |
58 | return {type(foo),foo} | |
59 | } 0 | |
60 | } {number 1} | |
61 | ||
62 | test {EVAL - Redis bulk -> Lua type conversion} { | |
63 | r set mykey myval | |
64 | r eval { | |
65 | local foo = redis.call('get','mykey') | |
66 | return {type(foo),foo} | |
67 | } 0 | |
68 | } {string myval} | |
69 | ||
70 | test {EVAL - Redis multi bulk -> Lua type conversion} { | |
71 | r del mylist | |
72 | r rpush mylist a | |
73 | r rpush mylist b | |
74 | r rpush mylist c | |
75 | r eval { | |
76 | local foo = redis.call('lrange','mylist',0,-1) | |
77 | return {type(foo),foo[1],foo[2],foo[3],# foo} | |
78 | } 0 | |
79 | } {table a b c 3} | |
80 | ||
81 | test {EVAL - Redis status reply -> Lua type conversion} { | |
82 | r eval { | |
83 | local foo = redis.call('set','mykey','myval') | |
84 | return {type(foo),foo['ok']} | |
85 | } 0 | |
86 | } {table OK} | |
87 | ||
88 | test {EVAL - Redis error reply -> Lua type conversion} { | |
89 | r set mykey myval | |
90 | r eval { | |
91 | local foo = redis.call('incr','mykey') | |
92 | return {type(foo),foo['err']} | |
93 | } 0 | |
94 | } {table {ERR value is not an integer or out of range}} | |
95 | ||
96 | test {EVAL - Redis nil bulk reply -> Lua type conversion} { | |
97 | r del mykey | |
98 | r eval { | |
99 | local foo = redis.call('get','mykey') | |
100 | return {type(foo),foo == false} | |
101 | } 0 | |
102 | } {boolean 1} | |
103 | ||
104 | test {EVAL - Is Lua affecting the currently selected DB?} { | |
105 | r set mykey "this is DB 9" | |
106 | r select 10 | |
107 | r set mykey "this is DB 10" | |
108 | r eval {return redis.call('get','mykey')} 0 | |
109 | } {this is DB 10} | |
110 | ||
111 | test {EVAL - Is Lua seleced DB retained?} { | |
112 | r eval {return redis.call('select','9')} 0 | |
113 | r get mykey | |
114 | } {this is DB 9} | |
115 | ||
116 | test {EVAL - Script can't run more than configured time limit} { | |
117 | r config set lua-time-limit 1 | |
118 | catch { | |
119 | r eval { | |
120 | local i = 0 | |
121 | while true do i=i+1 end | |
122 | } 0 | |
123 | } e | |
124 | set _ $e | |
125 | } {*execution time*} | |
126 | } | |
127 | ||
128 | start_server {tags {"scripting repl"}} { | |
129 | start_server {} { | |
130 | test {Before the slave connects we issue an EVAL command} { | |
131 | r eval {return redis.call('incr','x')} 0 | |
132 | } {1} | |
133 | ||
134 | test {Connect a slave to the main instance} { | |
135 | r -1 slaveof [srv 0 host] [srv 0 port] | |
136 | after 1000 | |
137 | s -1 role | |
138 | } {slave} | |
139 | ||
140 | test {Now use EVALSHA against the master} { | |
141 | r evalsha ae3477e27be955de7e1bc9adfdca626b478d3cb2 0 | |
142 | } {2} | |
143 | ||
144 | if {$::valgrind} {after 2000} else {after 100} | |
145 | ||
146 | test {If EVALSHA was replicated as EVAL the slave should be ok} { | |
147 | r -1 get x | |
148 | } {2} | |
149 | } | |
150 | } |