redis2-nginx-module icon indicating copy to clipboard operation
redis2-nginx-module copied to clipboard

QUESTION: store POST message body to redis

Open vkozubal opened this issue 8 years ago • 2 comments

How can I write the nginx config to store the image to redis

curl -X POST localhost:80/upload/123 --data-binary "@lena.png"

I am trying to use $request_body but it doesn't work as I guess this variable value isn't available in this location.

location ~ /upload/(.*) { redis2_query set $1 $request_body; redis2_pass 172.17.0.4:6379; } The expected result is to store the image binary data under the 123 key passed as query param. Is there any way to do that?

UPDATE: I used the https://github.com/klestoff/read-request-body-nginx-module read_request_body; directive. In this case, I am not able to send image bigger than client_body_buffer_size (default value is 16k) which is bad in if the image is bigger.

vkozubal avatar Sep 14 '17 12:09 vkozubal

@vkozubal It's possible to do streaming post of large values into redis with a small buffer on the nginx side by using lua-nginx-module's downstream cosocket API and a modified version of lua-resty-redis which does streaming redis set command sending.

agentzh avatar Sep 16 '17 20:09 agentzh

@vkozubal But not using this module. This module is hard to make the changes for your requirement. Since redis is a pure memory server, it might not be a good idea in the first place to store really large values into the redis server.

agentzh avatar Sep 16 '17 20:09 agentzh