bramble 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/bramble.rb +5 -0
- data/lib/bramble/conf.rb +1 -0
- data/lib/bramble/storage.rb +2 -1
- data/lib/bramble/storage/memory_storage.rb +4 -0
- data/lib/bramble/storage/redis_storage.rb +25 -10
- data/lib/bramble/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cec341f5da2fa1d4765e26f65ab96f9e7e773b1
|
4
|
+
data.tar.gz: aaeb464f20cc7c2d24d1e73e0db91e9049d6a60c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7d1ac3785451be8acdbc2f75fe68052e24ad1621d0c2ff811e12c77cf02c3abfd7150d0b31ac669e8471f7568b36ce8a4f58a6874e2dc3ef73a9296dd503daf
|
7
|
+
data.tar.gz: d53b58cc360b9acfc961e85ccb58c43135ea1c4d03da17a07565e80f8ce8c47adecf5fdff056493abff02dea09ce2cfe4d210c05ae677bff2b8935afe488d5fb
|
data/README.md
CHANGED
@@ -16,6 +16,10 @@ We have some staff-only views that expose stats about how people use our app. Ev
|
|
16
16
|
my_redis_connection = Redis.new # Your connection settings here!
|
17
17
|
Bramble.config do |conf|
|
18
18
|
conf.redis_conn = my_redis_connection
|
19
|
+
# By default, keys expire after 1 day.
|
20
|
+
# Assign a value here to override that:
|
21
|
+
# conf.expire_after = 60 * 60 * 24 * 7 # 7 days
|
22
|
+
# conf.expire_after = nil # never expire
|
19
23
|
end
|
20
24
|
```
|
21
25
|
|
@@ -91,6 +95,12 @@ We have some staff-only views that expose stats about how people use our app. Ev
|
|
91
95
|
Bramble.delete("shakespeare-letter-count")
|
92
96
|
```
|
93
97
|
|
98
|
+
Or delete everything:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
Bramble.delete_all
|
102
|
+
```
|
103
|
+
|
94
104
|
## Todo
|
95
105
|
|
96
106
|
- Write some more adapters: Memcached, ActiveRecord
|
data/lib/bramble.rb
CHANGED
data/lib/bramble/conf.rb
CHANGED
data/lib/bramble/storage.rb
CHANGED
@@ -4,43 +4,48 @@ module Bramble
|
|
4
4
|
module_function
|
5
5
|
|
6
6
|
def set(key, value)
|
7
|
-
|
7
|
+
redis_send(:set, key, value)
|
8
8
|
end
|
9
9
|
|
10
10
|
def get(key)
|
11
|
-
|
11
|
+
redis_send(:get, key)
|
12
12
|
end
|
13
13
|
|
14
14
|
def delete(key)
|
15
|
-
|
15
|
+
redis_send(:del, key)
|
16
16
|
end
|
17
17
|
|
18
18
|
def increment(key)
|
19
|
-
|
19
|
+
redis_send(:incr, key)
|
20
20
|
end
|
21
21
|
|
22
22
|
def map_result_push(key, value)
|
23
|
-
|
23
|
+
redis_send(:rpush, key, value)
|
24
24
|
end
|
25
25
|
|
26
26
|
def map_result_get(key)
|
27
|
-
|
27
|
+
redis_send(:lrange, key, 0, -1)
|
28
28
|
end
|
29
29
|
|
30
30
|
def reduce_result_set(storage_key, reduce_key, value)
|
31
|
-
|
31
|
+
redis_send(:hset, storage_key, reduce_key, value)
|
32
32
|
end
|
33
33
|
|
34
34
|
def reduce_result_get(storage_key)
|
35
|
-
|
35
|
+
redis_send(:hgetall, storage_key)
|
36
36
|
end
|
37
37
|
|
38
38
|
def map_keys_push(key, value)
|
39
|
-
|
39
|
+
redis_send(:sadd, key, value)
|
40
40
|
end
|
41
41
|
|
42
42
|
def map_keys_get(key)
|
43
|
-
|
43
|
+
redis_send(:smembers, key)
|
44
|
+
end
|
45
|
+
|
46
|
+
def delete_all
|
47
|
+
all_keys = redis_conn.keys("#{Bramble.config.namespace}*")
|
48
|
+
redis_conn.del(*all_keys)
|
44
49
|
end
|
45
50
|
|
46
51
|
private
|
@@ -50,6 +55,16 @@ module Bramble
|
|
50
55
|
def redis_conn
|
51
56
|
Bramble.config.redis_conn
|
52
57
|
end
|
58
|
+
|
59
|
+
def expire_after
|
60
|
+
Bramble.config.expire_after
|
61
|
+
end
|
62
|
+
|
63
|
+
def redis_send(operation, key, *args)
|
64
|
+
res = redis_conn.public_send(operation, key, *args)
|
65
|
+
expire_after && redis_conn.expire(key, expire_after)
|
66
|
+
res
|
67
|
+
end
|
53
68
|
end
|
54
69
|
end
|
55
70
|
end
|
data/lib/bramble/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bramble
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Mosolgo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|