forked from nickelser/suo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 06d296c
Showing
19 changed files
with
955 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.DS_Store | ||
*.gem | ||
*.rbc | ||
.bundle | ||
.config | ||
.yardoc | ||
Gemfile.lock | ||
InstalledFiles | ||
_yardoc | ||
coverage | ||
doc/ | ||
lib/bundler/man | ||
pkg | ||
rdoc | ||
spec/reports | ||
test/tmp | ||
test/version_tmp | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
AllCops: | ||
Exclude: | ||
- .git/**/* | ||
- tmp/**/* | ||
- suo.gemspec | ||
|
||
Lint/DuplicateMethods: | ||
Enabled: true | ||
|
||
Lint/DeprecatedClassMethods: | ||
Enabled: true | ||
|
||
Style/TrailingWhitespace: | ||
Enabled: true | ||
|
||
Style/Tab: | ||
Enabled: true | ||
|
||
Style/TrailingBlankLines: | ||
Enabled: true | ||
|
||
Style/NilComparison: | ||
Enabled: true | ||
|
||
Style/NonNilCheck: | ||
Enabled: true | ||
|
||
Style/Not: | ||
Enabled: true | ||
|
||
Style/RedundantReturn: | ||
Enabled: true | ||
|
||
Style/ClassCheck: | ||
Enabled: true | ||
|
||
Style/EmptyLines: | ||
Enabled: true | ||
|
||
Style/EmptyLiteral: | ||
Enabled: true | ||
|
||
Style/Alias: | ||
Enabled: true | ||
|
||
Style/MethodCallParentheses: | ||
Enabled: true | ||
|
||
Style/MethodDefParentheses: | ||
Enabled: true | ||
|
||
Style/SpaceBeforeBlockBraces: | ||
Enabled: true | ||
|
||
Style/SpaceInsideBlockBraces: | ||
Enabled: true | ||
|
||
Style/SpaceInsideParens: | ||
Enabled: true | ||
|
||
Style/DeprecatedHashMethods: | ||
Enabled: true | ||
|
||
Style/HashSyntax: | ||
Enabled: true | ||
|
||
Style/SpaceInsideHashLiteralBraces: | ||
Enabled: true | ||
EnforcedStyle: no_space | ||
|
||
Style/SpaceInsideBrackets: | ||
Enabled: true | ||
|
||
Style/AndOr: | ||
Enabled: false | ||
|
||
Style/TrailingComma: | ||
Enabled: true | ||
|
||
Style/SpaceBeforeComma: | ||
Enabled: true | ||
|
||
Style/SpaceBeforeComment: | ||
Enabled: true | ||
|
||
Style/SpaceBeforeSemicolon: | ||
Enabled: true | ||
|
||
Style/SpaceAroundBlockParameters: | ||
Enabled: true | ||
|
||
Style/SpaceAroundOperators: | ||
Enabled: true | ||
|
||
Style/SpaceAfterColon: | ||
Enabled: true | ||
|
||
Style/SpaceAfterComma: | ||
Enabled: true | ||
|
||
Style/SpaceAfterControlKeyword: | ||
Enabled: true | ||
|
||
Style/SpaceAfterNot: | ||
Enabled: true | ||
|
||
Style/SpaceAfterSemicolon: | ||
Enabled: true | ||
|
||
Lint/UselessComparison: | ||
Enabled: true | ||
|
||
Lint/InvalidCharacterLiteral: | ||
Enabled: true | ||
|
||
Lint/LiteralInInterpolation: | ||
Enabled: true | ||
|
||
Lint/LiteralInCondition: | ||
Enabled: true | ||
|
||
Lint/UnusedBlockArgument: | ||
Enabled: true | ||
|
||
Style/VariableInterpolation: | ||
Enabled: true | ||
|
||
Style/RedundantSelf: | ||
Enabled: true | ||
|
||
Style/ParenthesesAroundCondition: | ||
Enabled: true | ||
|
||
Style/WhileUntilDo: | ||
Enabled: true | ||
|
||
Style/EmptyLineBetweenDefs: | ||
Enabled: true | ||
|
||
Style/EmptyLinesAroundAccessModifier: | ||
Enabled: true | ||
|
||
Style/EmptyLinesAroundMethodBody: | ||
Enabled: true | ||
|
||
Style/ColonMethodCall: | ||
Enabled: true | ||
|
||
Lint/SpaceBeforeFirstArg: | ||
Enabled: true | ||
|
||
Lint/UnreachableCode: | ||
Enabled: true | ||
|
||
Style/UnlessElse: | ||
Enabled: true | ||
|
||
Style/ClassVars: | ||
Enabled: true | ||
|
||
Style/StringLiterals: | ||
Enabled: true | ||
EnforcedStyle: double_quotes | ||
|
||
Metrics/CyclomaticComplexity: | ||
Max: 8 | ||
|
||
Metrics/LineLength: | ||
Max: 128 | ||
|
||
Metrics/MethodLength: | ||
Max: 32 | ||
|
||
Metrics/PerceivedComplexity: | ||
Max: 8 | ||
|
||
# Disabled | ||
|
||
Style/EvenOdd: | ||
Enabled: false | ||
|
||
Style/AsciiComments: | ||
Enabled: false | ||
|
||
Style/NumericLiterals: | ||
Enabled: false | ||
|
||
Style/UnneededPercentQ: | ||
Enabled: false | ||
|
||
Style/SpecialGlobalVars: | ||
Enabled: false | ||
|
||
Style/TrivialAccessors: | ||
Enabled: false | ||
|
||
Style/PerlBackrefs: | ||
Enabled: false | ||
|
||
Metrics/AbcSize: | ||
Enabled: false | ||
|
||
Metrics/BlockNesting: | ||
Enabled: false | ||
|
||
Metrics/ClassLength: | ||
Enabled: false | ||
|
||
Metrics/MethodLength: | ||
Enabled: false | ||
|
||
Metrics/ParameterLists: | ||
Enabled: false | ||
|
||
Metrics/PerceivedComplexity: | ||
Enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
language: ruby | ||
rvm: | ||
- 2.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 0.1.0 | ||
|
||
- First release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source "https://rubygems.org" | ||
|
||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Suo | ||
|
||
:lock: Distributed semaphores using Memcached or Redis in Ruby. | ||
|
||
Suo provides a very performant distributed lock solution using Compare-And-Set (`CAS`) commands in Memcached, and `WATCH/MULTI` in Redis. | ||
|
||
## Installation | ||
|
||
Add this line to your application’s Gemfile: | ||
|
||
```ruby | ||
gem 'suo' | ||
``` | ||
|
||
## Usage | ||
|
||
### Basic | ||
|
||
```ruby | ||
# Memcached | ||
suo = Suo::Client::Memcached.new(connection: "127.0.0.1:11211") | ||
|
||
# Redis | ||
suo = Suo::Client::Redis.new(connection: {host: "10.0.1.1"}) | ||
|
||
# Pre-existing client | ||
suo = Suo::Client::Memcached.new(client: some_dalli_client) | ||
|
||
suo.lock("some_key") do | ||
# critical code here | ||
@puppies.pet! | ||
end | ||
|
||
2.times do | ||
Thread.new do | ||
# second argument is the number of resources - so this will run twice | ||
suo.lock("other_key", 2, timeout: 0.5) { puts "Will run twice!" } | ||
end | ||
end | ||
``` | ||
|
||
## TODO | ||
- better stale key handling (refresh blocks) | ||
- more race condition tests | ||
- refactor clients to re-use more code | ||
|
||
## History | ||
|
||
View the [changelog](https://github.com/nickelser/suo/blob/master/CHANGELOG.md) | ||
|
||
## Contributing | ||
|
||
Everyone is encouraged to help improve this project. Here are a few ways you can help: | ||
|
||
- [Report bugs](https://github.com/nickelser/suo/issues) | ||
- Fix bugs and [submit pull requests](https://github.com/nickelser/suo/pulls) | ||
- Write, clarify, or fix documentation | ||
- Suggest or add new features |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require "bundler/gem_tasks" | ||
require "rake/testtask" | ||
|
||
Rake::TestTask.new do |t| | ||
t.libs << "test" | ||
t.pattern = "test/*_test.rb" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require "bundler/setup" | ||
require "suo" | ||
require "irb" | ||
|
||
IRB.start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
IFS=$'\n\t' | ||
|
||
bundle install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require "suo/version" | ||
require "suo/clients" |
Oops, something went wrong.