Skip to content

Commit 9e45887

Browse files
committed
doc: how to install the depend library.
1 parent b199cba commit 9e45887

File tree

6 files changed

+54
-74
lines changed

6 files changed

+54
-74
lines changed

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ lua-resty-etcd
99

1010
- lua-resty-http: https://github.com/ledgetech/lua-resty-http
1111

12+
```shell
13+
luarocks install lua-resty-http
14+
```
15+
1216
## Create client object
1317

1418
#### cli, err = Etcd.new([option:table])
@@ -21,18 +25,18 @@ local cli, err = require('resty.etcd').new()
2125

2226
- `option:table`
2327
- `host`: string - default `http://127.0.0.1:2379`
24-
- `ttl`: int - default `-1`
28+
- `ttl`: int - default `-1`
2529
default ttl for key operation. set -1 to disable ttl.
26-
- `prefix`: string
30+
- `prefix`: string
2731
append this prefix path string to key operation url `'/v2/keys'`.
28-
- `timeout`: int
32+
- `timeout`: int
2933
request timeout seconds.
3034

3135

3236
**Returns**
3337

3438
1. `cli`: client object.
35-
2. `err`: error string.
39+
2. `err`: error string.
3640

3741

3842
## About the return values of client methods.
@@ -48,7 +52,7 @@ a `HTTP Response Entity` contains the following fields except `408` timeout stat
4852
**Note:** a client method will decode a response body as a JSON string if a `Content-Type` response header value is a `application/json`.
4953

5054

51-
please refer the **etcd API documentaion** at - https://github.com/coreos/etcd for more details of a response entity.
55+
please refer the **etcd API documentaion** at - https://github.com/coreos/etcd for more details of a response entity.
5256

5357

5458
## Key-value operations
@@ -224,7 +228,7 @@ local res, err = cli:waitdir('/path/to/dir')
224228

225229
#### res, err = cli:push(key:string, val:JSON encodable value [, ttl:int])
226230

227-
push a value into the specified directory.
231+
push a value into the specified directory.
228232

229233
```lua
230234
local res, err = cli:mkdir('/path/to/dir')

t/etcd-dir.t

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
# vim:set ft= ts=4 sw=4 et fdm=marker:
2-
3-
use Test::Nginx::Socket::Lua;
1+
use Test::Nginx::Socket::Lua 'no_plan';
42

53
log_level('warn');
6-
74
repeat_each(2);
85

9-
plan tests => repeat_each() * (blocks() * 3);
10-
116
our $HttpConfig = <<'_EOC_';
127
lua_socket_log_errors off;
13-
lua_package_path 'lib/?.lua;;';
8+
lua_package_path '/usr/share/lua/5.1/?.lua;lib/?.lua;;';
149
init_by_lua_block {
1510
function check_res(data, err, val, err_msg, is_dir)
1611
if err then
@@ -30,17 +25,17 @@ our $HttpConfig = <<'_EOC_';
3025
3126
if err_msg then
3227
if err_msg ~= data.body.message then
33-
ngx.say("failed to check error msg, got:",
28+
ngx.say("failed to check error msg, got:",
3429
data.body.message, ", expect: ", val)
3530
ngx.exit(200)
3631
else
3732
ngx.say("checked error msg as expect: ", err_msg)
3833
end
3934
end
40-
35+
4136
if is_dir then
4237
if not data.body.node.dir then
43-
ngx.say("failed to check dir, got normal file:",
38+
ngx.say("failed to check dir, got normal file:",
4439
data.body.node.dir)
4540
ngx.exit(200)
4641
else
@@ -213,7 +208,7 @@ checked val as expect: b
213208
local res2, err = etcd:wait("/dir", res.body.node.modifiedIndex + 1, 1)
214209
ngx.say("err: ", err, ", more than 1sec: ", ngx.now() - cur_time > 1)
215210

216-
ngx.timer.at(1, function ()
211+
ngx.timer.at(1, function ()
217212
etcd:set("/dir/a", "a")
218213
end)
219214

t/etcd-key.t

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
# vim:set ft= ts=4 sw=4 et fdm=marker:
2-
3-
use Test::Nginx::Socket::Lua;
1+
use Test::Nginx::Socket::Lua 'no_plan';
42

53
log_level('warn');
6-
74
repeat_each(2);
85

9-
plan tests => repeat_each() * (blocks() * 3);
10-
116
our $HttpConfig = <<'_EOC_';
127
lua_socket_log_errors off;
13-
lua_package_path 'lib/?.lua;;';
8+
lua_package_path '/usr/share/lua/5.1/?.lua;lib/?.lua;;';
149
init_by_lua_block {
1510
function check_res(data, err, val, err_msg)
1611
if err then
@@ -30,14 +25,13 @@ our $HttpConfig = <<'_EOC_';
3025
3126
if err_msg then
3227
if err_msg ~= data.body.message then
33-
ngx.say("failed to check error msg, got:",
28+
ngx.say("failed to check error msg, got:",
3429
data.body.message, ", expect: ", val)
3530
ngx.exit(200)
3631
else
3732
ngx.say("checked error msg as expect: ", err_msg)
3833
end
3934
end
40-
4135
end
4236
}
4337
_EOC_
@@ -138,7 +132,7 @@ checked error msg as expect: Key not found
138132
139133
res, err = etcd:get("/test")
140134
check_res(res, err, "abc")
141-
135+
142136
etcd:delete("/test", "abc")
143137
144138
res, err = etcd:get("/test")
@@ -232,7 +226,7 @@ checked val as expect: abc
232226
local res2, err = etcd:wait("/test", res.body.node.modifiedIndex + 1, 1)
233227
ngx.say("err: ", err, ", more than 1sec: ", ngx.now() - cur_time > 1)
234228

235-
ngx.timer.at(1, function ()
229+
ngx.timer.at(1, function ()
236230
etcd:set("/test", "bcd")
237231
end)
238232

t/etcd-stats.t

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
# vim:set ft= ts=4 sw=4 et fdm=marker:
2-
3-
use Test::Nginx::Socket::Lua;
1+
use Test::Nginx::Socket::Lua 'no_plan';
42

53
log_level('warn');
6-
74
repeat_each(2);
85

9-
plan tests => repeat_each() * (blocks() * 3);
10-
116
our $HttpConfig = <<'_EOC_';
127
lua_socket_log_errors off;
13-
lua_package_path 'lib/?.lua;;';
8+
lua_package_path '/usr/share/lua/5.1/?.lua;lib/?.lua;;';
149
init_by_lua_block {
1510
function check_res(data, err)
1611
if err then
@@ -86,7 +81,7 @@ followers type: table
8681
check_res(res, err)
8782
8883
-- ngx.say(require "cjson" .encode(res.body))
89-
84+
9085
assert(res.body.id)
9186
assert(res.body.startTime)
9287
assert(res.body.leaderInfo)
@@ -112,7 +107,7 @@ GET /t
112107
check_res(res, err)
113108
114109
-- ngx.log(ngx.WARN, require "cjson" .encode(res.body))
115-
110+
116111
assert(res.body.compareAndSwapFail)
117112
assert(res.body.updateFail)
118113
assert(res.body.getsFail)

t/normalize.t

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
# vim:set ft= ts=4 sw=4 et fdm=marker:
2-
3-
use Test::Nginx::Socket::Lua;
1+
use Test::Nginx::Socket::Lua 'no_plan';
42

53
log_level('warn');
6-
74
repeat_each(2);
85

9-
plan tests => repeat_each() * (blocks() * 3);
10-
116
our $HttpConfig = <<'_EOC_';
12-
lua_package_path 'lib/?.lua;;';
7+
lua_socket_log_errors off;
8+
lua_package_path '/usr/share/lua/5.1/?.lua;lib/?.lua;;';
139
_EOC_
1410
1511
run_tests();

t/typeof.t

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
# vim:set ft= ts=4 sw=4 et fdm=marker:
2-
3-
use Test::Nginx::Socket::Lua;
1+
use Test::Nginx::Socket::Lua 'no_plan';
42

53
log_level('warn');
6-
74
repeat_each(2);
85

9-
plan tests => repeat_each() * (blocks() * 3);
10-
116
our $HttpConfig = <<'_EOC_';
12-
lua_package_path 'lib/?.lua;;';
7+
lua_socket_log_errors off;
8+
lua_package_path '/usr/share/lua/5.1/?.lua;lib/?.lua;;';
139
_EOC_
1410
1511
run_tests();
@@ -47,38 +43,38 @@ __DATA__
4743
-- nil
4844
{ chk = {
4945
['nil'] = true,
50-
['non'] = true
46+
['non'] = true
5147
}
5248
},
5349
5450
-- boolean
5551
{ val = true,
5652
chk = {
57-
['boolean'] = true
53+
['boolean'] = true
5854
}
5955
},
6056
{ val = false,
6157
chk = {
6258
['boolean'] = true,
63-
['non'] = true
59+
['non'] = true
6460
}
6561
},
6662
6763
-- string
6864
{ val = 'hello',
6965
chk = {
70-
['string'] = true
66+
['string'] = true
7167
}
7268
},
7369
{ val = 'world',
7470
chk = {
75-
['string'] = true
71+
['string'] = true
7672
}
7773
},
7874
{ val = '',
7975
chk = {
8076
['string'] = true,
81-
['non'] = true
77+
['non'] = true
8278
}
8379
},
8480
@@ -96,7 +92,7 @@ __DATA__
9692
['uint8'] = true,
9793
['uint16'] = true,
9894
['uint32'] = true,
99-
['non'] = true
95+
['non'] = true
10096
}
10197
},
10298
{ val = 1,
@@ -128,28 +124,28 @@ __DATA__
128124
chk = {
129125
['number'] = true,
130126
['finite'] = true,
131-
['unsigned']= true
127+
['unsigned']= true
132128
}
133129
},
134130
{ val = -0.1,
135131
chk = {
136132
['number'] = true,
137-
['finite'] = true
133+
['finite'] = true
138134
}
139135
},
140136
{ val = 1/0,
141137
chk = {
142-
['number'] = true
138+
['number'] = true
143139
}
144140
},
145141
{ val = 0/0,
146142
chk = {
147143
['number'] = true,
148144
['nan'] = true,
149-
['non'] = true
145+
['non'] = true
150146
}
151147
},
152-
148+
153149
-- integer
154150
{ val = -128,
155151
chk = {
@@ -158,7 +154,7 @@ __DATA__
158154
['int'] = true,
159155
['int8'] = true,
160156
['int16'] = true,
161-
['int32'] = true
157+
['int32'] = true
162158
}
163159
},
164160
{ val = 127,
@@ -203,7 +199,7 @@ __DATA__
203199
['number'] = true,
204200
['finite'] = true,
205201
['int'] = true,
206-
['int32'] = true
202+
['int32'] = true
207203
}
208204
},
209205
{ val = 2147483647,
@@ -229,7 +225,7 @@ __DATA__
229225
['uint'] = true,
230226
['uint8'] = true,
231227
['uint16'] = true,
232-
['uint32'] = true
228+
['uint32'] = true
233229
}
234230
},
235231
{ val = 65535,
@@ -251,35 +247,35 @@ __DATA__
251247
['unsigned']= true,
252248
['int'] = true,
253249
['uint'] = true,
254-
['uint32'] = true
250+
['uint32'] = true
255251
}
256252
},
257-
253+
258254
-- function
259255
{ val = function()end,
260256
chk = {
261-
['Function']= true
257+
['Function']= true
262258
}
263259
},
264-
260+
265261
-- table
266262
{ val = {},
267263
chk = {
268-
['table'] = true
264+
['table'] = true
269265
}
270266
},
271-
267+
272268
-- thread
273269
{ val = coroutine.create(function() end),
274270
chk = {
275-
['thread'] = true
271+
['thread'] = true
276272
}
277273
}
278274
}
279275
local nilVal
280276
local msg
281277
282-
for _, field in ipairs(data) do
278+
for _, field in ipairs(data) do
283279
for method, res in pairs(DEFAULT_CMP) do
284280
if field.chk[method] ~= nil then
285281
res = field.chk[method]

0 commit comments

Comments
 (0)