suo 0.3.0 → 0.3.1

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: 32aa3b3d87eea1a5332765503443960363b69d96
4
- data.tar.gz: 57feb579d0f4c168e811ba46d14712fc4cd41159
3
+ metadata.gz: ad72e1c0045977e0ccffb7a56d1d652f3ca12fc8
4
+ data.tar.gz: b715298aacc8f3f7773103d0f7a7086ece89ef32
5
5
  SHA512:
6
- metadata.gz: 0742cbe948509ebc83ece59c59c9179dbfc900a620a9d4beccf8e784f1dfe1ed5ab037b2686f18b988899634d23ac018c5741c823c840848c33fb5af87bc4e55
7
- data.tar.gz: 7864bf86c8197c73d8016fb76a77ba9c8f506d2e1d8aef7c59798d2c0d9c368e5fa6ab556233e788c1ff307103ab242d0cb081596d69b40b38e7ff2b819b7c82
6
+ metadata.gz: ebc31f887ba239304901a342b33c0ec8a6065204b46eb923087524e2d23579dfce42f73ee7220f317ffa9b032e474c08f085b1693023148c2cc9b20c8569d4c9
7
+ data.tar.gz: 9acbeeac7c2dca1ffec0807ebd8aaf56fa1b53f7c7f300f45fd52b0e68e8638506d1622c6b506cf0455a22ed8aafa177b975961e5fb623387be5bfe6fccff531
@@ -1,3 +1,7 @@
1
+ ## 0.3.1
2
+
3
+ - Slight memory leak fix.
4
+
1
5
  ## 0.3.0
2
6
 
3
7
  - Dramatically simplify the interface by forcing clients to specify the key & resources at lock initialization instead of every method call.
data/README.md CHANGED
@@ -34,7 +34,7 @@ end
34
34
  # The resources argument is the number of resources the semaphore will allow to lock (defaulting to one - a mutex)
35
35
  suo = Suo::Client::Memcached.new("bar_resource", client: some_dalli_client, resources: 2)
36
36
 
37
- Thread.new { suo.lock{ puts "One"; sleep 2 } }
37
+ Thread.new { suo.lock { puts "One"; sleep 2 } }
38
38
  Thread.new { suo.lock { puts "Two"; sleep 2 } }
39
39
  Thread.new { suo.lock { puts "Three" } }
40
40
 
@@ -46,7 +46,7 @@ suo = Suo::Client::Memcached.new("protected_key", client: some_dalli_client, acq
46
46
  # manually locking/unlocking
47
47
  # the return value from lock without a block is a unique token valid only for the current lock
48
48
  # which must be unlocked manually
49
- token = suo
49
+ token = suo.lock
50
50
  foo.baz!
51
51
  suo.unlock(token)
52
52
 
@@ -77,7 +77,7 @@ end
77
77
 
78
78
  ## History
79
79
 
80
- View the [changelog](https://github.com/nickelser/suo/blob/master/CHANGELOG.md)
80
+ View the [changelog](https://github.com/nickelser/suo/blob/master/CHANGELOG.md).
81
81
 
82
82
  ## Contributing
83
83
 
@@ -8,17 +8,21 @@ module Suo
8
8
  resources: 1
9
9
  }.freeze
10
10
 
11
+ BLANK_STR = "".freeze
12
+
11
13
  attr_accessor :client, :key, :resources, :options
12
14
 
13
15
  include MonitorMixin
14
16
 
15
17
  def initialize(key, options = {})
16
18
  fail "Client required" unless options[:client]
19
+
17
20
  @options = DEFAULT_OPTIONS.merge(options)
18
21
  @retry_count = (@options[:acquisition_timeout] / @options[:acquisition_delay].to_f).ceil
19
22
  @client = @options[:client]
20
23
  @resources = @options[:resources].to_i
21
24
  @key = key
25
+
22
26
  super() # initialize Monitor mixin for thread safety
23
27
  end
24
28
 
@@ -124,7 +128,7 @@ module Suo
124
128
  fail NotImplementedError
125
129
  end
126
130
 
127
- def initial_set(val = "") # rubocop:disable Lint/UnusedMethodArgument
131
+ def initial_set(val = BLANK_STR) # rubocop:disable Lint/UnusedMethodArgument
128
132
  fail NotImplementedError
129
133
  end
130
134
 
@@ -158,7 +162,7 @@ module Suo
158
162
  end
159
163
 
160
164
  def deserialize_locks(val)
161
- unpacked = (val.nil? || val == "") ? [] : MessagePack.unpack(val)
165
+ unpacked = (val.nil? || val == BLANK_STR) ? [] : MessagePack.unpack(val)
162
166
 
163
167
  unpacked.map do |time, token|
164
168
  [Time.at(time), token]
@@ -20,7 +20,7 @@ module Suo
20
20
  @client.set_cas(@key, newval, cas)
21
21
  end
22
22
 
23
- def initial_set(val = "")
23
+ def initial_set(val = BLANK_STR)
24
24
  @client.set(@key, val)
25
25
  end
26
26
  end
@@ -1,6 +1,8 @@
1
1
  module Suo
2
2
  module Client
3
3
  class Redis < Base
4
+ OK_STR = "OK".freeze
5
+
4
6
  def initialize(key, options = {})
5
7
  options[:client] ||= ::Redis.new(options[:connection] || {})
6
8
  super
@@ -21,7 +23,7 @@ module Suo
21
23
  multi.set(@key, newval)
22
24
  end
23
25
 
24
- ret && ret[0] == "OK"
26
+ ret && ret[0] == OK_STR
25
27
  end
26
28
 
27
29
  def synchronize
@@ -32,7 +34,7 @@ module Suo
32
34
  @client.unwatch
33
35
  end
34
36
 
35
- def initial_set(val = "")
37
+ def initial_set(val = BLANK_STR)
36
38
  @client.set(@key, val)
37
39
  end
38
40
  end
@@ -1,3 +1,3 @@
1
1
  module Suo
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: suo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Elser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-16 00:00:00.000000000 Z
11
+ date: 2015-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dalli