openresty / openresty/lua-resty-redis
Bad Request : in function 'send'
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 2k
- Forks
- 447
- Avg merge
- 2h 24m
- Merged PRs (30d)
- 3
Description
@agentzh Hope you are doing great :),
I followed your comments and the issues you have solved for #44 and #104.
But am still getting the same issue, for sure its because of my poor understanding and apologise for the same in advance.
But am struggling to understand "resty.redis" part in the comment which you have mentioned in all the issues.
Below is the snippet of My Code which i tried and am still facing the issue.
Problem : I want to calculate the time redis takes to connect and do operation if its more than
0.100 i log it. To do that, i have overridden every method (Sharing only two here - new & get | And i Know there must be some better approach than this would love to know that too ).
- redis_extended.lua
local redis_import = require "resty.redis"
local red_mod = {}
function red_mod:new(o, ngx)
o = o or {}
setmetatable(o, self) -- http://lua-users.org/wiki/MetamethodsTutorial
self.__index = self
self.ngx = ngx
self.redis = redis_import:new()
return o
end
function red_mod:get(key)
local start_time = self.ngx.now()
-- local redis = require "resty.redis"
> if i uncomment above line and use below redis:get instead of self.get
> everything works fine
> (this is what i think from initial steps and am getting more confused
> because of this cause at this point am not even initialising the object)
local ok, err = self.redis:get(key)
local end_time = self.ngx.now() - start_time
if end_time > 0.100 then
self.ngx.log(self.ngx.ERR, "!@@! Execution Time for REDIS:GET Operation :- ", end_time)
end
return ok, err
end
return red_mod
And am calling this in the other modules, which is part of nginx co-routine. So if above code is used in one module it doesnt break as soon as i use this in other modules it fails.
local redis = require "eg-modules.redis_extended"
local red = redis:new(nil, ngx)
red:set_timeout(1000) -- 1 sec
local ok, err = red:connect(redis_health_check_host, redis_health_check_port)
if not ok then
ngx.log(ngx.ERR,"failed to connect: ", err)
return
end
local key = module.get_request_key(http_x_egnyte_request_id)
**-- Thing breaks here, in Get call**
local ok, err = red:get(key .. '.bck')
Everything works until the red:get call arrives, and at this point it throws the error.
It will be great help, if you can point out in the code where i am going wrong.
And on how to achieve this using any code snippet :-
Never ever share any cosocket objects (or any objects wrapping cosockets, like resty.redis objects) across the request handler boundary!
Out of Context-
And to have understanding of nginx in depth & lua (so that i dont ask such dumb questions) can you share in links (books, videos, docs).
Thanks a lot in advance :) .
Originally posted by @rushi47 in https://github.com/openresty/lua-resty-redis/issues/165#issuecomment-582836250
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with redis_extended.lua and the resty.redis entry point, then trace the red:new, red:connect, and red:get calls shown in the issue. Compare the wrapper's object lifecycle with the usage in the other nginx coroutine modules and review the related discussions in issues #44 and #104. Done means the failure at red:get is explained and a reproducible, supported usage pattern is identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua, redis
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100