-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[script] try redis commands via our connector
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env sh | ||
|
||
exec resty -I apicast/src script/redis.lua "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env resty -I apicast/src | ||
|
||
local cmd = arg[1] | ||
local args = {} | ||
|
||
for i=2, #arg do | ||
table.insert(args, arg[i]) | ||
end | ||
|
||
if not cmd then | ||
print('missing command') | ||
print('usage: ' .. arg[0] .. ' cmd [arg [arg ...]]') | ||
os.exit(1) | ||
end | ||
|
||
local inspect = require 'inspect' | ||
local ts = require 'threescale_utils' | ||
|
||
local red, err = ts.connect_redis() | ||
|
||
if not red and err then | ||
print('could not connect to redis: ', err) | ||
os.exit(1) | ||
end | ||
|
||
local fn = red[cmd] | ||
local res, err = fn(red, unpack(args)) | ||
|
||
if err then | ||
print('error: ', err) | ||
print(inspect(r)) | ||
os.exit(1) | ||
end | ||
|
||
print(inspect(res)) |