You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2022/04/20 07:49:49 UTC

[apisix] branch master updated: chore(redis): avoid recording bad value (#6876)

This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 506c873fb chore(redis): avoid recording bad value (#6876)
506c873fb is described below

commit 506c873fb0371628341b1609903b7199807ed868
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Wed Apr 20 15:49:42 2022 +0800

    chore(redis): avoid recording bad value (#6876)
    
    Signed-off-by: spacewander <sp...@gmail.com>
---
 apisix/stream/xrpc/protocols/redis/init.lua | 25 +++++++++++++++++----
 t/xrpc/redis.t                              | 34 +++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 4 deletions(-)

diff --git a/apisix/stream/xrpc/protocols/redis/init.lua b/apisix/stream/xrpc/protocols/redis/init.lua
index 4edcb5922..5f67f0465 100644
--- a/apisix/stream/xrpc/protocols/redis/init.lua
+++ b/apisix/stream/xrpc/protocols/redis/init.lua
@@ -89,12 +89,29 @@ local function read_req(sk)
             return nil, err
         end
 
-        local p, err = sk:read(n + 2)
-        if not p then
-            return nil, err
+        local s
+        if n > 1024 then
+            -- avoid recording big value
+            local p, err = sk:read(1024)
+            if not p then
+                return nil, err
+            end
+
+            local ok, err = sk:drain(n - 1024 + 2)
+            if not ok then
+                return nil, err
+            end
+
+            s = ffi_str(p, 1024) .. "..."
+        else
+            local p, err = sk:read(n + 2)
+            if not p then
+                return nil, err
+            end
+
+            s = ffi_str(p, n)
         end
 
-        local s = ffi_str(p, n)
         ctx.cmd_line[i] = s
     end
 
diff --git a/t/xrpc/redis.t b/t/xrpc/redis.t
index bc5319d65..e0d9a4db5 100644
--- a/t/xrpc/redis.t
+++ b/t/xrpc/redis.t
@@ -170,3 +170,37 @@ hget animals: null
 failed to set animals: WRONGTYPE Operation against a key holding the wrong kind of value
 hget animals: bark
 --- stream_conf_enable
+
+
+
+=== TEST 4: big value
+--- config
+    location /t {
+        content_by_lua_block {
+            local redis = require "resty.redis"
+            local red = redis:new()
+
+            local ok, err = red:connect("127.0.0.1", $TEST_NGINX_REDIS_PORT)
+            if not ok then
+                ngx.say("failed to connect: ", err)
+                return
+            end
+
+            local res, err = red:set("big-key", ("\r\n"):rep(1024 * 1024 * 16))
+            if not res then
+                ngx.say("failed to set: ", err)
+                return
+            end
+
+            local res, err = red:get("big-key")
+            if not res then
+                ngx.say("failed to get: ", err)
+                return
+            end
+
+            ngx.print(res)
+        }
+    }
+--- response_body eval
+"\r\n" x 16777216
+--- stream_conf_enable