rotary 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d91a035b7bc8d12853f4f372312d47a79ee2008f
4
- data.tar.gz: 0816ed9b7d5e25759a9d672296db5647e5baa528
3
+ metadata.gz: 937de9bd091e3c310811ba5ca77d566f8197fce6
4
+ data.tar.gz: 0bb6b8a64a102bdf777c1c1f345e1f46e6c301d7
5
5
  SHA512:
6
- metadata.gz: 963995e2f76b2cd92547b565427b055b950bf9932ee9c332b7a34cb4207af22888171527cdc8dc9c26bf6a0ae03ad0dea927572c0c0edcb203f36709de77c963
7
- data.tar.gz: 548523678285d0d620d83d51145c2bd09b31a3aec99c0c4fd21ed1c78f67b040cd0745c98d63d9e478b308ac362649d7a68695e6a9ff125392698753771afeff
6
+ metadata.gz: 94c47830c8ae7f204384457b6f8109a334a54738fab172f8d8cc7d33c8c0e0bf51bfd37a89d58bbfdd4ce37e3a17579a8dc126828820767577cdd1beb9ff80aa
7
+ data.tar.gz: fd5cf5e64b15afcbdf42389db23a399762002216d966ece09ee9e54eff3dd457677199f0a47b9af7ffed69a0393671959da81b91b3466bb9e241c4930dfe0475
@@ -60,12 +60,10 @@ module Rotary
60
60
 
61
61
  # Removes sessions, where ttl is bigger than threshold n.
62
62
  def clean_older_than(n)
63
- len = @redis.llen(@pool_list)
64
-
65
63
  # It doesn't have to happen atomically.
66
64
  # New session will be lpush'ed, we can easily check only
67
65
  # N sessions from the right.
68
- len.times do
66
+ size.times do
69
67
  serialized_session = @redis.rpop(@pool_list)
70
68
 
71
69
  # We have no sessions left. It can happen.
@@ -74,11 +72,13 @@ module Rotary
74
72
  key = ttl_key(serialized_session)
75
73
  ttl_marker = @redis.ttl(key)
76
74
 
77
- # redis.rb returns -2 when key doesn't exist
78
- no_ttl = ttl_marker == -2
79
- next if no_ttl
75
+ # When key doesn't exist
76
+ # redis <= 2.6 returns -1
77
+ # redis >= 2.8 returns -2
78
+ no_key = [-1, -2].include?(ttl_marker)
79
+ next if no_key
80
80
 
81
- old = ttl_marker < (@ttl - n)
81
+ old = @ttl ? ttl_marker < (@ttl - n) : false
82
82
  if old
83
83
  # delete ttl key
84
84
  @redis.del(key)
@@ -87,7 +87,7 @@ module Rotary
87
87
  yield(session) if block_given?
88
88
  else
89
89
  # push back from the left side
90
- @redis.lpush(@pool_list, session)
90
+ @redis.lpush(@pool_list, serialized_session)
91
91
  end
92
92
  end
93
93
  end
@@ -1,4 +1,4 @@
1
1
  module Rotary
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.7'
3
3
  end
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rotary
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Redozubov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-17 00:00:00.000000000 Z
11
+ date: 2014-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake