local exe_ret = {}
exe_ret["error"] = "success"
exe_ret["result"] = ""
--[[
    check condition
--]]
local ret = redis.call('EXISTS', KEYS[1])
if ret == 0 then
    exe_ret["error"] = "key not exists"
    return cjson.encode(exe_ret)
end

--[[
	get data index to add data index
--]]
local index_name = function ( key )
	local index = string.find(key, '}')
	index = string.find(key,'-',index + 2)
	local head  = string.sub(key, 1, index - 1)
	return head
end

--[[
	get data id
--]]
local key_id = function ( key )
	local index = string.find(key, '}')
	index = string.find(key, '-' ,index + 2)
	local head  = string.sub(key, index + 1)
	return head
end

local table_index = index_name(KEYS[1])
local table_id = key_id(KEYS[1])

--[[
	del hash data
--]]
redis.call('DEL', KEYS[1])

--[[
	remove data index
--]]
redis.call('ZREM', table_index, table_id)

return cjson.encode(exe_ret)