Closed vampire007 closed 6 years ago
@vampire007 I don't see you ever set the key dog
in your example above. You are getting nil just because that key does not exist (unless other errors happen).
I added a set()
call to your example, and it works fine on my side:
location /t {
content_by_lua_block {
local memcached = require "resty.memcached"
local memc, err = memcached:new()
if not memc then
ngx.say("failed to instantiate memc: ", err)
return
end
memc:set_timeout(1000)
local ok, err = memc:connect("127.0.0.1", 11211)
if not ok then
ngx.say("failed to connect: ", err)
return
end
memc:set("dog", 32)
local value, flags, err = memc:get("dog")
if not value then
memc:set("dog", 1)
ngx.say("failed to get dog ", err)
return
end
-- get key's token
local data, flags, token, err = memc:gets("dog")
if not token then
ngx.say("failed to get token")
return
end
ngx.say("token: ", token)
local ok, err = memc:cas("dog", data + 1, token)
if not ok then
ngx.say("failed to set dog ", err)
return
end
local res, flags, err = memc:get("dog")
if not res then
ngx.say("failed to get dog ", err)
return
end
ngx.say("dog: ", res)
}
}
To test this /t
:
$ curl localhost:8080/t
token: 704
dog: 33
Hey, I got a problem... Maybe it's stupid, but I don't know where to find help, so created this issue. Why do I always get nil value by the gets method? Here is the code which copied from your demo.