File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -560,6 +560,16 @@ def exists(key)
560560 end
561561 end
562562
563+ # Determine if any of the keys exists.
564+ #
565+ # @param [String, Array<String>] keys
566+ # @return [Boolean]
567+ def exists? ( *keys )
568+ synchronize do |client |
569+ client . call ( [ :exists , *keys ] , &Boolify )
570+ end
571+ end
572+
563573 # Find all keys matching the given pattern.
564574 #
565575 # @param [String] pattern
Original file line number Diff line number Diff line change @@ -175,6 +175,15 @@ def exists(key)
175175 node_for ( key ) . exists ( key )
176176 end
177177
178+ # Determine if any of the keys exists.
179+ def exists? ( *args )
180+ keys_per_node = args . group_by { |key | node_for ( key ) }
181+ keys_per_node . each do |node , keys |
182+ return true if node . exists? ( *keys )
183+ end
184+ false
185+ end
186+
178187 # Find all keys matching the given pattern.
179188 def keys ( glob = "*" )
180189 on_each_node ( :keys , glob ) . flatten
Original file line number Diff line number Diff line change @@ -11,6 +11,14 @@ def test_exists
1111 assert_equal true , r . exists ( "foo" )
1212 end
1313
14+ def test_exists?
15+ assert_equal false , r . exists? ( "{1}foo" , "{1}bar" )
16+
17+ r . set ( "{1}foo" , "s1" )
18+
19+ assert_equal true , r . exists? ( "{1}foo" )
20+ end
21+
1422 def test_type
1523 assert_equal "none" , r . type ( "foo" )
1624
You can’t perform that action at this time.
0 commit comments