@@ -546,3 +546,78 @@ passed
546546["GET /hello", "GET /hello", "GET /hello", "GET /hello"]
547547--- error_code eval
548548[200, 200, 503, 503]
549+
550+
551+
552+ === TEST 17: set route and flush the cluster script cache
553+ --- config
554+ location /t {
555+ content_by_lua_block {
556+ local t = require("lib.test_admin").test
557+ local code, body = t('/apisix/admin/routes/1',
558+ ngx.HTTP_PUT,
559+ [[{
560+ "uri": "/hello",
561+ "plugins": {
562+ "limit-count": {
563+ "count": 9999,
564+ "time_window": 60,
565+ "key": "remote_addr",
566+ "policy": "redis-cluster",
567+ "redis_cluster_nodes": [
568+ "127.0.0.1:5000",
569+ "127.0.0.1:5001"
570+ ],
571+ "redis_cluster_name": "redis-cluster-1"
572+ }
573+ },
574+ "upstream": {
575+ "nodes": {
576+ "127.0.0.1:1980": 1
577+ },
578+ "type": "roundrobin"
579+ }
580+ }]]
581+ )
582+ if code >= 300 then
583+ ngx.status = code
584+ ngx.say(body)
585+ return
586+ end
587+
588+ -- drop any cached script on every node so the next evalsha returns NOSCRIPT
589+ local redis = require("resty.redis")
590+ local seed = redis:new()
591+ seed:set_timeout(1000)
592+ local ok, err = seed:connect("127.0.0.1", 5000)
593+ if not ok then
594+ ngx.say("failed to connect seed: ", err)
595+ return
596+ end
597+ local nodes = seed:cluster("nodes")
598+ seed:set_keepalive(10000, 100)
599+ for addr in nodes:gmatch("(%d+%.%d+%.%d+%.%d+:%d+)@") do
600+ local ip, port = addr:match("([^:]+):(%d+)")
601+ local red = redis:new()
602+ red:set_timeout(1000)
603+ if red:connect(ip, tonumber(port)) then
604+ red:script("flush")
605+ red:set_keepalive(10000, 100)
606+ end
607+ end
608+ ngx.say("done")
609+ }
610+ }
611+ --- response_body
612+ done
613+
614+
615+
616+ === TEST 18: cluster path falls back to eval on NOSCRIPT
617+ --- request
618+ GET /hello
619+ --- error_code: 200
620+ --- grep_error_log eval
621+ qr/redis evalsha failed:.*Falling back to eval/
622+ --- grep_error_log_out
623+ redis evalsha failed: NOSCRIPT No matching script. Please use EVAL.. Falling back to eval
0 commit comments