redis-cluster 1.0.0.pre.rc.2 → 1.0.0.pre.rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 87ff565ce3c8c2268935d56508aa5b5896a3f8eb
4
- data.tar.gz: 474dd846727e7c52d56fea04333e0d35223026b0
3
+ metadata.gz: c4fb30f11cb1d74b3572c8e0c9ea64ff534da5c4
4
+ data.tar.gz: 08f644a16dc2155ea730e16170b40d72f2019511
5
5
  SHA512:
6
- metadata.gz: 37eb706afca0090ea9a43bcf769ac86a06d2c423b8f20ebd9aa68a7631076ed165ab83ddc3fec015a92a3499b65f825c90ac453c7d8d74fa1bbee38e2c975235
7
- data.tar.gz: b794604db2cf25cffbfbc92fd8120f9a7801f923f54ed077549d96f77a368f49b04dd8da33a60bb9c497a61a365aafb4c913a011e0f00f4445f2c140ebb3bcef
6
+ metadata.gz: 105c1a258630a397d8f51a259a356751efcf6d67cb68484b73e4f0fa230d05d896c5970298840961bbe472232a2d2f986e71f28841d2fbaa21628ccdc07b9149
7
+ data.tar.gz: ae7fa4048759d265ba68c6c21ba18acba1918a407f4c7879a4b18494a0595293a64ea84967add9d19b7a1f57ad7d3999bd4b407ec33ae1b6a249d2d60289d70c
@@ -16,6 +16,9 @@ class RedisCluster
16
16
  @client = Redis::Client.new(opts)
17
17
  @queue = []
18
18
  @url = "#{client.host}:#{client.port}"
19
+
20
+ @loading = false
21
+ @ban_from = nil
19
22
  end
20
23
 
21
24
  def inspect
@@ -47,6 +50,18 @@ class RedisCluster
47
50
  end
48
51
  end
49
52
 
53
+ def healthy
54
+ return true unless @loading
55
+
56
+ # ban for 60 seconds for loading state
57
+ if Time.now - @ban_from > 60
58
+ @loading = false
59
+ @ban_from = nil
60
+ end
61
+
62
+ !@loading
63
+ end
64
+
50
65
  private
51
66
 
52
67
  def _commit
@@ -60,6 +75,11 @@ class RedisCluster
60
75
  end
61
76
  @queue = []
62
77
 
78
+ if result.last.is_a?(Redis::CommandError) && result.last.message['LOADING']
79
+ @loading = true
80
+ @ban_from = Time.now
81
+ end
82
+
63
83
  result
64
84
  end
65
85
  end
@@ -41,9 +41,9 @@ class RedisCluster
41
41
  when :master
42
42
  slots[slot].first
43
43
  when :slave
44
- slots[slot][1..-1].sample || slots[slot].first
44
+ slots[slot][1..-1].select(&:healthy).sample || slots[slot].first
45
45
  when :master_slave
46
- slots[slot].sample
46
+ slots[slot].select(&:healthy).sample
47
47
  end
48
48
  end
49
49
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class RedisCluster
4
- VERSION = '1.0.0-rc.2'
4
+ VERSION = '1.0.0-rc.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-cluster
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.rc.2
4
+ version: 1.0.0.pre.rc.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bukalapak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-07 00:00:00.000000000 Z
11
+ date: 2018-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis