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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0be1feb4c9a93a2159aa779214bcab6f29fd5502
4
- data.tar.gz: 3a5f0aba73fc9e83e6b0526f58b8dc179f64c1aa
3
+ metadata.gz: 1cec341f5da2fa1d4765e26f65ab96f9e7e773b1
4
+ data.tar.gz: aaeb464f20cc7c2d24d1e73e0db91e9049d6a60c
5
5
  SHA512:
6
- metadata.gz: 0f91e5dd96320ecc5bd1375a9f6ee8601ba24c06f047e52217216f2fd0c399cc193f742bca15d179ddea6cbeeb17c62420fe7d5bae0cd2fa8235f337970259cf
7
- data.tar.gz: f896f04324b7dccd7960df5e7f6727e6903ccdc37d799e45cc648e1913af2f3e841c17e12f89354800d96e34bddbe04940ced7ea82a2666354dbb265f311a1a6
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
@@ -48,4 +48,9 @@ module Bramble
48
48
  def self.delete(handle)
49
49
  Bramble::State.clear_job(handle)
50
50
  end
51
+
52
+ # Clear _all_ data from Bramble runs
53
+ def self.delete_all
54
+ Bramble::Storage.delete_all
55
+ end
51
56
  end
@@ -1,6 +1,7 @@
1
1
  module Bramble
2
2
  CONF = OpenStruct.new(
3
3
  redis_conn: nil,
4
+ expire_after: 60 * 60 * 24,
4
5
  namespace: "Bramble",
5
6
  queue_as: :bramble,
6
7
  storage: Bramble::Storage::RedisStorage
@@ -12,7 +12,8 @@ module Bramble
12
12
  :set, :get, :delete, :increment,
13
13
  :map_result_push, :map_result_get,
14
14
  :reduce_result_set, :reduce_result_get,
15
- :map_keys_push, :map_keys_get
15
+ :map_keys_push, :map_keys_get,
16
+ :delete_all
16
17
 
17
18
  private
18
19
 
@@ -56,6 +56,10 @@ module Bramble
56
56
  def map_keys_get(key)
57
57
  STORAGE[key] || Set.new
58
58
  end
59
+
60
+ def delete_all
61
+ STORAGE.clear
62
+ end
59
63
  end
60
64
  end
61
65
  end
@@ -4,43 +4,48 @@ module Bramble
4
4
  module_function
5
5
 
6
6
  def set(key, value)
7
- redis_conn.set(key, value)
7
+ redis_send(:set, key, value)
8
8
  end
9
9
 
10
10
  def get(key)
11
- redis_conn.get(key)
11
+ redis_send(:get, key)
12
12
  end
13
13
 
14
14
  def delete(key)
15
- redis_conn.del(key)
15
+ redis_send(:del, key)
16
16
  end
17
17
 
18
18
  def increment(key)
19
- redis_conn.incr(key)
19
+ redis_send(:incr, key)
20
20
  end
21
21
 
22
22
  def map_result_push(key, value)
23
- redis_conn.rpush(key, value)
23
+ redis_send(:rpush, key, value)
24
24
  end
25
25
 
26
26
  def map_result_get(key)
27
- redis_conn.lrange(key, 0, -1)
27
+ redis_send(:lrange, key, 0, -1)
28
28
  end
29
29
 
30
30
  def reduce_result_set(storage_key, reduce_key, value)
31
- redis_conn.hset(storage_key, reduce_key, value)
31
+ redis_send(:hset, storage_key, reduce_key, value)
32
32
  end
33
33
 
34
34
  def reduce_result_get(storage_key)
35
- redis_conn.hgetall(storage_key)
35
+ redis_send(:hgetall, storage_key)
36
36
  end
37
37
 
38
38
  def map_keys_push(key, value)
39
- redis_conn.sadd(key, value)
39
+ redis_send(:sadd, key, value)
40
40
  end
41
41
 
42
42
  def map_keys_get(key)
43
- redis_conn.smembers(key)
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
@@ -1,3 +1,3 @@
1
1
  module Bramble
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  end
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.5.1
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: 2016-07-11 00:00:00.000000000 Z
11
+ date: 2017-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob