File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env ruby
2
+ # WARNING: This will lock up CPU on the target Redis instance. Never run against production.
3
+ #
2
4
# Copyright 2020 Scribd, Inc.
3
5
4
6
require 'logger'
12
14
ssl : :true
13
15
)
14
16
15
- SCRIPT = <<END
17
+ if ARGV [ 0 ] . nil?
18
+ raise "Specify milliseconds to inject as the first positional argument to `#{ __FILE__ } `"
19
+ else
20
+ milliseconds = ARGV [ 0 ] . to_i
21
+ end
22
+
23
+ SCRIPT = <<HEREDOC
16
24
-- From https://medium.com/@stockholmux/simulating-a-slow-command-with-node-redis-and-lua-efadbf913cd9
17
25
local aTempKey = "a-temp-key"
18
26
local cycles
19
27
redis.call("SET",aTempKey,"1")
20
- redis.call("PEXPIRE",aTempKey, 100 )
21
- for i = 0, 1500000 , 1 do
28
+ redis.call("PEXPIRE",aTempKey, #{ milliseconds } )
29
+ for i = 0, #{ 15000 * milliseconds } , 1 do
22
30
local apttl = redis.call("PTTL",aTempKey)
23
31
cycles = i;
24
32
if apttl == 0 then
25
33
break;
26
34
end
27
35
end
28
36
return cycles
29
- END
37
+ HEREDOC
30
38
31
39
LOGGER . info REDIS . eval ( SCRIPT )
You can’t perform that action at this time.
0 commit comments