redis 3.3.3 → 5.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +280 -12
  3. data/README.md +141 -147
  4. data/lib/redis/client.rb +77 -539
  5. data/lib/redis/commands/bitmaps.rb +66 -0
  6. data/lib/redis/commands/cluster.rb +28 -0
  7. data/lib/redis/commands/connection.rb +53 -0
  8. data/lib/redis/commands/geo.rb +84 -0
  9. data/lib/redis/commands/hashes.rb +254 -0
  10. data/lib/redis/commands/hyper_log_log.rb +37 -0
  11. data/lib/redis/commands/keys.rb +437 -0
  12. data/lib/redis/commands/lists.rb +285 -0
  13. data/lib/redis/commands/pubsub.rb +54 -0
  14. data/lib/redis/commands/scripting.rb +114 -0
  15. data/lib/redis/commands/server.rb +188 -0
  16. data/lib/redis/commands/sets.rb +214 -0
  17. data/lib/redis/commands/sorted_sets.rb +818 -0
  18. data/lib/redis/commands/streams.rb +384 -0
  19. data/lib/redis/commands/strings.rb +314 -0
  20. data/lib/redis/commands/transactions.rb +115 -0
  21. data/lib/redis/commands.rb +235 -0
  22. data/lib/redis/distributed.rb +300 -108
  23. data/lib/redis/errors.rb +22 -1
  24. data/lib/redis/hash_ring.rb +36 -79
  25. data/lib/redis/pipeline.rb +69 -83
  26. data/lib/redis/subscribe.rb +26 -19
  27. data/lib/redis/version.rb +3 -1
  28. data/lib/redis.rb +113 -2685
  29. metadata +40 -218
  30. data/.gitignore +0 -16
  31. data/.travis/Gemfile +0 -11
  32. data/.travis.yml +0 -89
  33. data/.yardopts +0 -3
  34. data/Gemfile +0 -4
  35. data/Rakefile +0 -87
  36. data/benchmarking/logging.rb +0 -71
  37. data/benchmarking/pipeline.rb +0 -51
  38. data/benchmarking/speed.rb +0 -21
  39. data/benchmarking/suite.rb +0 -24
  40. data/benchmarking/worker.rb +0 -71
  41. data/examples/basic.rb +0 -15
  42. data/examples/consistency.rb +0 -114
  43. data/examples/dist_redis.rb +0 -43
  44. data/examples/incr-decr.rb +0 -17
  45. data/examples/list.rb +0 -26
  46. data/examples/pubsub.rb +0 -37
  47. data/examples/sentinel/sentinel.conf +0 -9
  48. data/examples/sentinel/start +0 -49
  49. data/examples/sentinel.rb +0 -41
  50. data/examples/sets.rb +0 -36
  51. data/examples/unicorn/config.ru +0 -3
  52. data/examples/unicorn/unicorn.rb +0 -20
  53. data/lib/redis/connection/command_helper.rb +0 -44
  54. data/lib/redis/connection/hiredis.rb +0 -66
  55. data/lib/redis/connection/registry.rb +0 -12
  56. data/lib/redis/connection/ruby.rb +0 -429
  57. data/lib/redis/connection/synchrony.rb +0 -133
  58. data/lib/redis/connection.rb +0 -9
  59. data/redis.gemspec +0 -44
  60. data/test/bitpos_test.rb +0 -69
  61. data/test/blocking_commands_test.rb +0 -42
  62. data/test/client_test.rb +0 -59
  63. data/test/command_map_test.rb +0 -30
  64. data/test/commands_on_hashes_test.rb +0 -21
  65. data/test/commands_on_hyper_log_log_test.rb +0 -21
  66. data/test/commands_on_lists_test.rb +0 -20
  67. data/test/commands_on_sets_test.rb +0 -77
  68. data/test/commands_on_sorted_sets_test.rb +0 -137
  69. data/test/commands_on_strings_test.rb +0 -101
  70. data/test/commands_on_value_types_test.rb +0 -133
  71. data/test/connection_handling_test.rb +0 -277
  72. data/test/db/.gitkeep +0 -0
  73. data/test/distributed_blocking_commands_test.rb +0 -46
  74. data/test/distributed_commands_on_hashes_test.rb +0 -10
  75. data/test/distributed_commands_on_hyper_log_log_test.rb +0 -33
  76. data/test/distributed_commands_on_lists_test.rb +0 -22
  77. data/test/distributed_commands_on_sets_test.rb +0 -83
  78. data/test/distributed_commands_on_sorted_sets_test.rb +0 -18
  79. data/test/distributed_commands_on_strings_test.rb +0 -59
  80. data/test/distributed_commands_on_value_types_test.rb +0 -95
  81. data/test/distributed_commands_requiring_clustering_test.rb +0 -164
  82. data/test/distributed_connection_handling_test.rb +0 -23
  83. data/test/distributed_internals_test.rb +0 -79
  84. data/test/distributed_key_tags_test.rb +0 -52
  85. data/test/distributed_persistence_control_commands_test.rb +0 -26
  86. data/test/distributed_publish_subscribe_test.rb +0 -92
  87. data/test/distributed_remote_server_control_commands_test.rb +0 -66
  88. data/test/distributed_scripting_test.rb +0 -102
  89. data/test/distributed_sorting_test.rb +0 -20
  90. data/test/distributed_test.rb +0 -58
  91. data/test/distributed_transactions_test.rb +0 -32
  92. data/test/encoding_test.rb +0 -18
  93. data/test/error_replies_test.rb +0 -59
  94. data/test/fork_safety_test.rb +0 -65
  95. data/test/helper.rb +0 -232
  96. data/test/helper_test.rb +0 -24
  97. data/test/internals_test.rb +0 -457
  98. data/test/lint/blocking_commands.rb +0 -150
  99. data/test/lint/hashes.rb +0 -162
  100. data/test/lint/hyper_log_log.rb +0 -60
  101. data/test/lint/lists.rb +0 -143
  102. data/test/lint/sets.rb +0 -140
  103. data/test/lint/sorted_sets.rb +0 -316
  104. data/test/lint/strings.rb +0 -260
  105. data/test/lint/value_types.rb +0 -122
  106. data/test/persistence_control_commands_test.rb +0 -26
  107. data/test/pipelining_commands_test.rb +0 -242
  108. data/test/publish_subscribe_test.rb +0 -282
  109. data/test/remote_server_control_commands_test.rb +0 -118
  110. data/test/scanning_test.rb +0 -413
  111. data/test/scripting_test.rb +0 -78
  112. data/test/sentinel_command_test.rb +0 -80
  113. data/test/sentinel_test.rb +0 -255
  114. data/test/sorting_test.rb +0 -59
  115. data/test/ssl_test.rb +0 -73
  116. data/test/support/connection/hiredis.rb +0 -1
  117. data/test/support/connection/ruby.rb +0 -1
  118. data/test/support/connection/synchrony.rb +0 -17
  119. data/test/support/redis_mock.rb +0 -130
  120. data/test/support/ssl/gen_certs.sh +0 -31
  121. data/test/support/ssl/trusted-ca.crt +0 -25
  122. data/test/support/ssl/trusted-ca.key +0 -27
  123. data/test/support/ssl/trusted-cert.crt +0 -81
  124. data/test/support/ssl/trusted-cert.key +0 -28
  125. data/test/support/ssl/untrusted-ca.crt +0 -26
  126. data/test/support/ssl/untrusted-ca.key +0 -27
  127. data/test/support/ssl/untrusted-cert.crt +0 -82
  128. data/test/support/ssl/untrusted-cert.key +0 -28
  129. data/test/support/wire/synchrony.rb +0 -24
  130. data/test/support/wire/thread.rb +0 -5
  131. data/test/synchrony_driver.rb +0 -88
  132. data/test/test.conf.erb +0 -9
  133. data/test/thread_safety_test.rb +0 -62
  134. data/test/transactions_test.rb +0 -264
  135. data/test/unknown_commands_test.rb +0 -14
  136. data/test/url_param_test.rb +0 -138
@@ -0,0 +1,214 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Redis
4
+ module Commands
5
+ module Sets
6
+ # Get the number of members in a set.
7
+ #
8
+ # @param [String] key
9
+ # @return [Integer]
10
+ def scard(key)
11
+ send_command([:scard, key])
12
+ end
13
+
14
+ # Add one or more members to a set.
15
+ #
16
+ # @param [String] key
17
+ # @param [String, Array<String>] member one member, or array of members
18
+ # @return [Integer] The number of members that were successfully added
19
+ def sadd(key, *members)
20
+ members.flatten!(1)
21
+ send_command([:sadd, key].concat(members))
22
+ end
23
+
24
+ # Add one or more members to a set.
25
+ #
26
+ # @param [String] key
27
+ # @param [String, Array<String>] member one member, or array of members
28
+ # @return [Boolean] Wether at least one member was successfully added.
29
+ def sadd?(key, *members)
30
+ members.flatten!(1)
31
+ send_command([:sadd, key].concat(members), &Boolify)
32
+ end
33
+
34
+ # Remove one or more members from a set.
35
+ #
36
+ # @param [String] key
37
+ # @param [String, Array<String>] member one member, or array of members
38
+ # @return [Integer] The number of members that were successfully removed
39
+ def srem(key, *members)
40
+ members.flatten!(1)
41
+ send_command([:srem, key].concat(members))
42
+ end
43
+
44
+ # Remove one or more members from a set.
45
+ #
46
+ # @param [String] key
47
+ # @param [String, Array<String>] member one member, or array of members
48
+ # @return [Boolean] Wether at least one member was successfully removed.
49
+ def srem?(key, *members)
50
+ members.flatten!(1)
51
+ send_command([:srem, key].concat(members), &Boolify)
52
+ end
53
+
54
+ # Remove and return one or more random member from a set.
55
+ #
56
+ # @param [String] key
57
+ # @return [String]
58
+ # @param [Integer] count
59
+ def spop(key, count = nil)
60
+ if count.nil?
61
+ send_command([:spop, key])
62
+ else
63
+ send_command([:spop, key, Integer(count)])
64
+ end
65
+ end
66
+
67
+ # Get one or more random members from a set.
68
+ #
69
+ # @param [String] key
70
+ # @param [Integer] count
71
+ # @return [String]
72
+ def srandmember(key, count = nil)
73
+ if count.nil?
74
+ send_command([:srandmember, key])
75
+ else
76
+ send_command([:srandmember, key, count])
77
+ end
78
+ end
79
+
80
+ # Move a member from one set to another.
81
+ #
82
+ # @param [String] source source key
83
+ # @param [String] destination destination key
84
+ # @param [String] member member to move from `source` to `destination`
85
+ # @return [Boolean]
86
+ def smove(source, destination, member)
87
+ send_command([:smove, source, destination, member], &Boolify)
88
+ end
89
+
90
+ # Determine if a given value is a member of a set.
91
+ #
92
+ # @param [String] key
93
+ # @param [String] member
94
+ # @return [Boolean]
95
+ def sismember(key, member)
96
+ send_command([:sismember, key, member], &Boolify)
97
+ end
98
+
99
+ # Determine if multiple values are members of a set.
100
+ #
101
+ # @param [String] key
102
+ # @param [String, Array<String>] members
103
+ # @return [Array<Boolean>]
104
+ def smismember(key, *members)
105
+ members.flatten!(1)
106
+ send_command([:smismember, key].concat(members)) do |reply|
107
+ reply.map(&Boolify)
108
+ end
109
+ end
110
+
111
+ # Get all the members in a set.
112
+ #
113
+ # @param [String] key
114
+ # @return [Array<String>]
115
+ def smembers(key)
116
+ send_command([:smembers, key])
117
+ end
118
+
119
+ # Subtract multiple sets.
120
+ #
121
+ # @param [String, Array<String>] keys keys pointing to sets to subtract
122
+ # @return [Array<String>] members in the difference
123
+ def sdiff(*keys)
124
+ keys.flatten!(1)
125
+ send_command([:sdiff].concat(keys))
126
+ end
127
+
128
+ # Subtract multiple sets and store the resulting set in a key.
129
+ #
130
+ # @param [String] destination destination key
131
+ # @param [String, Array<String>] keys keys pointing to sets to subtract
132
+ # @return [Integer] number of elements in the resulting set
133
+ def sdiffstore(destination, *keys)
134
+ keys.flatten!(1)
135
+ send_command([:sdiffstore, destination].concat(keys))
136
+ end
137
+
138
+ # Intersect multiple sets.
139
+ #
140
+ # @param [String, Array<String>] keys keys pointing to sets to intersect
141
+ # @return [Array<String>] members in the intersection
142
+ def sinter(*keys)
143
+ keys.flatten!(1)
144
+ send_command([:sinter].concat(keys))
145
+ end
146
+
147
+ # Intersect multiple sets and store the resulting set in a key.
148
+ #
149
+ # @param [String] destination destination key
150
+ # @param [String, Array<String>] keys keys pointing to sets to intersect
151
+ # @return [Integer] number of elements in the resulting set
152
+ def sinterstore(destination, *keys)
153
+ keys.flatten!(1)
154
+ send_command([:sinterstore, destination].concat(keys))
155
+ end
156
+
157
+ # Add multiple sets.
158
+ #
159
+ # @param [String, Array<String>] keys keys pointing to sets to unify
160
+ # @return [Array<String>] members in the union
161
+ def sunion(*keys)
162
+ keys.flatten!(1)
163
+ send_command([:sunion].concat(keys))
164
+ end
165
+
166
+ # Add multiple sets and store the resulting set in a key.
167
+ #
168
+ # @param [String] destination destination key
169
+ # @param [String, Array<String>] keys keys pointing to sets to unify
170
+ # @return [Integer] number of elements in the resulting set
171
+ def sunionstore(destination, *keys)
172
+ keys.flatten!(1)
173
+ send_command([:sunionstore, destination].concat(keys))
174
+ end
175
+
176
+ # Scan a set
177
+ #
178
+ # @example Retrieve the first batch of keys in a set
179
+ # redis.sscan("set", 0)
180
+ #
181
+ # @param [String, Integer] cursor the cursor of the iteration
182
+ # @param [Hash] options
183
+ # - `:match => String`: only return keys matching the pattern
184
+ # - `:count => Integer`: return count keys at most per iteration
185
+ #
186
+ # @return [String, Array<String>] the next cursor and all found members
187
+ def sscan(key, cursor, **options)
188
+ _scan(:sscan, cursor, [key], **options)
189
+ end
190
+
191
+ # Scan a set
192
+ #
193
+ # @example Retrieve all of the keys in a set
194
+ # redis.sscan_each("set").to_a
195
+ # # => ["key1", "key2", "key3"]
196
+ #
197
+ # @param [Hash] options
198
+ # - `:match => String`: only return keys matching the pattern
199
+ # - `:count => Integer`: return count keys at most per iteration
200
+ #
201
+ # @return [Enumerator] an enumerator for all keys in the set
202
+ def sscan_each(key, **options, &block)
203
+ return to_enum(:sscan_each, key, **options) unless block_given?
204
+
205
+ cursor = 0
206
+ loop do
207
+ cursor, keys = sscan(key, cursor, **options)
208
+ keys.each(&block)
209
+ break if cursor == "0"
210
+ end
211
+ end
212
+ end
213
+ end
214
+ end