local key = KEYS[1]

local exe_ret = {}
exe_ret["error"] = "success"
exe_ret["result"] = ""

if #ARGV ~= 2 then
    exe_ret["error"] = "param num error"
	return cjson.encode(exe_ret)
end
local term = ARGV[1]
local will_val = ARGV[2]

if redis.call('HEXISTS', key, term) == 0 then
    exe_ret["result"] = redis.call('HSET', key, term, will_val)
    return cjson.encode(exe_ret)
end

local current_val = redis.call('HGET', key, term)
if string.find(current_val, '*') == nil then
    exe_ret["result"] = 2
    return cjson.encode(exe_ret)
end

exe_ret["result"] = redis.call('HSET', key, term, will_val)
return cjson.encode(exe_ret)


