Skip to content

Commit

Permalink
doc: how to install the depend library.
Browse files Browse the repository at this point in the history
  • Loading branch information
membphis committed May 8, 2019
1 parent b199cba commit 9e45887
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 74 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ lua-resty-etcd

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

```shell
luarocks install lua-resty-http
```

## Create client object

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

- `option:table`
- `host`: string - default `http://127.0.0.1:2379`
- `ttl`: int - default `-1`
- `ttl`: int - default `-1`
default ttl for key operation. set -1 to disable ttl.
- `prefix`: string
- `prefix`: string
append this prefix path string to key operation url `'/v2/keys'`.
- `timeout`: int
- `timeout`: int
request timeout seconds.


**Returns**

1. `cli`: client object.
2. `err`: error string.
2. `err`: error string.


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


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


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

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

push a value into the specified directory.
push a value into the specified directory.

```lua
local res, err = cli:mkdir('/path/to/dir')
Expand Down
17 changes: 6 additions & 11 deletions t/etcd-dir.t
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
# vim:set ft= ts=4 sw=4 et fdm=marker:

use Test::Nginx::Socket::Lua;
use Test::Nginx::Socket::Lua 'no_plan';

log_level('warn');

repeat_each(2);

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

our $HttpConfig = <<'_EOC_';
lua_socket_log_errors off;
lua_package_path 'lib/?.lua;;';
lua_package_path '/usr/share/lua/5.1/?.lua;lib/?.lua;;';
init_by_lua_block {
function check_res(data, err, val, err_msg, is_dir)
if err then
Expand All @@ -30,17 +25,17 @@ our $HttpConfig = <<'_EOC_';
if err_msg then
if err_msg ~= data.body.message then
ngx.say("failed to check error msg, got:",
ngx.say("failed to check error msg, got:",
data.body.message, ", expect: ", val)
ngx.exit(200)
else
ngx.say("checked error msg as expect: ", err_msg)
end
end
if is_dir then
if not data.body.node.dir then
ngx.say("failed to check dir, got normal file:",
ngx.say("failed to check dir, got normal file:",
data.body.node.dir)
ngx.exit(200)
else
Expand Down Expand Up @@ -213,7 +208,7 @@ checked val as expect: b
local res2, err = etcd:wait("/dir", res.body.node.modifiedIndex + 1, 1)
ngx.say("err: ", err, ", more than 1sec: ", ngx.now() - cur_time > 1)

ngx.timer.at(1, function ()
ngx.timer.at(1, function ()
etcd:set("/dir/a", "a")
end)

Expand Down
16 changes: 5 additions & 11 deletions t/etcd-key.t
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
# vim:set ft= ts=4 sw=4 et fdm=marker:

use Test::Nginx::Socket::Lua;
use Test::Nginx::Socket::Lua 'no_plan';

log_level('warn');

repeat_each(2);

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

our $HttpConfig = <<'_EOC_';
lua_socket_log_errors off;
lua_package_path 'lib/?.lua;;';
lua_package_path '/usr/share/lua/5.1/?.lua;lib/?.lua;;';
init_by_lua_block {
function check_res(data, err, val, err_msg)
if err then
Expand All @@ -30,14 +25,13 @@ our $HttpConfig = <<'_EOC_';
if err_msg then
if err_msg ~= data.body.message then
ngx.say("failed to check error msg, got:",
ngx.say("failed to check error msg, got:",
data.body.message, ", expect: ", val)
ngx.exit(200)
else
ngx.say("checked error msg as expect: ", err_msg)
end
end
end
}
_EOC_
Expand Down Expand Up @@ -138,7 +132,7 @@ checked error msg as expect: Key not found
res, err = etcd:get("/test")
check_res(res, err, "abc")
etcd:delete("/test", "abc")
res, err = etcd:get("/test")
Expand Down Expand Up @@ -232,7 +226,7 @@ checked val as expect: abc
local res2, err = etcd:wait("/test", res.body.node.modifiedIndex + 1, 1)
ngx.say("err: ", err, ", more than 1sec: ", ngx.now() - cur_time > 1)

ngx.timer.at(1, function ()
ngx.timer.at(1, function ()
etcd:set("/test", "bcd")
end)

Expand Down
13 changes: 4 additions & 9 deletions t/etcd-stats.t
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
# vim:set ft= ts=4 sw=4 et fdm=marker:

use Test::Nginx::Socket::Lua;
use Test::Nginx::Socket::Lua 'no_plan';

log_level('warn');

repeat_each(2);

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

our $HttpConfig = <<'_EOC_';
lua_socket_log_errors off;
lua_package_path 'lib/?.lua;;';
lua_package_path '/usr/share/lua/5.1/?.lua;lib/?.lua;;';
init_by_lua_block {
function check_res(data, err)
if err then
Expand Down Expand Up @@ -86,7 +81,7 @@ followers type: table
check_res(res, err)
-- ngx.say(require "cjson" .encode(res.body))
assert(res.body.id)
assert(res.body.startTime)
assert(res.body.leaderInfo)
Expand All @@ -112,7 +107,7 @@ GET /t
check_res(res, err)
-- ngx.log(ngx.WARN, require "cjson" .encode(res.body))
assert(res.body.compareAndSwapFail)
assert(res.body.updateFail)
assert(res.body.getsFail)
Expand Down
10 changes: 3 additions & 7 deletions t/normalize.t
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# vim:set ft= ts=4 sw=4 et fdm=marker:

use Test::Nginx::Socket::Lua;
use Test::Nginx::Socket::Lua 'no_plan';

log_level('warn');

repeat_each(2);

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

our $HttpConfig = <<'_EOC_';
lua_package_path 'lib/?.lua;;';
lua_socket_log_errors off;
lua_package_path '/usr/share/lua/5.1/?.lua;lib/?.lua;;';
_EOC_
run_tests();
Expand Down
56 changes: 26 additions & 30 deletions t/typeof.t
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# vim:set ft= ts=4 sw=4 et fdm=marker:

use Test::Nginx::Socket::Lua;
use Test::Nginx::Socket::Lua 'no_plan';

log_level('warn');

repeat_each(2);

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

our $HttpConfig = <<'_EOC_';
lua_package_path 'lib/?.lua;;';
lua_socket_log_errors off;
lua_package_path '/usr/share/lua/5.1/?.lua;lib/?.lua;;';
_EOC_
run_tests();
Expand Down Expand Up @@ -47,38 +43,38 @@ __DATA__
-- nil
{ chk = {
['nil'] = true,
['non'] = true
['non'] = true
}
},
-- boolean
{ val = true,
chk = {
['boolean'] = true
['boolean'] = true
}
},
{ val = false,
chk = {
['boolean'] = true,
['non'] = true
['non'] = true
}
},
-- string
{ val = 'hello',
chk = {
['string'] = true
['string'] = true
}
},
{ val = 'world',
chk = {
['string'] = true
['string'] = true
}
},
{ val = '',
chk = {
['string'] = true,
['non'] = true
['non'] = true
}
},
Expand All @@ -96,7 +92,7 @@ __DATA__
['uint8'] = true,
['uint16'] = true,
['uint32'] = true,
['non'] = true
['non'] = true
}
},
{ val = 1,
Expand Down Expand Up @@ -128,28 +124,28 @@ __DATA__
chk = {
['number'] = true,
['finite'] = true,
['unsigned']= true
['unsigned']= true
}
},
{ val = -0.1,
chk = {
['number'] = true,
['finite'] = true
['finite'] = true
}
},
{ val = 1/0,
chk = {
['number'] = true
['number'] = true
}
},
{ val = 0/0,
chk = {
['number'] = true,
['nan'] = true,
['non'] = true
['non'] = true
}
},
-- integer
{ val = -128,
chk = {
Expand All @@ -158,7 +154,7 @@ __DATA__
['int'] = true,
['int8'] = true,
['int16'] = true,
['int32'] = true
['int32'] = true
}
},
{ val = 127,
Expand Down Expand Up @@ -203,7 +199,7 @@ __DATA__
['number'] = true,
['finite'] = true,
['int'] = true,
['int32'] = true
['int32'] = true
}
},
{ val = 2147483647,
Expand All @@ -229,7 +225,7 @@ __DATA__
['uint'] = true,
['uint8'] = true,
['uint16'] = true,
['uint32'] = true
['uint32'] = true
}
},
{ val = 65535,
Expand All @@ -251,35 +247,35 @@ __DATA__
['unsigned']= true,
['int'] = true,
['uint'] = true,
['uint32'] = true
['uint32'] = true
}
},
-- function
{ val = function()end,
chk = {
['Function']= true
['Function']= true
}
},
-- table
{ val = {},
chk = {
['table'] = true
['table'] = true
}
},
-- thread
{ val = coroutine.create(function() end),
chk = {
['thread'] = true
['thread'] = true
}
}
}
local nilVal
local msg
for _, field in ipairs(data) do
for _, field in ipairs(data) do
for method, res in pairs(DEFAULT_CMP) do
if field.chk[method] ~= nil then
res = field.chk[method]
Expand Down

0 comments on commit 9e45887

Please sign in to comment.