Skip to content

Commit 5e3037f

Browse files
DoubleSpoutmembphis
authored andcommitted
1. fix watchdir delete not work (#35)
2. fix readdir kv.key not decode_base64 3. check if kv.value is exist
1 parent 4440ce6 commit 5e3037f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/resty/etcd/v3.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ local encode_base64 = ngx.encode_base64
2020
local decode_base64 = ngx.decode_base64
2121
local INIT_COUNT_RESIZE = 2e8
2222

23-
2423
local _M = {}
2524

2625

@@ -321,6 +320,7 @@ local function get(self, key, attr)
321320
if res.status==200 then
322321
if res.body.kvs and tab_nkeys(res.body.kvs)>0 then
323322
for _, kv in ipairs(res.body.kvs) do
323+
kv.key = decode_base64(kv.key)
324324
kv.value = decode_base64(kv.value)
325325
kv.value = decode_json(kv.value)
326326
end
@@ -446,8 +446,10 @@ local function request_chunk(self, method, host, port, path, opts, timeout)
446446

447447
if body.result.events then
448448
for _, event in ipairs(body.result.events) do
449-
event.kv.value = decode_base64(event.kv.value)
450-
event.kv.value = decode_json(event.kv.value)
449+
if event.kv.value then -- DELETE not have value
450+
event.kv.value = decode_base64(event.kv.value)
451+
event.kv.value = decode_json(event.kv.value)
452+
end
451453
event.kv.key = decode_base64(event.kv.key)
452454
end
453455
end

t/v3/key.t

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ timeout/
174174
etcd:set("/wdir/a", "bcd4a")
175175
end)
176176
177+
ngx.timer.at(0.3, function ()
178+
etcd:delete("/wdir/a")
179+
end)
180+
177181
local cur_time = ngx.now()
178182
local body_chunk_fun, err = etcd:watchdir("/wdir", {timeout = 1.5})
179183
if not body_chunk_fun then
@@ -204,6 +208,7 @@ GET /t
204208
qr/1:.*"created":true.*
205209
2:.*"value":"bcd4".*
206210
3:.*"value":"bcd4a".*
211+
4:.*"type":"DELETE".*
207212
timeout/
208213
--- timeout: 5
209214

0 commit comments

Comments
 (0)