pubsubstub 0.0.10 → 0.0.11
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.
- checksums.yaml +4 -4
- data/lib/pubsubstub/redis_pub_sub.rb +10 -2
- data/lib/pubsubstub/version.rb +1 -1
- data/spec/redis_pub_sub_spec.rb +17 -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: 47ff717bde3d2e41574d94a5f95e7a01a086c425
|
4
|
+
data.tar.gz: d14af107a0b1be58b2afa83f2a221def5d2a436c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38de78410010ea79af53323418bc7804b47b3b07a3900de2199f7692209b3e16b5e4e317ad48b275dce723c68ebf780bc95e605fae2eda6e7b9a36e5ae5d8ab6
|
7
|
+
data.tar.gz: 0911311b184fce34bf5d3845ebccb9a59e05a8a4ae878fd741b4f656db0bf665c4bd5130446b01257a56fecc1520cab9eb2ecd2ce355165cec899db43d2f5645
|
@@ -1,5 +1,8 @@
|
|
1
1
|
module Pubsubstub
|
2
2
|
class RedisPubSub
|
3
|
+
EVENT_SCORE_THRESHOLD = 1000
|
4
|
+
EXPIRE_THRESHOLD = 24 * 60 * 60
|
5
|
+
|
3
6
|
def initialize(channel_name)
|
4
7
|
@channel_name = channel_name
|
5
8
|
end
|
@@ -38,8 +41,13 @@ module Pubsubstub
|
|
38
41
|
|
39
42
|
class << self
|
40
43
|
def publish(channel_name, event)
|
41
|
-
|
42
|
-
blocking_redis.
|
44
|
+
scrollback = "#{channel_name}.scrollback"
|
45
|
+
blocking_redis.pipelined do
|
46
|
+
blocking_redis.publish("#{channel_name}.pubsub", event.to_json)
|
47
|
+
blocking_redis.zadd(scrollback, event.id, event.to_json)
|
48
|
+
blocking_redis.zremrangebyrank(scrollback, 0, -EVENT_SCORE_THRESHOLD)
|
49
|
+
blocking_redis.expire(scrollback, EXPIRE_THRESHOLD)
|
50
|
+
end
|
43
51
|
end
|
44
52
|
|
45
53
|
def sub
|
data/lib/pubsubstub/version.rb
CHANGED
data/spec/redis_pub_sub_spec.rb
CHANGED
@@ -9,14 +9,30 @@ describe Pubsubstub::RedisPubSub do
|
|
9
9
|
let(:redis) { double('redis') }
|
10
10
|
let(:event) { double('Event', to_json: "event_data", id: 1234) }
|
11
11
|
before {
|
12
|
-
allow(
|
12
|
+
allow(redis).to receive(:pipelined).and_yield
|
13
13
|
}
|
14
14
|
|
15
15
|
it "publishes the event to a redis channel and adds it to the scrollback" do
|
16
|
+
allow(subject).to receive(:blocking_redis) { redis }
|
16
17
|
expect(redis).to receive(:publish).with("test.pubsub", event.to_json)
|
17
18
|
expect(redis).to receive(:zadd).with("test.scrollback", event.id, event.to_json)
|
19
|
+
expect(redis).to receive(:zremrangebyrank).with("test.scrollback", 0, -1000)
|
20
|
+
expect(redis).to receive(:expire).with("test.scrollback", Pubsubstub::RedisPubSub::EXPIRE_THRESHOLD)
|
18
21
|
subject.publish("test", event)
|
19
22
|
end
|
23
|
+
|
24
|
+
it "truncates the scrollback" do
|
25
|
+
count = Pubsubstub::RedisPubSub::EVENT_SCORE_THRESHOLD
|
26
|
+
(1...count).each do |id|
|
27
|
+
event = double(to_json: "event_data #{id}", id: id)
|
28
|
+
subject.publish('test', event)
|
29
|
+
end
|
30
|
+
expect(subject.blocking_redis.zcard("test.scrollback")).to eq(count - 1)
|
31
|
+
|
32
|
+
event = double(to_json: "event_data N", id: count)
|
33
|
+
subject.publish('test', event)
|
34
|
+
expect(subject.blocking_redis.zcard("test.scrollback")).to eq(count - 1)
|
35
|
+
end
|
20
36
|
end
|
21
37
|
end
|
22
38
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pubsubstub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guillaume Malette
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|