redis_buddy 0.4.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/redis_buddy/cache_store.rb +45 -32
- data/lib/redis_buddy/version.rb +1 -1
- metadata +4 -4
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
module RedisBuddy
|
|
2
2
|
class CacheStore < ActiveSupport::Cache::Store
|
|
3
3
|
def initialize(*adresses)
|
|
4
|
-
|
|
4
|
+
options = adresses.extract_options!
|
|
5
|
+
ns = options.delete(:redis_namespace) || Rails.application.class.to_s.split('::').first.downcase
|
|
5
6
|
@r = RedisFactory.create(adresses)
|
|
6
7
|
@client = Redis::Namespace.new(ns, :redis => @r)
|
|
8
|
+
super options
|
|
7
9
|
end
|
|
8
10
|
|
|
9
|
-
def
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
method, ttl = :setex, options[:ttl] if options[:ttl]
|
|
13
|
-
method = :set unless method
|
|
14
|
-
value = encode(value)
|
|
11
|
+
def push(key, value)
|
|
12
|
+
@client.lpush(key, encode(value))
|
|
13
|
+
end
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
def pop(key)
|
|
16
|
+
value = @client.rpop(key)
|
|
17
|
+
value ? decode(value) : nil
|
|
17
18
|
end
|
|
18
19
|
|
|
19
|
-
def
|
|
20
|
-
@client.
|
|
20
|
+
def exist?(key)
|
|
21
|
+
@client.exists(key)
|
|
21
22
|
end
|
|
23
|
+
alias :exists? :exist?
|
|
22
24
|
|
|
23
25
|
def increment(key, amount = nil)
|
|
24
26
|
amount.nil? ? @client.incr(key) : @client.incrby(key, amount)
|
|
@@ -28,6 +30,10 @@ module RedisBuddy
|
|
|
28
30
|
amount.nil? ? @client.decr(key) : @client.decrby(key, amount)
|
|
29
31
|
end
|
|
30
32
|
|
|
33
|
+
def delete_matched(matcher, options = nil)
|
|
34
|
+
delete keys(matcher)
|
|
35
|
+
end
|
|
36
|
+
|
|
31
37
|
def expire_in(key, ttl)
|
|
32
38
|
@client.expire(key, ttl)
|
|
33
39
|
end
|
|
@@ -36,16 +42,6 @@ module RedisBuddy
|
|
|
36
42
|
@client.exipireat(key, time)
|
|
37
43
|
end
|
|
38
44
|
|
|
39
|
-
def read(key)
|
|
40
|
-
value = @client.get(key)
|
|
41
|
-
value ? decode(value) : nil
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def pop(key)
|
|
45
|
-
value = @client.rpop(key)
|
|
46
|
-
value ? decode(value) : nil
|
|
47
|
-
end
|
|
48
|
-
|
|
49
45
|
def length(key)
|
|
50
46
|
@client.llen(key)
|
|
51
47
|
end
|
|
@@ -58,14 +54,6 @@ module RedisBuddy
|
|
|
58
54
|
@client.type(key)
|
|
59
55
|
end
|
|
60
56
|
|
|
61
|
-
def exists?(key)
|
|
62
|
-
@client.exists(key)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def delete(key)
|
|
66
|
-
@client.del(key)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
57
|
def clear
|
|
70
58
|
@client.flushdb
|
|
71
59
|
end
|
|
@@ -74,24 +62,49 @@ module RedisBuddy
|
|
|
74
62
|
@client.info
|
|
75
63
|
end
|
|
76
64
|
|
|
77
|
-
def keys(
|
|
78
|
-
|
|
65
|
+
def keys(matcher = "*", options = nil)
|
|
66
|
+
options = merged_options(options)
|
|
67
|
+
@client.keys namespaced_key(matcher, options)
|
|
79
68
|
end
|
|
80
69
|
|
|
81
70
|
def client
|
|
82
71
|
@client
|
|
83
72
|
end
|
|
84
73
|
|
|
74
|
+
protected
|
|
75
|
+
def write_entry(key, entry, options = {})
|
|
76
|
+
options[:expires_in] = options.delete(:ttl) if options[:ttl]
|
|
77
|
+
options[:unless_exist] = options.delete(:nx) if options[:nx]
|
|
78
|
+
options[:getset] = options.delete(:return) if options[:return]
|
|
79
|
+
|
|
80
|
+
method = :getset if options[:getset]
|
|
81
|
+
method = :setnx if options[:unless_exist]
|
|
82
|
+
method, expires_in = :setex, options[:expires_in] if options[:expires_in]
|
|
83
|
+
method = :set unless method
|
|
84
|
+
entry = encode(entry)
|
|
85
|
+
|
|
86
|
+
expires_in ? @client.send(method, key, expires_in, entry) : @client.send(method, key, entry)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def read_entry(key, options)
|
|
90
|
+
entry = @client.get(key)
|
|
91
|
+
entry ? decode(entry) : nil
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def delete_entry(key, options)
|
|
95
|
+
@client.del(key)
|
|
96
|
+
end
|
|
97
|
+
|
|
85
98
|
private
|
|
86
99
|
def decode(value)
|
|
87
|
-
value =
|
|
100
|
+
value = Marshal.load(value)
|
|
88
101
|
value.with_indifferent_access if value.is_a?(Hash)
|
|
89
102
|
value
|
|
90
103
|
end
|
|
91
104
|
|
|
92
105
|
def encode(value)
|
|
93
106
|
return value unless encode?(value)
|
|
94
|
-
|
|
107
|
+
Marshal.dump(value)
|
|
95
108
|
end
|
|
96
109
|
|
|
97
110
|
def encode?(value)
|
data/lib/redis_buddy/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: redis_buddy
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 23
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
|
+
- 1
|
|
7
8
|
- 0
|
|
8
|
-
- 4
|
|
9
9
|
- 0
|
|
10
|
-
version: 0.
|
|
10
|
+
version: 1.0.0
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Ole Riesenberg
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2011-
|
|
18
|
+
date: 2011-03-17 00:00:00 +01:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies: []
|
|
21
21
|
|