openresty / openresty/lua-resty-redis

i have a problem status lua 200 not showing

Open
#149 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
2k
Forks
447
Avg merge
2h 24m
Merged PRs (30d)
3

Description

i made some script like below.

default.conf

location /proxy {

    proxy_pass http://127.0.0.1:8001/;
    rewrite_by_lua_file ./lua/set_by_file.lua;
    }    

######### lua/set_by_file.lua
local pretty = require "resty.prettycjson"

        function getval(v, def)
        if v == nil then
                return def
        end
                return v
        end

        local data = {request={}, response={}}

        local req = data["request"]
        local resp = data["response"]
        req["host"] = ngx.var.host
        req["uri"] = ngx.var.uri
        req["headers"] = ngx.req.get_headers()
        req["time"] = ngx.req.start_time()
        req["method"] = ngx.req.get_method()
        req["get_args"] = ngx.req.get_uri_args()

        req["body"] = ngx.var.request_body

        content_type = getval(ngx.var.CONTENT_TYPE, "")


        resp["headers"] = ngx.resp.get_headers()
        resp["status"] = ngx.status
        resp["duration"] = ngx.var.upstream_response_time
        resp["time"] = ngx.now()
        resp["body"] = ngx.var.response_body

        local hasilnya = pretty({data})



		local redis = require "resty.redis"
                local red = redis:new()

                red:set_timeout(1000) -- 1 sec

                -- or connect to a unix domain socket file listened
                -- by a redis server:
                --     local ok, err = red:connect("unix:/path/to/redis.sock")

                local ok, err = red:connect("127.0.0.1", 6379)
                if not ok then
                    ngx.say("failed to connect: ", err)
                    return
                end

                ok, err = red:set("dog", pretty({data}))
                if not ok then
                    ngx.say("failed to set dog: ", err)
                    return
                end

                ngx.say("set result: ", ok)

result


"[\n\t{\n\t\t\"request\": {\n\t\t\t\"host\": \"localhost\",\n\t\t\t\"method\": \"GET\",\n\t\t\t\"uri\": \"\\/proxy\",\n\t\t\t\"time\": 1536133125.225,\n\t\t\t\"get_args\": \t\t\t{},\n\t\t\t\"headers\": {\n\t\t\t\t\"host\": \"localhost\",\n\t\t\t\t\"accept\": \"*\\/*\",\n\t\t\t\t\"user-agent\": \"curl\\/7.47.0\"\n\t\t\t}\n\t\t},\n\t\t\"response\": {\n\t\t\t\"status\": 0,\n\t\t\t\"time\": 1536133125.225,\n\t\t\t\"headers\": {\n\t\t\t\t\"connection\": \"keep-alive\"\n\t\t\t}\n\t\t}\n\t}\n]"

But, i have a problem with the response status. I got "0" status as a result. It should be "200" for the normal response. Do you have any suggestions for this issue?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue provides an nginx configuration and Lua script using ngx.status, ngx.resp.get_headers(), and resty.redis, and reports a response status of 0 instead of 200. Start by reproducing the configuration and checking when the response status is available; the issue does not define a repository change or a clear completion condition.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, nginx, redis
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.