• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

swarthy / redis-semaphore / #362

24 May 2024 04:32PM UTC coverage: 99.708%. Remained the same
#362

push

web-flow
Merge pull request #218 from swarthy/chore/update-dev-deps

chore: update devDeps

135 of 137 branches covered (98.54%)

Branch coverage included in aggregate %.

547 of 547 relevant lines covered (100.0%)

247.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/multiSemaphore/acquire/lua.ts
1
import { createEval } from '../../utils/index'
1✔
2

3
export const acquireLua = createEval<
1✔
4
  [string, number, number, string, number, number],
5
  0 | 1
6
>(
7
  `
8
  local key = KEYS[1]
9
  local limit = tonumber(ARGV[1])
10
  local permits = tonumber(ARGV[2])
11
  local identifier = ARGV[3]
12
  local lockTimeout = tonumber(ARGV[4])
13
  local now = tonumber(ARGV[5])
14
  local expiredTimestamp = now - lockTimeout
15
  local args = {}
16

17
  redis.call('zremrangebyscore', key, '-inf', expiredTimestamp)
18

19
  if (redis.call('zcard', key) + permits) <= limit then
20
    for i=0, permits - 1 do
21
      table.insert(args, now)
22
      table.insert(args, identifier .. '_' .. i)
23
    end
24
    redis.call('zadd', key, unpack(args))
25
    redis.call('pexpire', key, lockTimeout)
26
    return 1
27
  else
28
    return 0
29
  end`,
30
  1
31
)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc