Comments (4)
你应当使用 ngx.req.read_body(), ngx.req.get_body_data() 和 ngx.req.get_body_file() 来读取请求体。另一种选择是使用 ngx.req.socket().
你上面的代码并没有读取请求体数据。引用 $echo_request_body 变量并不会自动触发请求体读取操作。
from lua-resty-redis.
感谢回复!
如果我在content_by_lua
前面加proxy_pass
是否就可以使 $echo_request_body 变量赋值?
from lua-resty-redis.
加入了请求读取操作,请帮忙再看一下:
location /from_proxy {
proxy_pass http://backend;
}
location /to_redis {
default_type text/html;
set $key $url;
set $exptime 300;
content_by_lua '
local res = ngx.location.capture("/from_proxy", {
method = ngx.HTTP_GET,
body = ngx.req.get_body_data()})
local redis = require "resty.redis"
local red = redis:new()
red:set_timeout(1000)
local ok, err = red:connect("127.0.0.1", 6379)
if not ok then
return nil
end
local ok, err = red:set(ngx.var.key,ngx.var.res.body,ngx.var.exptime)
if not ok then
return nil
end
red:close()
';
}
from lua-resty-redis.
Hello!
On Mon, Oct 22, 2012 at 10:42 PM, LazyZhu [email protected] wrote:
加入了请求体读取操作,请帮忙再看一下:
location /proxy_request {
proxy_pass http://backend;
}location /toredis {
default_type text/html;
set $key $url;
set $exptime 300;
content_by_lua 'local res = ngx.location.capture("/proxy_request", { body = ngx.req.get_body_data()})
你这里并没有如你说的那样加入请求体读取操作。ngx.req.read_body() 才是请求体读取操作:
http://wiki.nginx.org/HttpLuaModule#ngx.req.read_body
你调用 ngx.req.get_body_data() 和读取 $echo_request_body 变量的效果几乎是完全相同的。
-agentzh
from lua-resty-redis.
Related Issues (20)
- SSL not working
- The performance of redis pipeline mode is unstable HOT 3
- CLIENT SETNAME?
- redis:get(key) question HOT 2
- opm package outdated HOT 1
- Connection pool not creating HOT 2
- How to create a single redis connection HOT 5
- this support two-way authentication?
- Add keepalive for redis client to make the connections reliable
- Nginx 1.24 HOT 2
- Nginx creates more connection than poolsize, backlog to redis HOT 5
- lua tcp socket read timed out, context: ssl_certificate_by_lua*, client: 172.69.58.204, server: 0.0.0.0:443 HOT 2
- redis set_keepalive doesn't work HOT 1
- lua entry thread aborted: runtime error: /usr/local/openresty/lualib/resty/redis.lua:357: bad request HOT 1
- no request found HOT 1
- Add the host:port to the error message
- Reading from client: error:0A000126:SSL routines::unexpected eof while reading
- red:smembers("key"), sometime not include the new member? HOT 6
- [Feature Request] Pipeline coroutine safety HOT 6
- Redis: timeout HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lua-resty-redis.