mirror of
https://github.com/dkam/suo.git
synced 2025-01-29 07:42:43 +00:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59d3385d8a | ||
|
|
3d5c102c08 | ||
|
|
7bb28cc007 | ||
|
|
65cae9aa58 | ||
|
|
6b6eb4e590 | ||
|
|
485f2bff37 | ||
|
|
3a37a74982 | ||
|
|
b02c256c25 | ||
|
|
d57f6a15ac | ||
|
|
d293ef6fcf | ||
|
|
6e74322ff1 | ||
|
|
b9d3f1b7a1 | ||
|
|
270c05b80e | ||
|
|
60e167e146 | ||
|
|
ad08c8b5ea | ||
|
|
9b8ef6c244 |
38
.github/workflows/CI.yml
vendored
Normal file
38
.github/workflows/CI.yml
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
ruby:
|
||||||
|
- '2.5'
|
||||||
|
- '2.6'
|
||||||
|
- '2.7'
|
||||||
|
- '3.0'
|
||||||
|
- ruby-head
|
||||||
|
continue-on-error: ${{ matrix.ruby == 'ruby-head' }}
|
||||||
|
services:
|
||||||
|
memcached:
|
||||||
|
image: memcached
|
||||||
|
ports:
|
||||||
|
- 11211:11211
|
||||||
|
redis:
|
||||||
|
image: redis
|
||||||
|
ports:
|
||||||
|
- 6379:6379
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: ruby/setup-ruby@v1
|
||||||
|
with:
|
||||||
|
ruby-version: ${{ matrix.ruby }}
|
||||||
|
bundler-cache: true
|
||||||
|
- run: |
|
||||||
|
bundle exec rake
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
language: ruby
|
|
||||||
rvm:
|
|
||||||
- 2.2.6
|
|
||||||
- 2.3.7
|
|
||||||
- 2.4.4
|
|
||||||
- 2.5.1
|
|
||||||
services:
|
|
||||||
- memcached
|
|
||||||
- redis-server
|
|
||||||
11
CHANGELOG.md
11
CHANGELOG.md
@@ -1,3 +1,14 @@
|
|||||||
|
## 0.4.0
|
||||||
|
|
||||||
|
- Monotonic clock for locks, avoiding issues with DST (thanks @doits)
|
||||||
|
- Pooled connection support (thanks @mlarraz)
|
||||||
|
- Switch to Github actions for tests (thanks @mlarraz)
|
||||||
|
- Update supported Ruby versions (thanks @mlarraz & @pat)
|
||||||
|
|
||||||
|
## 0.3.4
|
||||||
|
|
||||||
|
- Support for connection pooling when using memcached locks, via `with` blocks using Dalli (thanks to Lev).
|
||||||
|
|
||||||
## 0.3.3
|
## 0.3.3
|
||||||
|
|
||||||
- Default TTL for keys to allow for short-lived locking keys (thanks to Ian Remillard) without leaking memory.
|
- Default TTL for keys to allow for short-lived locking keys (thanks to Ian Remillard) without leaking memory.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# Suo [](https://travis-ci.org/nickelser/suo) [](https://codeclimate.com/github/nickelser/suo) [](https://codeclimate.com/github/nickelser/suo) [](http://badge.fury.io/rb/suo)
|
# Suo [](https://github.com/nickelser/suo/actions?query=workflow%3ACI) [](https://codeclimate.com/github/nickelser/suo) [](http://badge.fury.io/rb/suo)
|
||||||
|
|
||||||
:lock: Distributed semaphores using Memcached or Redis in Ruby.
|
:lock: Distributed semaphores using Memcached or Redis in Ruby.
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ require "securerandom"
|
|||||||
require "monitor"
|
require "monitor"
|
||||||
|
|
||||||
require "dalli"
|
require "dalli"
|
||||||
require "dalli/cas/client"
|
|
||||||
|
|
||||||
require "redis"
|
require "redis"
|
||||||
|
|
||||||
|
|||||||
@@ -132,10 +132,10 @@ module Suo
|
|||||||
end
|
end
|
||||||
|
|
||||||
def retry_with_timeout
|
def retry_with_timeout
|
||||||
start = Time.now.to_f
|
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
||||||
|
|
||||||
retry_count.times do
|
retry_count.times do
|
||||||
elapsed = Time.now.to_f - start
|
elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
|
||||||
break if elapsed >= options[:acquisition_timeout]
|
break if elapsed >= options[:acquisition_timeout]
|
||||||
|
|
||||||
synchronize do
|
synchronize do
|
||||||
|
|||||||
@@ -7,28 +7,30 @@ module Suo
|
|||||||
end
|
end
|
||||||
|
|
||||||
def clear
|
def clear
|
||||||
@client.delete(@key)
|
@client.with { |client| client.delete(@key) }
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def get
|
def get
|
||||||
@client.get_cas(@key)
|
@client.with { |client| client.get_cas(@key) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def set(newval, cas, expire: false)
|
def set(newval, cas, expire: false)
|
||||||
if expire
|
if expire
|
||||||
@client.set_cas(@key, newval, cas, @options[:ttl])
|
@client.with { |client| client.set_cas(@key, newval, cas, @options[:ttl]) }
|
||||||
else
|
else
|
||||||
@client.set_cas(@key, newval, cas)
|
@client.with { |client| client.set_cas(@key, newval, cas) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def initial_set(val = BLANK_STR)
|
def initial_set(val = BLANK_STR)
|
||||||
@client.set(@key, val)
|
@client.with do |client|
|
||||||
_val, cas = @client.get_cas(@key)
|
client.set(@key, val)
|
||||||
|
_val, cas = client.get_cas(@key)
|
||||||
cas
|
cas
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|||||||
@@ -9,21 +9,31 @@ module Suo
|
|||||||
end
|
end
|
||||||
|
|
||||||
def clear
|
def clear
|
||||||
@client.del(@key)
|
with { |r| r.del(@key) }
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def with(&block)
|
||||||
|
if @client.respond_to?(:with)
|
||||||
|
@client.with(&block)
|
||||||
|
else
|
||||||
|
yield @client
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def get
|
def get
|
||||||
[@client.get(@key), nil]
|
[with { |r| r.get(@key) }, nil]
|
||||||
end
|
end
|
||||||
|
|
||||||
def set(newval, _, expire: false)
|
def set(newval, _, expire: false)
|
||||||
ret = @client.multi do |multi|
|
ret = with do |r|
|
||||||
|
r.multi do |rr|
|
||||||
if expire
|
if expire
|
||||||
multi.setex(@key, @options[:ttl], newval)
|
rr.setex(@key, @options[:ttl], newval)
|
||||||
else
|
else
|
||||||
multi.set(@key, newval)
|
rr.set(@key, newval)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -31,11 +41,9 @@ module Suo
|
|||||||
end
|
end
|
||||||
|
|
||||||
def synchronize
|
def synchronize
|
||||||
@client.watch(@key) do
|
with { |r| r.watch(@key) { yield } }
|
||||||
yield
|
|
||||||
end
|
|
||||||
ensure
|
ensure
|
||||||
@client.unwatch
|
with { |r| r.unwatch }
|
||||||
end
|
end
|
||||||
|
|
||||||
def initial_set(val = BLANK_STR)
|
def initial_set(val = BLANK_STR)
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
module Suo
|
module Suo
|
||||||
VERSION = "0.3.3".freeze
|
VERSION = "0.4.0".freeze
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,14 +19,14 @@ Gem::Specification.new do |spec|
|
|||||||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
||||||
spec.require_paths = ["lib"]
|
spec.require_paths = ["lib"]
|
||||||
|
|
||||||
spec.required_ruby_version = "~> 2.0"
|
spec.required_ruby_version = ">= 2.5"
|
||||||
|
|
||||||
spec.add_dependency "dalli"
|
spec.add_dependency "dalli"
|
||||||
spec.add_dependency "redis"
|
spec.add_dependency "redis"
|
||||||
spec.add_dependency "msgpack"
|
spec.add_dependency "msgpack"
|
||||||
|
|
||||||
spec.add_development_dependency "bundler", "~> 1.5"
|
spec.add_development_dependency "bundler"
|
||||||
spec.add_development_dependency "rake", "~> 10.0"
|
spec.add_development_dependency "rake", "~> 13.0"
|
||||||
spec.add_development_dependency "rubocop", "~> 0.49.0"
|
spec.add_development_dependency "rubocop", "~> 0.49.0"
|
||||||
spec.add_development_dependency "minitest", "~> 5.5.0"
|
spec.add_development_dependency "minitest", "~> 5.5.0"
|
||||||
spec.add_development_dependency "codeclimate-test-reporter", "~> 0.4.7"
|
spec.add_development_dependency "codeclimate-test-reporter", "~> 0.4.7"
|
||||||
|
|||||||
Reference in New Issue
Block a user