Skip to content

Instantly share code, notes, and snippets.

@ChinaXing
Created May 12, 2015 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChinaXing/2de46b122a0677577b8f to your computer and use it in GitHub Desktop.
Save ChinaXing/2de46b122a0677577b8f to your computer and use it in GitHub Desktop.
-------------------------------------------------------------------------------------
-- Internal function
-------------------------------------------------------------------------------------
function delete_by_wild (red, wild)
local result, err = red:keys(wild)
if not result then
ngx.say("failed to get keys : " .. wild .. ", reason :", err)
return nil
end
for i, k in ipairs(result) do
red:del(k)
end
return true
end
function init_redis()
local redis = require "resty.redis"
local red = redis:new()
red:set_timeout(1000)
local ok, err = red:connect("redis.server.address.com", 6379)
if not ok then
ngx.say("failed to connect: ", err)
return false
end
local res, err = red:auth("instanceId:password")
if not res then
ngx.say("failed to authenticate: ", err)
return false
end
-- add commands
red:add_commands("keys","del")
ngx.say(" ** add commands ok ** ")
return red
end
function delete_shop (red, merchant_id, probe_sn_list)
delete_by_wild(red, "probe_online_" .. merchant_id)
for i, probe in ipairs(probe_sn_list) do
delete_by_wild(red, "probe_online_1001_" .. probe)
end
delete_by_wild(red, "probe_visitor_*_" .. merchant_id)
for i, probe in ipairs(probe_sn_list) do
delete_by_wild(red, "probe_visitor_*_1001_" .. probe)
end
delete_by_wild(red, "dev_merchant_probe_status_" .. merchant_id)
delete_by_wild(red, "dev_merchant_last_leave_" .. merchant_id)
delete_by_wild(red, "dev_merchant_online_probe_" .. merchant_id)
end
-------------------------------------------------------------------------------------
--
-- Main handler
--
-------------------------------------------------------------------------------------
local red = init_redis()
if not red then
ngx.say("initailize redis failed")
return
end
-- do delete
delete_shop(red, "bf0cf2586dfe11e4a4eed8490b8ac7cb", {"P12015042101002808","P12015042101002807","P12015042101002809"})
ngx.say("Sir, It's finished. ( Lua is a pretty Girl ! )")
-- or just close the connection right away:
local ok, err = red:close()
if not ok then
ngx.say("failed to close: ", err)
return
end
-------------------------------------------------------------------------------------
@ChinaXing
Copy link
Author

lua_package_path "/usr/local/lib/lua/resty/redis.lua;;";

server {
    listen 9119;
    server_name china-tree.com;
    location /probe/clear/shop/cache/ {
        content_by_lua_file /home/admin/nginx/conf/probe-clear-shop-cache.lua;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment