Class: SaferRedis::Assessor

Inherits:
Object
  • Object
show all
Defined in:
lib/safer_redis/assessor.rb

Class Method Summary collapse

Class Method Details

.assess!(doc, redis:) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/safer_redis/assessor.rb', line 7

def self.assess!(doc, redis:)
  # DEL becomes UNLINK if lazyfree-lazy-user-del is set
  # https://github.com/redis/redis/pull/6243
  # https://redis.io/docs/management/config-file/
  if doc.name == "DEL" && config_get("lazyfree-lazy-user-del", redis:) == "yes"
    doc = SaferRedis::CommandDoc.new("UNLINK")
  end

  if doc.dangerous?
    # Anything tagged @dangerous is… dangerous
    raise SaferRedis::Danger.new(doc)

  elsif doc.slow? && doc.complexity != "O(1)"
    # Anything tagged @slow might be dangerous, but we'll let through O(1)
    # complexity commands e.g. SET
    raise SaferRedis::Danger.new(doc)
  end
end

.config_get(option, redis:) ⇒ Object



26
27
28
# File 'lib/safer_redis/assessor.rb', line 26

def self.config_get(option, redis:)
  SaferRedis.really { redis.config(:get, option)[option] }
end