Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local formatKey = function (key, suffix)
- local res = "Nette.Journal:" .. key
- if suffix ~= nil then
- res = res .. ":" .. suffix
- end
- return res
- end
- local formatStorageKey = function(key, suffix)
- local res = "Nette.Storage:" .. key
- if suffix ~= nil then
- res = res .. ":" .. suffix
- end
- return res
- end
- local priorityEntries = function (priority)
- return redis.call('zRangeByScore', formatKey("priority"), 0, priority)
- end
- local entryTags = function (key)
- return redis.call('sMembers', formatKey(key, "tags"))
- end
- local tagEntries = function (tag)
- return redis.call('sMembers', formatKey(tag, "keys"))
- end
- local cleanEntry = function (keys)
- for i, key in pairs(keys) do
- local tags = entryTags(key)
- -- redis.call('multi')
- for i, tag in pairs(tags) do
- redis.call('sRem', formatKey(tag, "keys"), key)
- end
- -- drop tags of entry and priority, in case there are some
- redis.call('del', formatKey(key, "tags"), formatKey(key, "priority"))
- redis.call('zRem', formatKey("priority"), key)
- -- redis.call('exec')
- end
- end
- local dp = cjson.decode(ARGV[1])
- -- clean the entry key
- cleanEntry({KEYS[1]})
- -- write the entry key
- -- redis.call('multi')
- -- add entry to each tag & tag to entry
- if dp["tags"] ~= nil then
- for i, tag in pairs(dp["tags"]) do
- redis.call('sAdd', formatKey(tag, "keys") , KEYS[1])
- redis.call('sAdd', formatKey(KEYS[1], "tags") , tag)
- end
- end
- if dp["priority"] ~= nil then
- redis.call('zAdd', formatKey("priority"), dp["priority"], KEYS[1])
- end
- -- redis.call('exec')
- return redis.status_reply("Ok")
Advertisement
Add Comment
Please, Sign In to add comment