From 28a713c574a3271942809c6cbac33fb3b60b5a0f Mon Sep 17 00:00:00 2001 From: Volodymyr Yavdoshenko Date: Fri, 28 Nov 2025 15:52:35 +0200 Subject: [PATCH 1/2] fix: add dragonfly support --- cacheops/lua/cache_thing.lua | 14 +++++++++++++- cacheops/lua/cache_thing_insideout.lua | 1 + cacheops/lua/invalidate.lua | 13 ++++++++++++- cacheops/lua/invalidate_insideout.lua | 14 ++++++++++++-- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/cacheops/lua/cache_thing.lua b/cacheops/lua/cache_thing.lua index 9569b87b..100d7adc 100644 --- a/cacheops/lua/cache_thing.lua +++ b/cacheops/lua/cache_thing.lua @@ -1,3 +1,4 @@ +--!df flags=allow-undeclared-keys local prefix = KEYS[1] local key = KEYS[2] local precall_key = KEYS[3] @@ -17,6 +18,17 @@ redis.call('setex', key, timeout, data) -- A pair of funcs -- NOTE: we depend here on keys order being stable + +-- Format value for cache key (integers without .0) +local format_val = function (val) + if type(val) == 'number' then + if val == math.floor(val) then + return string.format('%.0f', val) + end + end + return tostring(val) +end + local conj_schema = function (conj) local parts = {} for field, _ in pairs(conj) do @@ -29,7 +41,7 @@ end local conj_cache_key = function (db_table, conj) local parts = {} for field, val in pairs(conj) do - table.insert(parts, field .. '=' .. tostring(val)) + table.insert(parts, field .. '=' .. format_val(val)) end return prefix .. 'conj:' .. db_table .. ':' .. table.concat(parts, '&') diff --git a/cacheops/lua/cache_thing_insideout.lua b/cacheops/lua/cache_thing_insideout.lua index a060f346..3917fbf6 100644 --- a/cacheops/lua/cache_thing_insideout.lua +++ b/cacheops/lua/cache_thing_insideout.lua @@ -1,3 +1,4 @@ +--!df flags=allow-undeclared-keys local prefix = KEYS[1] local key = KEYS[2] local data = ARGV[1] diff --git a/cacheops/lua/invalidate.lua b/cacheops/lua/invalidate.lua index c946450e..50b122f3 100644 --- a/cacheops/lua/invalidate.lua +++ b/cacheops/lua/invalidate.lua @@ -1,12 +1,23 @@ +--!df flags=allow-undeclared-keys local prefix = KEYS[1] local db_table = ARGV[1] local obj = cjson.decode(ARGV[2]) -- Utility functions +-- Format value for cache key (integers without .0) +local format_val = function (val) + if type(val) == 'number' then + if val == math.floor(val) then + return string.format('%.0f', val) + end + end + return tostring(val) +end + local conj_cache_key = function (db_table, scheme, obj) local parts = {} for field in string.gmatch(scheme, "[^,]+") do - table.insert(parts, field .. '=' .. tostring(obj[field])) + table.insert(parts, field .. '=' .. format_val(obj[field])) end return prefix .. 'conj:' .. db_table .. ':' .. table.concat(parts, '&') diff --git a/cacheops/lua/invalidate_insideout.lua b/cacheops/lua/invalidate_insideout.lua index 3de0281b..0329414c 100644 --- a/cacheops/lua/invalidate_insideout.lua +++ b/cacheops/lua/invalidate_insideout.lua @@ -1,12 +1,22 @@ +--!df flags=allow-undeclared-keys local prefix = KEYS[1] local db_table = ARGV[1] local obj = cjson.decode(ARGV[2]) +-- Format value for cache key (integers without .0) +local format_val = function (val) + if type(val) == 'number' then + if val == math.floor(val) then + return string.format('%.0f', val) + end + end + return tostring(val) +end + local conj_cache_key = function (db_table, scheme, obj) local parts = {} for field in string.gmatch(scheme, "[^,]+") do - -- All obj values are strings, we still use tostring() in case obj does not contain field - table.insert(parts, field .. '=' .. tostring(obj[field])) + table.insert(parts, field .. '=' .. format_val(obj[field])) end return prefix .. 'conj:' .. db_table .. ':' .. table.concat(parts, '&') From 0f79f79ca2968bf99539f4ee9abc906202e11478 Mon Sep 17 00:00:00 2001 From: Volodymyr Yavdoshenko Date: Wed, 3 Dec 2025 17:26:47 +0200 Subject: [PATCH 2/2] update lua files --- cacheops/lua/cache_thing.lua | 13 +------------ cacheops/lua/invalidate.lua | 12 +----------- cacheops/lua/invalidate_insideout.lua | 13 ++----------- 3 files changed, 4 insertions(+), 34 deletions(-) diff --git a/cacheops/lua/cache_thing.lua b/cacheops/lua/cache_thing.lua index 100d7adc..460e3f04 100644 --- a/cacheops/lua/cache_thing.lua +++ b/cacheops/lua/cache_thing.lua @@ -18,17 +18,6 @@ redis.call('setex', key, timeout, data) -- A pair of funcs -- NOTE: we depend here on keys order being stable - --- Format value for cache key (integers without .0) -local format_val = function (val) - if type(val) == 'number' then - if val == math.floor(val) then - return string.format('%.0f', val) - end - end - return tostring(val) -end - local conj_schema = function (conj) local parts = {} for field, _ in pairs(conj) do @@ -41,7 +30,7 @@ end local conj_cache_key = function (db_table, conj) local parts = {} for field, val in pairs(conj) do - table.insert(parts, field .. '=' .. format_val(val)) + table.insert(parts, field .. '=' .. tostring(val)) end return prefix .. 'conj:' .. db_table .. ':' .. table.concat(parts, '&') diff --git a/cacheops/lua/invalidate.lua b/cacheops/lua/invalidate.lua index 50b122f3..dda89acf 100644 --- a/cacheops/lua/invalidate.lua +++ b/cacheops/lua/invalidate.lua @@ -4,20 +4,10 @@ local db_table = ARGV[1] local obj = cjson.decode(ARGV[2]) -- Utility functions --- Format value for cache key (integers without .0) -local format_val = function (val) - if type(val) == 'number' then - if val == math.floor(val) then - return string.format('%.0f', val) - end - end - return tostring(val) -end - local conj_cache_key = function (db_table, scheme, obj) local parts = {} for field in string.gmatch(scheme, "[^,]+") do - table.insert(parts, field .. '=' .. format_val(obj[field])) + table.insert(parts, field .. '=' .. tostring(obj[field])) end return prefix .. 'conj:' .. db_table .. ':' .. table.concat(parts, '&') diff --git a/cacheops/lua/invalidate_insideout.lua b/cacheops/lua/invalidate_insideout.lua index 0329414c..8064a598 100644 --- a/cacheops/lua/invalidate_insideout.lua +++ b/cacheops/lua/invalidate_insideout.lua @@ -3,20 +3,11 @@ local prefix = KEYS[1] local db_table = ARGV[1] local obj = cjson.decode(ARGV[2]) --- Format value for cache key (integers without .0) -local format_val = function (val) - if type(val) == 'number' then - if val == math.floor(val) then - return string.format('%.0f', val) - end - end - return tostring(val) -end - local conj_cache_key = function (db_table, scheme, obj) local parts = {} for field in string.gmatch(scheme, "[^,]+") do - table.insert(parts, field .. '=' .. format_val(obj[field])) + -- All obj values are strings, we still use tostring() in case obj does not contain field + table.insert(parts, field .. '=' .. tostring(obj[field])) end return prefix .. 'conj:' .. db_table .. ':' .. table.concat(parts, '&')