local res, prefix = redis.request(redis_params, redis_attrs,
{ 'ZRANGE', lfb_cache_prefix, '-1', '-1' })
if res ~= 1 then
- print('Redis request parameters are wrong')
+ logger.errx('Redis request parameters are wrong')
+ os.exit(1)
end
+
local _, bucket_params = redis.request(redis_params, redis_attrs,
{ 'HMGET', tostring(prefix[1]), 'l', 'b', 'r', 'dr', 'db' })
- local last = tonumber(bucket_params[1])
+
+ local last = tonumber(bucket_params[1])
local burst = tonumber(bucket_params[2])
- local rate = tonumber(bucket_params[3])
- local dynr = tonumber(bucket_params[4]) / 10000.0
- local dynb = tonumber(bucket_params[5]) / 10000.0
+ local rate = tonumber(bucket_params[3])
+ local dynr = tonumber(bucket_params[4]) / 10000.0
+ local dynb = tonumber(bucket_params[5]) / 10000.0
print(string.format('prefix: %s, last: %s, burst: %s, rate: %s, dynamic_rate: %s, dynamic_burst: %s',
prefix[1], last, burst, rate, dynr, dynb))
end
local function upgrade_bucket_handler(args)
+ if args.prefix == nil or args.prefix == "" then
+ logger.errx('Prefix is empty or nil')
+ end
+
if args.burst then
local res = redis.request(redis_params, redis_attrs,
{ 'HSET', tostring(args.prefix), 'b', tostring(args.burst) })
if res ~= 1 then
- print('Incorrect arguments for redis request for burst')
+ logger.errx('Incorrect arguments for redis request for burst or prefix is incorrect')
+ os.exit(1)
end
end
local res = redis.request(redis_params, redis_attrs,
{ 'HSET', tostring(args.prefix), 'r', tostring(args.rate) })
if res ~= 1 then
- print('Incorrect arguments for redis request for rate')
+ logger.errx('Incorrect arguments for redis request for rate or prefix is incorrect')
+ os.exit(1)
end
end
local res = redis.request(redis_params, redis_attrs,
{ 'HSET', tostring(args.prefix), 's', tostring(args.symbol) })
if res ~= 1 then
- print('Incorrect arguments for redis request for symbol')
+ logger.errx('Incorrect arguments for redis request for symbol or prefix is incorrect')
+ os.exit(1)
end
end
local res = redis.request(redis_params, redis_attrs,
{ 'HSET', tostring(args.prefix), 'db', tostring(args.dynb) })
if res ~= 1 then
- print('Incorrect arguments for redis request for dynamic burst')
+ logger.errx('Incorrect arguments for redis request for dynamic burst or prefix is incorrect')
+ os.exit(1)
end
end
local res = redis.request(redis_params, redis_attrs,
{ 'HSET', tostring(args.prefix), 'dr', tostring(args.dynr) })
if res ~= 1 then
- print('Incorrect arguments for redis request for dynamic rate')
+ logger.errx('Incorrect arguments for redis request for dynamic rate or prefix is incorrect')
+ os.exit(1)
end
end
local function unblock_bucket_helper(prefix)
local res = redis.request(redis_params, redis_attrs, { 'HSET', tostring(prefix), 'b', 0 })
if res ~= 1 then
- print('Failed to unblock bucket')
+ logger.errx('Failed to unblock bucket')
+ os.exit(1)
end
end
local res, prefix = redis.request(redis_params, redis_attrs,
{ 'ZRANGE', lfb_cache_prefix, '-1', '-1' })
if res ~= 1 then
- print('Redis request parameters are wrong')
+ logger.errx('Redis request parameters are wrong')
+ os.exit(1)
end
unblock_bucket_helper(prefix)
end