diff --git a/script/redis b/script/redis new file mode 100755 index 000000000..53c18f3e9 --- /dev/null +++ b/script/redis @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +exec resty -I apicast/src script/redis.lua "$@" diff --git a/script/redis.lua b/script/redis.lua new file mode 100644 index 000000000..0869bf1d6 --- /dev/null +++ b/script/redis.lua @@ -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))