Module: Gitlab::Redis::ClusterUtil
- Defined in:
- lib/gitlab/redis/cluster_util.rb
Class Method Summary collapse
- .batch(entries, redis) ⇒ Object
- .batch_del(keys, redis) ⇒ Object
- .batch_entries(entries) ⇒ Object
-
.batch_get(keys, redis) ⇒ Object
Redis cluster alternative to mget.
- .batch_unlink(keys, redis) ⇒ Object
-
.cluster?(obj) ⇒ Boolean
clusters? is used to select Redis command types, on ‘true`, the subsequent commands should be compatible with Redis Cluster.
Class Method Details
.batch(entries, redis) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/gitlab/redis/cluster_util.rb', line 45 def batch(entries, redis) entries.each_slice(pipeline_batch_size).flat_map do |subset| redis.pipelined do |pipeline| yield pipeline, subset end end end |
.batch_del(keys, redis) ⇒ Object
26 27 28 29 30 |
# File 'lib/gitlab/redis/cluster_util.rb', line 26 def batch_del(keys, redis) batch(keys, redis) do |pipeline, subset| subset.each { |key| pipeline.del(key) } end.sum end |
.batch_entries(entries) ⇒ Object
39 40 41 42 43 |
# File 'lib/gitlab/redis/cluster_util.rb', line 39 def batch_entries(entries) entries.each_slice(pipeline_batch_size).flat_map do |subset| yield subset end end |
.batch_get(keys, redis) ⇒ Object
Redis cluster alternative to mget
33 34 35 36 37 |
# File 'lib/gitlab/redis/cluster_util.rb', line 33 def batch_get(keys, redis) batch(keys, redis) do |pipeline, subset| subset.map { |key| pipeline.get(key) } end.flatten end |
.batch_unlink(keys, redis) ⇒ Object
20 21 22 23 24 |
# File 'lib/gitlab/redis/cluster_util.rb', line 20 def batch_unlink(keys, redis) batch(keys, redis) do |pipeline, subset| subset.each { |key| pipeline.unlink(key) } end.sum end |
.cluster?(obj) ⇒ Boolean
clusters? is used to select Redis command types, on ‘true`, the subsequent commands should be compatible with Redis Cluster.
When working with MultiStore, if even 1 of 2 stores is a Redis::Cluster, we should err on the side of caution and return ‘true `,
12 13 14 15 16 17 18 |
# File 'lib/gitlab/redis/cluster_util.rb', line 12 def cluster?(obj) if obj.is_a?(MultiStore) cluster?(obj.primary_store) || cluster?(obj.secondary_store) else obj.is_a?(::Redis::Cluster) end end |