| 
4 | 4 | -- KEYS[3]: holder_prefix (prefix for holder keys, e.g. "semaphores:holders:key:")  | 
5 | 5 | -- ARGV[1]: capacity (total semaphore capacity)  | 
6 | 6 | --  | 
7 |  | --- Returns: {recovered_tokens, current_holders, available_tokens, total_cleaned}  | 
 | 7 | +-- Returns: {recovered_tokens, missing_tokens, excess_tokens}  | 
8 | 8 | -- This script should be run periodically to recover tokens from crashed clients  | 
9 | 9 | 
 
  | 
10 | 10 | local tokens_key = KEYS[1]  | 
@@ -52,15 +52,5 @@ for i = 1, excess_tokens do  | 
52 | 52 |     redis.call('RPOP', tokens_key)  | 
53 | 53 | end  | 
54 | 54 | 
 
  | 
55 |  | --- Step 4: Refresh expiry on data structures to prevent cleanup  | 
56 |  | -local final_holders = redis.call('SCARD', holders_key)  | 
57 |  | -local final_available = redis.call('LLEN', tokens_key)  | 
58 | 55 | 
 
  | 
59 |  | -if final_holders > 0 then  | 
60 |  | -    redis.call('EXPIRE', holders_key, 3600)  -- 1 hour expiry  | 
61 |  | -end  | 
62 |  | -if final_available > 0 then  | 
63 |  | -    redis.call('EXPIRE', tokens_key, 3600)   -- 1 hour expiry  | 
64 |  | -end  | 
65 |  | - | 
66 |  | -return {recovered_tokens, final_holders, final_available, #cleaned_holders}  | 
 | 56 | +return {recovered_tokens, missing_tokens, excess_tokens}  | 
0 commit comments