I'd like to summary key values of monthly with 'hget' command.
Test Set) hmset SiteID:TotalCnt 20180101 10 20180102 2 20180103 5 20180120 10 20180131 30 20180205 20 20180210 5
I'd like to summary key values of 2018.01 So, I did..
sumkey.lua
local mon = ARGV[1]
local sumkey = 0
local forkey = ''
for i = 1,31 do
if i < 10 then local dd = '0' .. tostring(i)
else dd = tostring(i)
end
forkey = mon .. dd
sumkey = sumkey + redis.call('hget' , KEYS[1] , forkey)
end
return sumkey
ubuntu@:~$ redis-cli -n 2 --eval sumkey.lua (error) ERR Error running script (call to f_1c9d9d311f9c1e2fbb34fa81176539ad45da3b5b): @enable_strict_lua:15: user_script:8: Script attempted to access unexisting global variable 'dd'
tostring does not work.!!!
How can I summary values of key ???