Skip to content

Commit 06d296c

Browse files
committed
first commit
0 parents  commit 06d296c

19 files changed

+955
-0
lines changed

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.DS_Store
2+
*.gem
3+
*.rbc
4+
.bundle
5+
.config
6+
.yardoc
7+
Gemfile.lock
8+
InstalledFiles
9+
_yardoc
10+
coverage
11+
doc/
12+
lib/bundler/man
13+
pkg
14+
rdoc
15+
spec/reports
16+
test/tmp
17+
test/version_tmp
18+
tmp

.rubocop.yml

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
AllCops:
2+
Exclude:
3+
- .git/**/*
4+
- tmp/**/*
5+
- suo.gemspec
6+
7+
Lint/DuplicateMethods:
8+
Enabled: true
9+
10+
Lint/DeprecatedClassMethods:
11+
Enabled: true
12+
13+
Style/TrailingWhitespace:
14+
Enabled: true
15+
16+
Style/Tab:
17+
Enabled: true
18+
19+
Style/TrailingBlankLines:
20+
Enabled: true
21+
22+
Style/NilComparison:
23+
Enabled: true
24+
25+
Style/NonNilCheck:
26+
Enabled: true
27+
28+
Style/Not:
29+
Enabled: true
30+
31+
Style/RedundantReturn:
32+
Enabled: true
33+
34+
Style/ClassCheck:
35+
Enabled: true
36+
37+
Style/EmptyLines:
38+
Enabled: true
39+
40+
Style/EmptyLiteral:
41+
Enabled: true
42+
43+
Style/Alias:
44+
Enabled: true
45+
46+
Style/MethodCallParentheses:
47+
Enabled: true
48+
49+
Style/MethodDefParentheses:
50+
Enabled: true
51+
52+
Style/SpaceBeforeBlockBraces:
53+
Enabled: true
54+
55+
Style/SpaceInsideBlockBraces:
56+
Enabled: true
57+
58+
Style/SpaceInsideParens:
59+
Enabled: true
60+
61+
Style/DeprecatedHashMethods:
62+
Enabled: true
63+
64+
Style/HashSyntax:
65+
Enabled: true
66+
67+
Style/SpaceInsideHashLiteralBraces:
68+
Enabled: true
69+
EnforcedStyle: no_space
70+
71+
Style/SpaceInsideBrackets:
72+
Enabled: true
73+
74+
Style/AndOr:
75+
Enabled: false
76+
77+
Style/TrailingComma:
78+
Enabled: true
79+
80+
Style/SpaceBeforeComma:
81+
Enabled: true
82+
83+
Style/SpaceBeforeComment:
84+
Enabled: true
85+
86+
Style/SpaceBeforeSemicolon:
87+
Enabled: true
88+
89+
Style/SpaceAroundBlockParameters:
90+
Enabled: true
91+
92+
Style/SpaceAroundOperators:
93+
Enabled: true
94+
95+
Style/SpaceAfterColon:
96+
Enabled: true
97+
98+
Style/SpaceAfterComma:
99+
Enabled: true
100+
101+
Style/SpaceAfterControlKeyword:
102+
Enabled: true
103+
104+
Style/SpaceAfterNot:
105+
Enabled: true
106+
107+
Style/SpaceAfterSemicolon:
108+
Enabled: true
109+
110+
Lint/UselessComparison:
111+
Enabled: true
112+
113+
Lint/InvalidCharacterLiteral:
114+
Enabled: true
115+
116+
Lint/LiteralInInterpolation:
117+
Enabled: true
118+
119+
Lint/LiteralInCondition:
120+
Enabled: true
121+
122+
Lint/UnusedBlockArgument:
123+
Enabled: true
124+
125+
Style/VariableInterpolation:
126+
Enabled: true
127+
128+
Style/RedundantSelf:
129+
Enabled: true
130+
131+
Style/ParenthesesAroundCondition:
132+
Enabled: true
133+
134+
Style/WhileUntilDo:
135+
Enabled: true
136+
137+
Style/EmptyLineBetweenDefs:
138+
Enabled: true
139+
140+
Style/EmptyLinesAroundAccessModifier:
141+
Enabled: true
142+
143+
Style/EmptyLinesAroundMethodBody:
144+
Enabled: true
145+
146+
Style/ColonMethodCall:
147+
Enabled: true
148+
149+
Lint/SpaceBeforeFirstArg:
150+
Enabled: true
151+
152+
Lint/UnreachableCode:
153+
Enabled: true
154+
155+
Style/UnlessElse:
156+
Enabled: true
157+
158+
Style/ClassVars:
159+
Enabled: true
160+
161+
Style/StringLiterals:
162+
Enabled: true
163+
EnforcedStyle: double_quotes
164+
165+
Metrics/CyclomaticComplexity:
166+
Max: 8
167+
168+
Metrics/LineLength:
169+
Max: 128
170+
171+
Metrics/MethodLength:
172+
Max: 32
173+
174+
Metrics/PerceivedComplexity:
175+
Max: 8
176+
177+
# Disabled
178+
179+
Style/EvenOdd:
180+
Enabled: false
181+
182+
Style/AsciiComments:
183+
Enabled: false
184+
185+
Style/NumericLiterals:
186+
Enabled: false
187+
188+
Style/UnneededPercentQ:
189+
Enabled: false
190+
191+
Style/SpecialGlobalVars:
192+
Enabled: false
193+
194+
Style/TrivialAccessors:
195+
Enabled: false
196+
197+
Style/PerlBackrefs:
198+
Enabled: false
199+
200+
Metrics/AbcSize:
201+
Enabled: false
202+
203+
Metrics/BlockNesting:
204+
Enabled: false
205+
206+
Metrics/ClassLength:
207+
Enabled: false
208+
209+
Metrics/MethodLength:
210+
Enabled: false
211+
212+
Metrics/ParameterLists:
213+
Enabled: false
214+
215+
Metrics/PerceivedComplexity:
216+
Enabled: false

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: ruby
2+
rvm:
3+
- 2.2.0

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.1.0
2+
3+
- First release

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source "https://rubygems.org"
2+
3+
gemspec

README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Suo
2+
3+
:lock: Distributed semaphores using Memcached or Redis in Ruby.
4+
5+
Suo provides a very performant distributed lock solution using Compare-And-Set (`CAS`) commands in Memcached, and `WATCH/MULTI` in Redis.
6+
7+
## Installation
8+
9+
Add this line to your application’s Gemfile:
10+
11+
```ruby
12+
gem 'suo'
13+
```
14+
15+
## Usage
16+
17+
### Basic
18+
19+
```ruby
20+
# Memcached
21+
suo = Suo::Client::Memcached.new(connection: "127.0.0.1:11211")
22+
23+
# Redis
24+
suo = Suo::Client::Redis.new(connection: {host: "10.0.1.1"})
25+
26+
# Pre-existing client
27+
suo = Suo::Client::Memcached.new(client: some_dalli_client)
28+
29+
suo.lock("some_key") do
30+
# critical code here
31+
@puppies.pet!
32+
end
33+
34+
2.times do
35+
Thread.new do
36+
# second argument is the number of resources - so this will run twice
37+
suo.lock("other_key", 2, timeout: 0.5) { puts "Will run twice!" }
38+
end
39+
end
40+
```
41+
42+
## TODO
43+
- better stale key handling (refresh blocks)
44+
- more race condition tests
45+
- refactor clients to re-use more code
46+
47+
## History
48+
49+
View the [changelog](https://github.com/nickelser/suo/blob/master/CHANGELOG.md)
50+
51+
## Contributing
52+
53+
Everyone is encouraged to help improve this project. Here are a few ways you can help:
54+
55+
- [Report bugs](https://github.com/nickelser/suo/issues)
56+
- Fix bugs and [submit pull requests](https://github.com/nickelser/suo/pulls)
57+
- Write, clarify, or fix documentation
58+
- Suggest or add new features

Rakefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require "bundler/gem_tasks"
2+
require "rake/testtask"
3+
4+
Rake::TestTask.new do |t|
5+
t.libs << "test"
6+
t.pattern = "test/*_test.rb"
7+
end

bin/console

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env ruby
2+
3+
require "bundler/setup"
4+
require "suo"
5+
require "irb"
6+
7+
IRB.start

bin/setup

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
5+
bundle install

lib/suo.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require "suo/version"
2+
require "suo/clients"

0 commit comments

Comments
 (0)