redis_buddy 0.3.0 → 0.4.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/README.md +2 -2
- data/lib/redis_buddy/cache_store.rb +98 -100
- data/lib/redis_buddy/version.rb +1 -1
- data/lib/redis_buddy.rb +2 -3
- metadata +3 -3
data/README.md
CHANGED
@@ -13,11 +13,11 @@
|
|
13
13
|
|
14
14
|
### config/application.rb
|
15
15
|
|
16
|
-
config.cache_store =
|
16
|
+
config.cache_store = RedisBuddy::CacheStore.new('127.0.0.1')
|
17
17
|
|
18
18
|
or
|
19
19
|
|
20
|
-
config.cache_store =
|
20
|
+
config.cache_store = RedisBuddy::CacheStore.new(['127.0.0.1', '10.20.1.40'])
|
21
21
|
|
22
22
|
|
23
23
|
## Copyright
|
@@ -1,103 +1,101 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
!value.is_a?(Integer)
|
100
|
-
end
|
1
|
+
module RedisBuddy
|
2
|
+
class CacheStore < ActiveSupport::Cache::Store
|
3
|
+
def initialize(*adresses)
|
4
|
+
ns = Rails.application.class.to_s.split('::').first.downcase
|
5
|
+
@r = RedisFactory.create(adresses)
|
6
|
+
@client = Redis::Namespace.new(ns, :redis => @r)
|
7
|
+
end
|
8
|
+
|
9
|
+
def write(key, value, options = {})
|
10
|
+
method = :getset if options[:return]
|
11
|
+
method = :setnx if options[:nx]
|
12
|
+
method, ttl = :setex, options[:ttl] if options[:ttl]
|
13
|
+
method = :set unless method
|
14
|
+
value = encode(value)
|
15
|
+
|
16
|
+
ttl ? @client.send(method, key, ttl, value) : @client.send(method, key, value)
|
17
|
+
end
|
18
|
+
|
19
|
+
def push(key, value)
|
20
|
+
@client.lpush(key, encode(value))
|
21
|
+
end
|
22
|
+
|
23
|
+
def increment(key, amount = nil)
|
24
|
+
amount.nil? ? @client.incr(key) : @client.incrby(key, amount)
|
25
|
+
end
|
26
|
+
|
27
|
+
def decrement(key, amount = nil)
|
28
|
+
amount.nil? ? @client.decr(key) : @client.decrby(key, amount)
|
29
|
+
end
|
30
|
+
|
31
|
+
def expire_in(key, ttl)
|
32
|
+
@client.expire(key, ttl)
|
33
|
+
end
|
34
|
+
|
35
|
+
def exipire_at(key, time)
|
36
|
+
@client.exipireat(key, time)
|
37
|
+
end
|
38
|
+
|
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
|
+
def length(key)
|
50
|
+
@client.llen(key)
|
51
|
+
end
|
52
|
+
|
53
|
+
def ttl(key)
|
54
|
+
@client.ttl(key)
|
55
|
+
end
|
56
|
+
|
57
|
+
def type(key)
|
58
|
+
@client.type(key)
|
59
|
+
end
|
60
|
+
|
61
|
+
def exists?(key)
|
62
|
+
@client.exists(key)
|
63
|
+
end
|
64
|
+
|
65
|
+
def delete(key)
|
66
|
+
@client.del(key)
|
67
|
+
end
|
68
|
+
|
69
|
+
def clear
|
70
|
+
@client.flushdb
|
71
|
+
end
|
72
|
+
|
73
|
+
def info
|
74
|
+
@client.info
|
75
|
+
end
|
76
|
+
|
77
|
+
def keys(pattern = "*")
|
78
|
+
@client.keys(pattern)
|
79
|
+
end
|
80
|
+
|
81
|
+
def client
|
82
|
+
@client
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
def decode(value)
|
87
|
+
value = Yajl.load(value)
|
88
|
+
value.with_indifferent_access if value.is_a?(Hash)
|
89
|
+
value
|
90
|
+
end
|
91
|
+
|
92
|
+
def encode(value)
|
93
|
+
return value unless encode?(value)
|
94
|
+
Yajl.dump(value)
|
95
|
+
end
|
96
|
+
|
97
|
+
def encode?(value)
|
98
|
+
!value.is_a?(Integer)
|
101
99
|
end
|
102
100
|
end
|
103
101
|
end
|
data/lib/redis_buddy/version.rb
CHANGED
data/lib/redis_buddy.rb
CHANGED
@@ -1,3 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
end
|
1
|
+
require 'redis/redis_factory'
|
2
|
+
require 'redis_buddy/cache_store'
|
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: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 4
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ole Riesenberg
|