Giter Club home page Giter Club logo

Comments (7)

agentzh avatar agentzh commented on September 4, 2024

@djhalaninext Your code has a great risk of entering an infinite tight loop (thus maxing out CPU without doing anything good) when the read_reply() returns an error other than "read timeout", like "close" (when redis closes the connection prematurely). Always be VERY careful about while true loops.

from lua-resty-redis.

agentzh avatar agentzh commented on September 4, 2024

@djhalaninext Also, set_keepalive puts the underlying connection into the connection pool and shuts down the current resty.redis object and I don't think you want that upon every loop iteration. Better read the official documentation more carefully.

from lua-resty-redis.

agentzh avatar agentzh commented on September 4, 2024

@djhalaninext Another thing is that it's better to put require() on the top level of your Lua module instead of calling it everytime your function is called. require cannot be JIT compiled and it does not make sense to call it over and over again.

from lua-resty-redis.

agentzh avatar agentzh commented on September 4, 2024

@djhalaninext Always handle the errors of those resty.redis calls carefully in Lua, including set_keepalive and read_reply.

from lua-resty-redis.

agentzh avatar agentzh commented on September 4, 2024

@djhalaninext For redis subscribing, it's normal to get the read timeout error, which is not fatal at all. You just need to try read_reply again on the same resty.redis object. But as I've mentioned above, you MUST handle any other errors explicity without retrying read_reply blindly over and over again. Because for other fatal errors, any subsequent read_reply call will always return the "closed" error immediately, leading to hot tight looping in your example.

from lua-resty-redis.

agentzh avatar agentzh commented on September 4, 2024

@djhalaninext BTW, please use the openresty-en mailing list for such general discussions instead. Thank you for your cooperation! Please see http://openresty.org/#Community

from lua-resty-redis.

djhalaninext avatar djhalaninext commented on September 4, 2024

@agentzh Thanks for all the input. Will fix and post more questions in openresty-en mailing list.

from lua-resty-redis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.