mirror of
https://github.com/dkam/suo.git
synced 2025-01-29 07:42:43 +00:00
don't go around allocating empty strings willy-nilly
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
## 0.3.1
|
||||||
|
|
||||||
|
- Slight memory leak fix.
|
||||||
|
|
||||||
## 0.3.0
|
## 0.3.0
|
||||||
|
|
||||||
- Dramatically simplify the interface by forcing clients to specify the key & resources at lock initialization instead of every method call.
|
- Dramatically simplify the interface by forcing clients to specify the key & resources at lock initialization instead of every method call.
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ suo = Suo::Client::Memcached.new("protected_key", client: some_dalli_client, acq
|
|||||||
# manually locking/unlocking
|
# manually locking/unlocking
|
||||||
# the return value from lock without a block is a unique token valid only for the current lock
|
# the return value from lock without a block is a unique token valid only for the current lock
|
||||||
# which must be unlocked manually
|
# which must be unlocked manually
|
||||||
token = suo
|
token = suo.lock
|
||||||
foo.baz!
|
foo.baz!
|
||||||
suo.unlock(token)
|
suo.unlock(token)
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ end
|
|||||||
|
|
||||||
## History
|
## History
|
||||||
|
|
||||||
View the [changelog](https://github.com/nickelser/suo/blob/master/CHANGELOG.md)
|
View the [changelog](https://github.com/nickelser/suo/blob/master/CHANGELOG.md).
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
|||||||
@@ -8,17 +8,21 @@ module Suo
|
|||||||
resources: 1
|
resources: 1
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
|
BLANK_STR = "".freeze
|
||||||
|
|
||||||
attr_accessor :client, :key, :resources, :options
|
attr_accessor :client, :key, :resources, :options
|
||||||
|
|
||||||
include MonitorMixin
|
include MonitorMixin
|
||||||
|
|
||||||
def initialize(key, options = {})
|
def initialize(key, options = {})
|
||||||
fail "Client required" unless options[:client]
|
fail "Client required" unless options[:client]
|
||||||
|
|
||||||
@options = DEFAULT_OPTIONS.merge(options)
|
@options = DEFAULT_OPTIONS.merge(options)
|
||||||
@retry_count = (@options[:acquisition_timeout] / @options[:acquisition_delay].to_f).ceil
|
@retry_count = (@options[:acquisition_timeout] / @options[:acquisition_delay].to_f).ceil
|
||||||
@client = @options[:client]
|
@client = @options[:client]
|
||||||
@resources = @options[:resources].to_i
|
@resources = @options[:resources].to_i
|
||||||
@key = key
|
@key = key
|
||||||
|
|
||||||
super() # initialize Monitor mixin for thread safety
|
super() # initialize Monitor mixin for thread safety
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -124,7 +128,7 @@ module Suo
|
|||||||
fail NotImplementedError
|
fail NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
||||||
def initial_set(val = "") # rubocop:disable Lint/UnusedMethodArgument
|
def initial_set(val = BLANK_STR) # rubocop:disable Lint/UnusedMethodArgument
|
||||||
fail NotImplementedError
|
fail NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -158,7 +162,7 @@ module Suo
|
|||||||
end
|
end
|
||||||
|
|
||||||
def deserialize_locks(val)
|
def deserialize_locks(val)
|
||||||
unpacked = (val.nil? || val == "") ? [] : MessagePack.unpack(val)
|
unpacked = (val.nil? || val == BLANK_STR) ? [] : MessagePack.unpack(val)
|
||||||
|
|
||||||
unpacked.map do |time, token|
|
unpacked.map do |time, token|
|
||||||
[Time.at(time), token]
|
[Time.at(time), token]
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ module Suo
|
|||||||
@client.set_cas(@key, newval, cas)
|
@client.set_cas(@key, newval, cas)
|
||||||
end
|
end
|
||||||
|
|
||||||
def initial_set(val = "")
|
def initial_set(val = BLANK_STR)
|
||||||
@client.set(@key, val)
|
@client.set(@key, val)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
module Suo
|
module Suo
|
||||||
module Client
|
module Client
|
||||||
class Redis < Base
|
class Redis < Base
|
||||||
|
OK_STR = "OK".freeze
|
||||||
|
|
||||||
def initialize(key, options = {})
|
def initialize(key, options = {})
|
||||||
options[:client] ||= ::Redis.new(options[:connection] || {})
|
options[:client] ||= ::Redis.new(options[:connection] || {})
|
||||||
super
|
super
|
||||||
@@ -21,7 +23,7 @@ module Suo
|
|||||||
multi.set(@key, newval)
|
multi.set(@key, newval)
|
||||||
end
|
end
|
||||||
|
|
||||||
ret && ret[0] == "OK"
|
ret && ret[0] == OK_STR
|
||||||
end
|
end
|
||||||
|
|
||||||
def synchronize
|
def synchronize
|
||||||
@@ -32,7 +34,7 @@ module Suo
|
|||||||
@client.unwatch
|
@client.unwatch
|
||||||
end
|
end
|
||||||
|
|
||||||
def initial_set(val = "")
|
def initial_set(val = BLANK_STR)
|
||||||
@client.set(@key, val)
|
@client.set(@key, val)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
module Suo
|
module Suo
|
||||||
VERSION = "0.3.0"
|
VERSION = "0.3.1"
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user