Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nickelser committed Apr 12, 2015
0 parents commit 06d296c
Show file tree
Hide file tree
Showing 19 changed files with 955 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .gitignore
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
216 changes: 216 additions & 0 deletions .rubocop.yml
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
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: ruby
rvm:
- 2.2.0
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.1.0

- First release
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://rubygems.org"

gemspec
58 changes: 58 additions & 0 deletions README.md
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
7 changes: 7 additions & 0 deletions Rakefile
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
7 changes: 7 additions & 0 deletions bin/console
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
5 changes: 5 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

bundle install
2 changes: 2 additions & 0 deletions lib/suo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require "suo/version"
require "suo/clients"
Loading

0 comments on commit 06d296c

Please sign in to comment.