redis_buddy 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ redis_buddy.tmproj
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in redis_buddy.gemspec
4
+ gemspec
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Ole Riesenberg
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -22,6 +22,4 @@
22
22
 
23
23
  ## Copyright
24
24
 
25
- (c) 2010 Ole Riesenberg, released under the MIT license
26
-
27
- redis-store (c) 2009 Luca Guidi - [http://lucaguidi.com](http://lucaguidi.com), released under the MIT license
25
+ (c) 2011 Ole Riesenberg, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -5,9 +5,9 @@ class RedisFactory
5
5
  def create(*addresses)
6
6
  addresses = extract_addresses(addresses)
7
7
  if addresses.size > 1
8
- DistributedMarshaledRedis.new addresses
8
+ Redis::Distributed.new addresses
9
9
  else
10
- JsonRedis.new addresses.first || {}
10
+ Redis.new addresses.first || {}
11
11
  end
12
12
  end
13
13
 
@@ -4,60 +4,99 @@ module ActiveSupport
4
4
  def initialize(*adresses)
5
5
  ns = Rails.application.class.to_s.split('::').first.downcase
6
6
  @r = RedisFactory.create(adresses)
7
- @data = Redis::Namespace.new(ns, :redis => @r)
7
+ @client = Redis::Namespace.new(ns, :redis => @r)
8
8
  end
9
9
 
10
- def write(key, value, options = nil)
11
- method = options && options[:unless_exist] ? :set_unless_exists : :set
10
+ def write(key, value, options = {})
11
+ method = :getset if options[:return]
12
+ method = :setnx if options[:nx]
13
+ method, ttl = :setex, options[:ttl] if options[:ttl]
14
+ method = :set unless method
15
+ value = encode(value)
12
16
 
13
- if options && options[:expire]
14
- if (info.is_a?(Array) ? info.first['redis_version'] : info['redis_version']) <= '1.2.6'
15
- @data.send(:set, key, value)
16
- @data.send(:expire, key, options[:expire])
17
- else
18
- @data.send(:setex, key, value,options[:expire])
19
- end
20
- else
21
- @data.send(method, key, value)
22
- end
17
+ ttl ? @client.send(method, key, ttl, value) : @client.send(method, key, value)
18
+ end
19
+
20
+ def push(key, value)
21
+ @client.lpush(key, encode(value))
22
+ end
23
+
24
+ def increment(key, amount = nil)
25
+ amount.nil? ? @client.incr(key) : @client.incrby(key, amount)
26
+ end
27
+
28
+ def decrement(key, amount = nil)
29
+ amount.nil? ? @client.decr(key) : @client.decrby(key, amount)
30
+ end
31
+
32
+ def expire_in(key, ttl)
33
+ @client.expire(key, ttl)
34
+ end
35
+
36
+ def exipire_at(key, time)
37
+ @client.exipireat(key, time)
23
38
  end
24
39
 
25
40
  def read(key)
26
- @data.get(key)
41
+ value = @client.get(key)
42
+ value ? decode(value) : nil
27
43
  end
28
44
 
29
- def ttl(key)
30
- @data.ttl(key)
45
+ def pop(key)
46
+ value = @client.rpop(key)
47
+ value ? decode(value) : nil
31
48
  end
32
49
 
33
- def delete(key)
34
- @data.del(key)
50
+ def length(key)
51
+ @client.llen(key)
35
52
  end
36
53
 
37
- def exist?(key)
38
- @data.exists(key)
54
+ def ttl(key)
55
+ @client.ttl(key)
39
56
  end
40
57
 
41
- def increment(key, amount = nil)
42
- amount.nil? ? @data.incr(key) : @data.incrby(key, amount)
58
+ def type(key)
59
+ @client.type(key)
43
60
  end
44
61
 
45
- def decrement(key, amount = nil)
46
- amount.nil? ? @data.decr(key) : @data.decrby(key, amount)
62
+ def exists?(key)
63
+ @client.exists(key)
47
64
  end
48
65
 
49
- def delete_matched(matcher)
50
- super do
51
- @data.keys(matcher).each { |key| @data.del(key) }
52
- end
66
+ def delete(key)
67
+ @client.del(key)
53
68
  end
54
69
 
55
70
  def clear
56
- @data.flushdb
71
+ @client.flushdb
57
72
  end
58
73
 
59
74
  def info
60
- @data.info
75
+ @client.info
76
+ end
77
+
78
+ def keys(pattern = "*")
79
+ @client.keys(pattern)
80
+ end
81
+
82
+ def client
83
+ @client
84
+ end
85
+
86
+ private
87
+ def decode(value)
88
+ value = Yajl.load(value)
89
+ value.with_indifferent_access if value.is_a?(Hash)
90
+ value
91
+ end
92
+
93
+ def encode(value)
94
+ return value unless encode?(value)
95
+ Yajl.dump(value)
96
+ end
97
+
98
+ def encode?(value)
99
+ !value.is_a?(Integer)
61
100
  end
62
101
  end
63
102
  end
@@ -0,0 +1,3 @@
1
+ module RedisBuddy
2
+ VERSION = "0.3.0"
3
+ end
data/lib/redis_buddy.rb CHANGED
@@ -1,11 +1,3 @@
1
- require 'redis'
2
- require 'redis/distributed'
3
- require 'redis/namespace'
4
-
5
- require 'redis/redis_factory'
6
- require 'redis/json_redis'
7
- require 'redis/distributed_json_redis'
8
- require 'redis/marshaled_redis'
9
- require 'redis/distributed_marshaled_redis'
10
-
11
- require 'redis_buddy/cache_store'
1
+ module RedisBuddy
2
+ # Your code goes here...
3
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "redis_buddy/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "redis_buddy"
7
+ s.version = RedisBuddy::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Ole Riesenberg"]
10
+ s.email = ["or@buddybrand.com"]
11
+ s.homepage = "http://rubygems.org/gems/redis_buddy"
12
+ s.summary = %q{A namespaced Redis Cache Store for Rails 3}
13
+ s.description = %q{A namespaced Redis Cache Store for Rails 3}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ Gem::Specification.new do |s|
21
+ s.add_dependency(%q<redis>, ["~> 2.1.1"])
22
+ s.add_dependency(%q<redis-namespace>, [">= 0.10.0"])
23
+ s.add_dependency(%q<yajl-ruby>, [">= 0"])
24
+ end
25
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_buddy
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 19
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
- - 2
8
- - 1
9
- version: 0.2.1
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Ole Riesenberg
@@ -14,76 +15,37 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-10-07 00:00:00 +02:00
18
+ date: 2011-02-16 00:00:00 +01:00
18
19
  default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: redis
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ~>
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 2
30
- - 0
31
- - 6
32
- version: 2.0.6
33
- type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: redis-namespace
37
- prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- segments:
44
- - 0
45
- - 8
46
- - 0
47
- version: 0.8.0
48
- type: :runtime
49
- version_requirements: *id002
50
- - !ruby/object:Gem::Dependency
51
- name: yajl-ruby
52
- prerelease: false
53
- requirement: &id003 !ruby/object:Gem::Requirement
54
- none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- segments:
59
- - 0
60
- version: "0"
61
- type: :runtime
62
- version_requirements: *id003
63
- description: A namespaced Redis Cache Store for Rails 3, based on redis-store
64
- email: labs@buddybrand.de
20
+ dependencies: []
21
+
22
+ description: A namespaced Redis Cache Store for Rails 3
23
+ email:
24
+ - or@buddybrand.com
65
25
  executables: []
66
26
 
67
27
  extensions: []
68
28
 
69
- extra_rdoc_files:
70
- - README.md
29
+ extra_rdoc_files: []
30
+
71
31
  files:
72
- - lib/redis/distributed_json_redis.rb
73
- - lib/redis/distributed_marshaled_redis.rb
74
- - lib/redis/json_redis.rb
75
- - lib/redis/marshaled_redis.rb
32
+ - .gitignore
33
+ - Gemfile
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
76
37
  - lib/redis/redis_factory.rb
77
38
  - lib/redis_buddy.rb
78
39
  - lib/redis_buddy/cache_store.rb
79
- - README.md
40
+ - lib/redis_buddy/version.rb
41
+ - redis_buddy.gemspec
80
42
  has_rdoc: true
81
- homepage: http://buddybrand.de
43
+ homepage: http://rubygems.org/gems/redis_buddy
82
44
  licenses: []
83
45
 
84
46
  post_install_message:
85
- rdoc_options:
86
- - --charset=UTF-8
47
+ rdoc_options: []
48
+
87
49
  require_paths:
88
50
  - lib
89
51
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -91,6 +53,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
53
  requirements:
92
54
  - - ">="
93
55
  - !ruby/object:Gem::Version
56
+ hash: 3
94
57
  segments:
95
58
  - 0
96
59
  version: "0"
@@ -99,13 +62,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
62
  requirements:
100
63
  - - ">="
101
64
  - !ruby/object:Gem::Version
65
+ hash: 3
102
66
  segments:
103
67
  - 0
104
68
  version: "0"
105
69
  requirements: []
106
70
 
107
71
  rubyforge_project:
108
- rubygems_version: 1.3.7
72
+ rubygems_version: 1.4.1
109
73
  signing_key:
110
74
  specification_version: 3
111
75
  summary: A namespaced Redis Cache Store for Rails 3
@@ -1,14 +0,0 @@
1
- class DistributedJsonRedis < Redis::Distributed
2
-
3
- # backwards compat
4
- def self.inherited(child)
5
- ActiveSupport::Deprecation.warn("#{child.to_s} is deprecated. Use DistributedJsonRedis instead.") if defined?(ActiveSupport::Deprecation)
6
- end
7
-
8
- def initialize(addresses)
9
- nodes = addresses.map do |address|
10
- JsonRedis.new(address)
11
- end
12
- @ring = Redis::HashRing.new(nodes)
13
- end
14
- end
@@ -1,4 +0,0 @@
1
- # backwards compat
2
- class DistributedMarshaledRedis < DistributedJsonRedis
3
- end
4
-
@@ -1,29 +0,0 @@
1
- class JsonRedis < Redis
2
-
3
- # backwards compat
4
- def self.inherited(child)
5
- ActiveSupport::Deprecation.warn("#{child.to_s} is deprecated. Use JsonRedis instead.") if defined?(ActiveSupport::Deprecation)
6
- end
7
-
8
- def set(key, value)
9
- value = Yajl.dump(value) if encode?(value)
10
- super(key, value)
11
- end
12
-
13
- def setex(key, value, expires)
14
- value = Yajl.dump(value) if encode?(value)
15
- super(key, value, expires)
16
- end
17
-
18
- def get(key)
19
- result = @client.call(:get, key)
20
- result = Yajl.load(result) if result
21
- result
22
- end
23
-
24
- private
25
- def encode?(value)
26
- !value.is_a?(Integer)
27
- end
28
- end
29
-
@@ -1,4 +0,0 @@
1
- # backwards compat
2
- class MarshaledRedis < JsonRedis
3
- end
4
-