insert_entry.lua 679 B

123456789101112131415161718192021222324252627
  1. -- KEYS[1]: full path of entry
  2. local full_path = KEYS[1]
  3. -- KEYS[2]: dir of the entry
  4. local dir_list_key = KEYS[2]
  5. -- ARGV[1]: content of the entry
  6. local entry = ARGV[1]
  7. -- ARGV[2]: TTL of the entry
  8. local ttlSec = tonumber(ARGV[2])
  9. -- ARGV[3]: isSuperLargeDirectory
  10. local isSuperLargeDirectory = ARGV[3] == "1"
  11. -- ARGV[4]: zscore of the entry in zset
  12. local zscore = tonumber(ARGV[4])
  13. -- ARGV[5]: name of the entry
  14. local name = ARGV[5]
  15. if ttlSec > 0 then
  16. redis.call("SET", full_path, entry, "EX", ttlSec)
  17. else
  18. redis.call("SET", full_path, entry)
  19. end
  20. if not isSuperLargeDirectory and name ~= "" then
  21. redis.call("ZADD", dir_list_key, "NX", zscore, name)
  22. end
  23. return 0