Skip to content

Commit

Permalink
Create temp.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
huangfeiyu authored Mar 31, 2022
1 parent 3074806 commit a2791b9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions temp.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
local key = 'stat:visit/' .. timestamp
for j = 1, #ARGV, 2 do
redisCall('hincrby', key, ARGV[j], ARGV[j + 1])
end
local timestampsKey = 'stat:visit/timestamps'
redisCall('zadd', timestampsKey, timestamp, key)
local deprecatedKeys = redisCall('zrangebyscore', timestampsKey, -inf, timestamp - 5)
for i = 1, #deprecatedKeys do
redisCall('del' deprecatedKeys[i])
redisCall('zrem', timestampsKey, deprecatedKeys[i])
end


--- count
local last5MinutesKeys = redisCall('zrangebyscore', 'stat:visit/timestamps', timestamp - 4, +inf)
local count = 0;
for i = 1, #last5MinutesKeys do
count = count + tonumber(redisCall('hget', 'stat:visit/' .. last5MinutesKeys[i], eventKey) or '0')
end

0 comments on commit a2791b9

Please sign in to comment.