redisstore 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aecc22797bd2314d48b08ed839a5473db6f3b274
4
+ data.tar.gz: 81c2fb62c007fe58e41aabf4eec927d85f220e51
5
+ SHA512:
6
+ metadata.gz: 7ec93b0468feb8f0b0b39c6d3e1d36624dab7874b07175868218e260d9e2c603be7221dc50839cd2049c30c270e5418b6906904edc04692eceefab4220989b93
7
+ data.tar.gz: 4012eb31eb4a7899192d6cb679cd2101c2a7530764f0846f41b7596209c3e49d04034c27e8b4af28e221b5bc3cf51c67c131d29d0424575ded41dd3dd9470a1b
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg/*.gem
2
+ coverage/
3
+ .coveralls.yml
4
+ .bundle
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format Fuubar
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ Encoding:
2
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.1.0
5
+ - 2.0.0
6
+ - 1.9.3
7
+ services:
8
+ - redis-server
9
+ notifications:
10
+ email: false
11
+ irc:
12
+ channels:
13
+ - ircs://irc.oftc.net:6697#akerl
14
+ channel_key: sekrit
15
+ template:
16
+ - '%{repository}/%{branch}/%{build_number}: %{message} -- %{build_url}'
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
data/Gemfile.lock ADDED
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ redisstore (0.0.1)
5
+ basiccache
6
+ redis
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (1.1.0)
12
+ basiccache (0.0.29)
13
+ coveralls (0.7.0)
14
+ multi_json (~> 1.3)
15
+ rest-client
16
+ simplecov (>= 0.7)
17
+ term-ansicolor
18
+ thor
19
+ diff-lcs (1.2.5)
20
+ docile (1.1.1)
21
+ fuubar (1.3.2)
22
+ rspec (>= 2.14.0, < 3.1.0)
23
+ ruby-progressbar (~> 1.3)
24
+ hashr (0.0.22)
25
+ mime-types (2.0)
26
+ multi_json (1.8.2)
27
+ parser (2.1.1)
28
+ ast (~> 1.1)
29
+ slop (~> 3.4, >= 3.4.5)
30
+ powerpack (0.0.9)
31
+ rainbow (1.99.1)
32
+ rake (10.1.1)
33
+ redis (3.0.6)
34
+ rest-client (1.6.7)
35
+ mime-types (>= 1.16)
36
+ rspec (2.14.1)
37
+ rspec-core (~> 2.14.0)
38
+ rspec-expectations (~> 2.14.0)
39
+ rspec-mocks (~> 2.14.0)
40
+ rspec-core (2.14.7)
41
+ rspec-expectations (2.14.4)
42
+ diff-lcs (>= 1.1.3, < 2.0)
43
+ rspec-mocks (2.14.4)
44
+ rubocop (0.16.0)
45
+ parser (~> 2.1)
46
+ powerpack (~> 0.0.6)
47
+ rainbow (>= 1.1.4)
48
+ ruby-progressbar (1.4.0)
49
+ simplecov (0.8.2)
50
+ docile (~> 1.1.0)
51
+ multi_json
52
+ simplecov-html (~> 0.8.0)
53
+ simplecov-html (0.8.0)
54
+ slop (3.4.7)
55
+ term-ansicolor (1.2.2)
56
+ tins (~> 0.8)
57
+ thor (0.18.1)
58
+ tins (0.13.1)
59
+ travis-lint (1.7.0)
60
+ hashr (~> 0.0.22)
61
+
62
+ PLATFORMS
63
+ ruby
64
+
65
+ DEPENDENCIES
66
+ coveralls
67
+ fuubar
68
+ parser (~> 2.1.0.pre1)
69
+ rake
70
+ redisstore!
71
+ rspec
72
+ rubocop
73
+ travis-lint
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Les Aker
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ redisstore
2
+ =========
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/redisstore.png)](http://badge.fury.io/rb/redisstore)
5
+ [![Dependency Status](https://gemnasium.com/akerl/redisstore.png)](https://gemnasium.com/akerl/redisstore)
6
+ [![Code Climate](https://codeclimate.com/github/akerl/redisstore.png)](https://codeclimate.com/github/akerl/redisstore)
7
+ [![Coverage Status](https://coveralls.io/repos/akerl/redisstore/badge.png?branch=master)](https://coveralls.io/r/akerl/redisstore?branch=master)
8
+ [![Build Status](https://travis-ci.org/akerl/redisstore.png?branch=master)](https://travis-ci.org/akerl/redisstore)
9
+
10
+ Redis storage backend for [BasicCache](https://github.com/akerl/basiccache)
11
+
12
+ ## Usage
13
+
14
+ ```
15
+ require 'basiccache'
16
+ require 'redisstore'
17
+
18
+ store = RedisStore.new(host: '1.2.3.4', port: 1234)
19
+ cache = BasicCache.new store
20
+ ```
21
+
22
+ Your options when creating the store are passed off to [redis-rb](https://github.com/redis/redis-rb), so you can provide whichever other options you'd like, such as specifying a unix socket or authentication details. Similarly, if your Redis instance is on localhost:6379, you don't need to specify anything.
23
+
24
+ ## Installation
25
+
26
+ gem install redisstore
27
+
28
+ ## License
29
+
30
+ redisstore is released under the MIT License. See the bundled LICENSE file for details.
31
+
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ desc 'Update bundle'
6
+ task :bundle do
7
+ `bundle update`
8
+ end
9
+
10
+ desc 'Run tests'
11
+ RSpec::Core::RakeTask.new(:spec)
12
+
13
+ desc 'Run Rubocop on the gem'
14
+ Rubocop::RakeTask.new(:rubocop) do |task|
15
+ task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
16
+ task.fail_on_error = true
17
+ end
18
+
19
+ desc 'Run travis-lint on .travis.yml'
20
+ task :travislint do
21
+ print 'There is an issue with your .travis.yml' unless system('travis-lint')
22
+ end
23
+
24
+ task default: [:spec, :travislint, :rubocop, :build, :install]
25
+ task release: [:bundle]
data/lib/redisstore.rb ADDED
@@ -0,0 +1,89 @@
1
+ require 'redis'
2
+ require 'json'
3
+
4
+ ##
5
+ # Redis-backed Store designed for BasicCache
6
+
7
+ module RedisStore
8
+ class << self
9
+ ##
10
+ # Insert a helper .new() method for creating a new Store object
11
+
12
+ def new(*args)
13
+ self::Store.new(*args)
14
+ end
15
+ end
16
+
17
+ ##
18
+ # Redis-backed store object
19
+
20
+ class Store
21
+ attr_reader :raw
22
+
23
+ ##
24
+ # Generate an empty store
25
+
26
+ def initialize(params = {})
27
+ @raw = Redis.new(params)
28
+ end
29
+
30
+ ##
31
+ # Clears a specified key or the whole store
32
+
33
+ def clear!(key = nil)
34
+ if key.nil?
35
+ @raw.flushdb && {}
36
+ else
37
+ key = prep(key)
38
+ value = @raw.get key
39
+ @raw.del key
40
+ parse value
41
+ end
42
+ end
43
+
44
+ ##
45
+ # Retrieve a key
46
+
47
+ def [](key)
48
+ parse @raw.get(prep key)
49
+ end
50
+
51
+ ##
52
+ # Set a key
53
+
54
+ def []=(key, value)
55
+ @raw.set prep(key), prep(value)
56
+ end
57
+
58
+ ##
59
+ # Return the size of the store
60
+
61
+ def size
62
+ @raw.dbsize
63
+ end
64
+
65
+ ##
66
+ # Check for a key in the store
67
+
68
+ def include?(key)
69
+ @raw.exists prep(key)
70
+ end
71
+
72
+ ##
73
+ # Array of keys in the store
74
+
75
+ def keys
76
+ @raw.keys.map { |x| parse x }
77
+ end
78
+
79
+ private
80
+
81
+ def prep(object)
82
+ Marshal.dump object
83
+ end
84
+
85
+ def parse(object)
86
+ Marshal.load object
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'redisstore'
3
+ s.version = '0.0.1'
4
+ s.date = Time.now.strftime("%Y-%m-%d")
5
+
6
+ s.summary = 'Redis Store for BasicCache'
7
+ s.description = "Stores cached values in Redis"
8
+ s.authors = ['Les Aker']
9
+ s.email = 'me@lesaker.org'
10
+ s.homepage = 'https://github.com/akerl/redisstore'
11
+ s.license = 'MIT'
12
+
13
+ s.files = `git ls-files`.split
14
+ s.test_files = `git ls-files spec/*`.split
15
+
16
+ s.add_dependency 'basiccache'
17
+ s.add_dependency 'redis'
18
+
19
+ s.add_development_dependency 'rubocop'
20
+ s.add_development_dependency 'travis-lint'
21
+ s.add_development_dependency 'rake'
22
+ s.add_development_dependency 'coveralls'
23
+ s.add_development_dependency 'rspec'
24
+ s.add_development_dependency 'fuubar'
25
+ s.add_development_dependency 'parser', '~> 2.1.0.pre1'
26
+ end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+ require 'set'
3
+
4
+ describe RedisStore do
5
+ describe '#new' do
6
+ it 'creates store objects' do
7
+ expect(RedisStore.new).to be_an_instance_of RedisStore::Store
8
+ end
9
+ end
10
+
11
+ describe RedisStore::Store do
12
+ let(:keys) { [1, 2, 3, 4, 5, :foo, 'foo'].to_set }
13
+ let(:store) do
14
+ store = RedisStore::Store.new
15
+ store.raw.flushdb
16
+ (1..5).each { |i| store[i] = i + 5 }
17
+ store[:foo] = :bar
18
+ store['foo'] = 'bar'
19
+ store
20
+ end
21
+
22
+ describe '#initialize' do
23
+ it 'creates a new store raw object' do
24
+ expect(store.raw).to be_an_instance_of Redis
25
+ end
26
+ end
27
+ describe '#clear!' do
28
+ describe 'when given no argument' do
29
+ it 'empties the store' do
30
+ expect(store.clear!).to eql Hash.new
31
+ end
32
+ end
33
+ describe 'when given an argument' do
34
+ it 'removes a key from the store' do
35
+ old_size = store.size
36
+ store.clear! 1
37
+ expect(store.size).to eql old_size - 1
38
+ end
39
+ end
40
+ end
41
+ describe '#[]' do
42
+ it 'retrieves a key' do
43
+ expect(store[1]).to eql 6
44
+ expect(store[:foo]).to eql :bar
45
+ expect(store['foo']).to eql 'bar'
46
+ end
47
+ end
48
+ describe '#[]=' do
49
+ it 'sets a key' do
50
+ expect(store[6] = 10).to eql 10
51
+ end
52
+ end
53
+ describe '#size' do
54
+ it 'returns the size of the store' do
55
+ expect(store.size).to eql 7
56
+ end
57
+ end
58
+ describe '#include?' do
59
+ it 'checks for a key in the store' do
60
+ expect(store.include? :fish).to be_false
61
+ expect(store.include? 1).to be_true
62
+ end
63
+ end
64
+ describe '#keys' do
65
+ it 'lists the keys in the store' do
66
+ expect(store.keys.to_set).to eql keys
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,10 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+
4
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
5
+ SimpleCov.start do
6
+ add_filter '/spec/'
7
+ end
8
+
9
+ require 'rspec'
10
+ require 'redisstore'
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redisstore
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Les Aker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: basiccache
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: redis
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: travis-lint
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: fuubar
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: parser
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: 2.1.0.pre1
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: 2.1.0.pre1
139
+ description: Stores cached values in Redis
140
+ email: me@lesaker.org
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files: []
144
+ files:
145
+ - .gitignore
146
+ - .rspec
147
+ - .rubocop.yml
148
+ - .travis.yml
149
+ - Gemfile
150
+ - Gemfile.lock
151
+ - LICENSE
152
+ - README.md
153
+ - Rakefile
154
+ - lib/redisstore.rb
155
+ - redisstore.gemspec
156
+ - spec/redisstore_spec.rb
157
+ - spec/spec_helper.rb
158
+ homepage: https://github.com/akerl/redisstore
159
+ licenses:
160
+ - MIT
161
+ metadata: {}
162
+ post_install_message:
163
+ rdoc_options: []
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - '>='
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - '>='
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ requirements: []
177
+ rubyforge_project:
178
+ rubygems_version: 2.0.14
179
+ signing_key:
180
+ specification_version: 4
181
+ summary: Redis Store for BasicCache
182
+ test_files:
183
+ - spec/redisstore_spec.rb
184
+ - spec/spec_helper.rb