openresty / lua-resty-redis

Lua redis client driver for the ngx_lua based on the cosocket API
1.9k stars 449 forks source link

red:smembers("key"), sometime not include the new member? #277

Open yuchao-java opened 3 months ago

yuchao-java commented 3 months ago

in my kong lua scripts, I write some code in access function like this: local redis = require "resty.redis" local red = redis:new() red:set_timeouts(5000, 5000, 5000) local ok, err = red:connect(redisHost, redisPort) local result, err = red:smembers("all_allow_urls") local ok, keep_err = red:set_keepalive(10000, 100) at first, the key "all_allow_urls" in redis is a set, which include 10 members, then I execute SADD all_allow_urls 'aaa' in redis-cli cmd; but when I visit my kong to check the result from red:smembers("all_allow_urls"), it sometimes include "aaa" but sometimes not。 Can you help me?

yuchao-java commented 3 months ago

the same question, after I execute set key1 value1 in redis-cli cmd, local result2, err =red:get("key1"), the result2 is userdata: NULL when the red.get_reused_times() > 1, and the result2 is aaa when the red.get_reused_times() == 0. How to get new data in redis when the data is changed?

zhuizhuhaomeng commented 3 months ago

Use tcpdump to capture the packets. And then use wireshark to look into this issue.

yuchao-java commented 3 months ago

Even if rebooting redis and kong doesn't work, the problem remains, do you have some quick solutions? thx

yuchao-java commented 3 months ago

Use tcpdump to capture the packets. And then use wireshark to look into this issue.

The tcp stream that I captured by using kong to operate redis through lua-resty-redis. For the first time, 44 data are normally obtained in the set whose key is api:all_allow_urls, scard it also displays 44 data, and the content of string whose key is bbb is 0000. When the connection is put back into the connection pool and reused to read again, the set contains only 37 data and the contents of the bbb are empty. [Uploading redis_tcp_stream.log…]()

See attachment for details, Please!

zhuizhuhaomeng commented 2 months ago

can't find the attachment @yuchao-java

yuchao-java commented 2 months ago

redis_tcp_stream.log sorry, maybe something wrong, here