File tree Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change 1
1
# Unreleased
2
2
3
+ * Setting ` Redis.exists_returns_integer = false ` disables warning message about new behaviour.
4
+
3
5
# 4.2.0
4
6
5
7
* Convert commands to accept keyword arguments rather than option hashes. This both help catching typos, and reduce needless allocations.
Original file line number Diff line number Diff line change 5
5
6
6
class Redis
7
7
class << self
8
- attr_accessor :exists_returns_integer
8
+ attr_reader :exists_returns_integer
9
+
10
+ def exists_returns_integer = ( value )
11
+ unless value
12
+ message = "`Redis#exists(key)` will return an Integer by default in redis-rb 4.3. The option to explicitly " \
13
+ "disable this behaviour via `Redis.exists_returns_integer` will be removed in 5.0. You should use " \
14
+ "`exists?` instead. "
15
+
16
+ ::Kernel . warn ( message )
17
+ end
18
+
19
+ @exists_returns_integer = value
20
+ end
21
+
9
22
attr_writer :current
10
23
end
11
24
@@ -561,11 +574,16 @@ def unlink(*keys)
561
574
# @return [Integer]
562
575
def exists ( *keys )
563
576
if !Redis . exists_returns_integer && keys . size == 1
564
- message = "`Redis#exists(key)` will return an Integer in redis-rb 4.3, if you want to keep the old behavior, " \
565
- "use `exists?` instead. To opt-in to the new behavior now you can set Redis.exists_returns_integer = true. " \
566
- "(#{ ::Kernel . caller ( 1 , 1 ) . first } )\n "
577
+ if Redis . exists_returns_integer . nil?
578
+ message = "`Redis#exists(key)` will return an Integer in redis-rb 4.3. `exists?` returns a boolean, you " \
579
+ "should use it instead. To opt-in to the new behavior now you can set Redis.exists_returns_integer = " \
580
+ "true. To disable this message and keep the current (boolean) behaviour of 'exists' you can set " \
581
+ "`Redis.exists_returns_integer = false`, but this option will be removed in 5.0. " \
582
+ "(#{ ::Kernel . caller ( 1 , 1 ) . first } )\n "
583
+
584
+ ::Kernel . warn ( message )
585
+ end
567
586
568
- ::Kernel . warn ( message )
569
587
exists? ( *keys )
570
588
else
571
589
_exists ( *keys )
You can’t perform that action at this time.
0 commit comments