Skip to content

Latest commit

 

History

History
69 lines (53 loc) · 1.15 KB

cops_redis.adoc

File metadata and controls

69 lines (53 loc) · 1.15 KB

Redis

Redis/NotKeys

Enabled by default Safe Supports autocorrection Version Added Version Changed

Enabled

No

No

0.1

-

This cop detects the use of KEYS query that should be noted when used in a production environment. Consider using SCAN query instead of KEYS query. See https://redis.io/commands/keys/ for details.

To avoid detecting Hash#keys calling, this cop adds an offense only if a receiver of keys method is named redis.

Examples

# bad
redis.keys("pattern-*")

# bad
Redis.new.keys("pattern-*")

# good
cursor = 0
all_keys = []
loop do
  cursor, keys = redis.scan(cursor, match: "pattern-*")
  all_keys += keys
  break if cursor == "0"
end
all_keys

Redis/Setex

Enabled by default Safe Supports autocorrection Version Added Version Changed

Enabled

Yes

No

0.1

-

Use setex method instead of calling both set and expire methods in a transaction. See https://redis.io/commands/setex/ for details.

Examples

# bad
redis.multi do
  redis.set(key, value)
  redis.expire(key, 120)
end

# good
redis.setex(key, 120, value)