redis_notifier 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8304b168f4328e2341feb1ae5d8e6e7257255d1e
4
- data.tar.gz: 59f00c3991471a5db839342c9e1521f136ad33b7
3
+ metadata.gz: 093e0b8a04f3212d26e302cc28fd457654894d1c
4
+ data.tar.gz: d490247df436cfd0a4177a08db021203cb62299c
5
5
  SHA512:
6
- metadata.gz: b0879c3b7f5efe0b8d7d1be8284b50af42fecf7fc59dd981f7f83012a7be1949762f630b27931b8d95296a20b8c5a7c0cd7c671656b892f38d359d405799623e
7
- data.tar.gz: 35d482d305040376ca2a6d04f5f60f20f9ee7c1642ab8bcd1969e97344da133576bef303d5e20d07f2bbee6e92e3b85ea8cb269550b6172fa06274c7ffb3a73a
6
+ metadata.gz: 127750efc33ff3bbdd3e75b8b38fbd1e7180aa477013f9b91c47c40b1dc55eb42b4716376ffa8874a02c35dd800f6b0cab982aad68397fcf9922490dad598f16
7
+ data.tar.gz: dcdf619849ab03fe545b2e6ffb042ffd7a8f5f96d66fca9c3be0c464fb370652f54790c3c6f6b03912040538baa26a2ec09660ee8feb2865f6aa2c960b763d32
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # RedisNotifier
2
2
 
3
- TODO: Write a gem description
3
+ Observe redis keyevent/keyspace and notify
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,7 +20,22 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- TODO: Write usage instructions here
23
+ ```ruby
24
+ require 'redis'
25
+ require 'redis_notifier'
26
+
27
+ redis_notifier = RedisNotifier::Base.new(Redis.new)
28
+
29
+ redis_notifier.on_event(:expired) do |key|
30
+ puts "** #{key} as expired"
31
+ end
32
+
33
+ redis_notifier.observe_key('keys:my_key') do |event|
34
+ puts ">> event '#{event}' on 'keys:my_key"
35
+ end
36
+
37
+ redis_notifier.listen
38
+ ```
24
39
 
25
40
  ## Contributing
26
41
 
@@ -0,0 +1,16 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
+
3
+ require 'redis'
4
+ require 'redis_notifier'
5
+
6
+ redis_notifier = RedisNotifier::Base.new(Redis.new)
7
+
8
+ redis_notifier.on_event(:expired) do |key|
9
+ puts "** #{key} as expired"
10
+ end
11
+
12
+ redis_notifier.observe_key('keys:my_key') do |event|
13
+ puts ">> event '#{event}' on 'keys:my_key"
14
+ end
15
+
16
+ redis_notifier.listen
@@ -1,3 +1,3 @@
1
1
  module RedisNotifier
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -23,16 +23,16 @@ module RedisNotifier
23
23
  @db = db.to_s
24
24
  @redis = redis
25
25
  redis.config(:set, NOTIFY_KEYSPACE_EVENTS, keyspace_config)
26
- @callbacks = { keys: {}, events: {} }
26
+ @callbacks = { key: {}, event: {} }
27
27
  @listened_channels = []
28
28
  end
29
29
 
30
30
  def on_event(event_name, &block)
31
- on :events, event_name, &block
31
+ on :event, event_name, &block
32
32
  end
33
33
 
34
34
  def observe_key(key, &block)
35
- on :keys, key, &block
35
+ on :key, key, &block
36
36
  end
37
37
 
38
38
  def on(type, prefix, &block)
@@ -44,19 +44,20 @@ module RedisNotifier
44
44
  end
45
45
 
46
46
  def build_channel_for(type, prefix)
47
- case type
48
- when :events
49
- "__keyevent@#{db}__:#{prefix}"
50
- when :keys
51
- "__keyspace@#{db}__:#{prefix}"
47
+ namespace = case type
48
+ when :event
49
+ 'keyevent'
50
+ when :key
51
+ 'keyspace'
52
52
  end
53
+ "__#{namespace}@#{db}__:#{prefix}"
53
54
  end
54
55
 
55
56
  def find_type_from(channel)
56
57
  if channel.include?('__keyevent@')
57
- :events
58
+ :event
58
59
  elsif channel.include?('__keyspace@')
59
- :keys
60
+ :key
60
61
  else
61
62
  nil
62
63
  end
@@ -20,5 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "rspec", "~> 3.1.7"
23
+ spec.add_development_dependency 'rspec', '~> 3.1', '>= 3.1.7'
24
24
  end
@@ -0,0 +1,35 @@
1
+ describe RedisNotifier::Base do
2
+
3
+ let(:redis) do
4
+ redis = double(:redis)
5
+ allow(redis).to receive(:config)
6
+ redis
7
+ end
8
+ let(:db) { '0' }
9
+ subject { RedisNotifier::Base.new(redis, db) }
10
+
11
+ describe '#initialize' do
12
+ let(:keyspace_config) { 'foo' }
13
+ it 'calls redis config.' do
14
+ expect(redis).to receive(:config).with(:set, 'notify-keyspace-events', keyspace_config)
15
+ RedisNotifier::Base.new(redis, db, keyspace_config)
16
+ end
17
+ end
18
+
19
+ describe '#build_channel_for' do
20
+ let(:prefix) { 'foo' }
21
+ context 'type is "event"' do
22
+ it { expect(subject.build_channel_for(:event, prefix) ).to eq("__keyevent@#{db}__:#{prefix}") }
23
+ end
24
+ context 'type is "key"' do
25
+ it { expect(subject.build_channel_for(:key, prefix) ).to eq("__keyspace@#{db}__:#{prefix}") }
26
+ end
27
+ end
28
+
29
+ describe '#find_type_from' do
30
+ it { expect(subject.find_type_from('__keyevent@0__:foo')).to eq(:event) }
31
+ it { expect(subject.find_type_from('__keyspace@0__:foo')).to eq(:key) }
32
+ it { expect(subject.find_type_from('foobar')).to be(nil) }
33
+ end
34
+
35
+ end
@@ -0,0 +1,92 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+
18
+ require_relative '../lib/redis_notifier'
19
+
20
+ RSpec.configure do |config|
21
+ # rspec-expectations config goes here. You can use an alternate
22
+ # assertion/expectation library such as wrong or the stdlib/minitest
23
+ # assertions if you prefer.
24
+ config.expect_with :rspec do |expectations|
25
+ # This option will default to `true` in RSpec 4. It makes the `description`
26
+ # and `failure_message` of custom matchers include text for helper methods
27
+ # defined using `chain`, e.g.:
28
+ # be_bigger_than(2).and_smaller_than(4).description
29
+ # # => "be bigger than 2 and smaller than 4"
30
+ # ...rather than:
31
+ # # => "be bigger than 2"
32
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
33
+ end
34
+
35
+ # rspec-mocks config goes here. You can use an alternate test double
36
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
37
+ config.mock_with :rspec do |mocks|
38
+ # Prevents you from mocking or stubbing a method that does not exist on
39
+ # a real object. This is generally recommended, and will default to
40
+ # `true` in RSpec 4.
41
+ mocks.verify_partial_doubles = true
42
+ end
43
+
44
+ # The settings below are suggested to provide a good initial experience
45
+ # with RSpec, but feel free to customize to your heart's content.
46
+ =begin
47
+ # These two settings work together to allow you to limit a spec run
48
+ # to individual examples or groups you care about by tagging them with
49
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
50
+ # get run.
51
+ config.filter_run :focus
52
+ config.run_all_when_everything_filtered = true
53
+
54
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
55
+ # For more details, see:
56
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
57
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
58
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
59
+ config.disable_monkey_patching!
60
+
61
+ # This setting enables warnings. It's recommended, but in some cases may
62
+ # be too noisy due to issues in dependencies.
63
+ config.warnings = true
64
+
65
+ # Many RSpec users commonly either run the entire suite or an individual
66
+ # file, and it's useful to allow more verbose output when running an
67
+ # individual spec file.
68
+ if config.files_to_run.one?
69
+ # Use the documentation formatter for detailed output,
70
+ # unless a formatter has already been configured
71
+ # (e.g. via a command-line flag).
72
+ config.default_formatter = 'doc'
73
+ end
74
+
75
+ # Print the 10 slowest examples and example groups at the
76
+ # end of the spec run, to help surface which specs are running
77
+ # particularly slow.
78
+ config.profile_examples = 10
79
+
80
+ # Run specs in random order to surface order dependencies. If you find an
81
+ # order dependency and want to debug it, you can fix the order by providing
82
+ # the seed, which is printed after each run.
83
+ # --seed 1234
84
+ config.order = :random
85
+
86
+ # Seed global randomization in this process using the `--seed` CLI option.
87
+ # Setting this allows you to use `--seed` to deterministically reproduce
88
+ # test failures related to randomization by passing the same `--seed` value
89
+ # as the one that triggered the failure.
90
+ Kernel.srand config.seed
91
+ =end
92
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-14 00:00:00.000000000 Z
11
+ date: 2014-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -43,6 +43,9 @@ dependencies:
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ - - ">="
46
49
  - !ruby/object:Gem::Version
47
50
  version: 3.1.7
48
51
  type: :development
@@ -50,6 +53,9 @@ dependencies:
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
55
  - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '3.1'
58
+ - - ">="
53
59
  - !ruby/object:Gem::Version
54
60
  version: 3.1.7
55
61
  description: ''
@@ -64,9 +70,12 @@ files:
64
70
  - LICENSE.txt
65
71
  - README.md
66
72
  - Rakefile
73
+ - examples/simple.rb
67
74
  - lib/redis_notifier.rb
68
75
  - lib/redis_notifier/version.rb
69
76
  - redis_notifier.gemspec
77
+ - spec/redis_notifier/base_spec.rb
78
+ - spec/spec_helper.rb
70
79
  homepage: ''
71
80
  licenses:
72
81
  - Copyright Samuel
@@ -91,4 +100,6 @@ rubygems_version: 2.4.2
91
100
  signing_key:
92
101
  specification_version: 4
93
102
  summary: Observe redis keyevent/keyspace and notify
94
- test_files: []
103
+ test_files:
104
+ - spec/redis_notifier/base_spec.rb
105
+ - spec/spec_helper.rb