faye-redis 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ### 0.2.0 / 2013-10-01
2
+
3
+ * Migrate from Yajl to MultiJson to support JRuby
4
+ * Trigger `close` event as required by Faye 1.0
5
+
6
+
7
+ ### 0.1.1 / 2013-04-28
8
+
9
+ * Improve garbage collection to avoid leaking Redis memory
10
+
11
+
12
+ ### 0.1.0 / 2012-02-26
13
+
14
+ * Initial release: Redis backend for Faye 0.8
15
+
@@ -0,0 +1,61 @@
1
+ # Faye::Redis [![Build Status](https://travis-ci.org/faye/faye-redis-ruby.png)](https://travis-ci.org/faye/faye-redis-ruby)
2
+
3
+ This plugin provides a Redis-based backend for the
4
+ [Faye](http://faye.jcoglan.com) messaging server. It allows a single Faye
5
+ service to be distributed across many front-end web servers by storing state and
6
+ routing messages through a [Redis](http://redis.io) database server.
7
+
8
+
9
+ ## Usage
10
+
11
+ Pass in the engine and any settings you need when setting up your Faye server.
12
+
13
+ ```rb
14
+ require 'faye'
15
+ require 'faye/redis'
16
+
17
+ bayeux = Faye::RackAdapter.new(
18
+ :mount => '/',
19
+ :timeout => 25,
20
+ :engine => {
21
+ :type => Faye::Redis,
22
+ :host => 'redis.example.com',
23
+ # more options
24
+ }
25
+ )
26
+ ```
27
+
28
+ The full list of settings is as follows.
29
+
30
+ * <b>`:uri`</b> - redis URL (example: `redis://:secretpassword@example.com:9000/4`)
31
+ * <b>`:host`</b> - hostname of your Redis instance
32
+ * <b>`:port`</b> - port number, default is `6379`
33
+ * <b>`:password`</b> - password, if `requirepass` is set
34
+ * <b>`:database`</b> - number of database to use, default is `0`
35
+ * <b>`:namespace`</b> - prefix applied to all keys, default is `''`
36
+ * <b>`:socket`</b> - path to Unix socket if `unixsocket` is set
37
+
38
+
39
+ ## License
40
+
41
+ (The MIT License)
42
+
43
+ Copyright (c) 2011-2013 James Coglan
44
+
45
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
46
+ this software and associated documentation files (the 'Software'), to deal in
47
+ the Software without restriction, including without limitation the rights to
48
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
49
+ the Software, and to permit persons to whom the Software is furnished to do so,
50
+ subject to the following conditions:
51
+
52
+ The above copyright notice and this permission notice shall be included in all
53
+ copies or substantial portions of the Software.
54
+
55
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
56
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
57
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
58
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
59
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
60
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
61
+
@@ -1,5 +1,5 @@
1
1
  require 'em-hiredis'
2
- require 'yajl'
2
+ require 'multi_json'
3
3
 
4
4
  module Faye
5
5
  class Redis
@@ -40,9 +40,14 @@ module Faye
40
40
  end
41
41
  @subscriber = @redis.pubsub
42
42
 
43
- @subscriber.subscribe(@ns + '/notifications')
43
+ @message_channel = @ns + '/notifications/messages'
44
+ @close_channel = @ns + '/notifications/close'
45
+
46
+ @subscriber.subscribe(@message_channel)
47
+ @subscriber.subscribe(@close_channel)
44
48
  @subscriber.on(:message) do |topic, message|
45
- empty_queue(message) if topic == @ns + '/notifications'
49
+ empty_queue(message) if topic == @message_channel
50
+ @server.trigger(:close, message) if topic == @close_channel
46
51
  end
47
52
 
48
53
  @gc = EventMachine.add_periodic_timer(gc, &method(:gc))
@@ -50,7 +55,8 @@ module Faye
50
55
 
51
56
  def disconnect
52
57
  return unless @redis
53
- @subscriber.unsubscribe(@ns + '/notifications')
58
+ @subscriber.unsubscribe(@message_channel)
59
+ @subscriber.unsubscribe(@close_channel)
54
60
  EventMachine.cancel_timer(@gc)
55
61
  end
56
62
 
@@ -97,6 +103,7 @@ module Faye
97
103
  @redis.zrem(@ns + '/clients', client_id) do
98
104
  @server.debug 'Destroyed client ?', client_id
99
105
  @server.trigger(:disconnect, client_id)
106
+ @redis.publish(@close_channel, client_id)
100
107
  callback.call if callback
101
108
  end
102
109
  end
@@ -138,7 +145,7 @@ module Faye
138
145
  init
139
146
  @server.debug 'Publishing message ?', message
140
147
 
141
- json_message = Yajl::Encoder.encode(message)
148
+ json_message = MultiJson.dump(message)
142
149
  channels = Channel.expand(message['channel'])
143
150
  keys = channels.map { |c| @ns + "/channels#{c}" }
144
151
 
@@ -148,7 +155,7 @@ module Faye
148
155
 
149
156
  @server.debug 'Queueing for client ?: ?', client_id, message
150
157
  @redis.rpush(queue, json_message)
151
- @redis.publish(@ns + '/notifications', client_id)
158
+ @redis.publish(@message_channel, client_id)
152
159
 
153
160
  client_exists(client_id) do |exists|
154
161
  @redis.del(queue) unless exists
@@ -170,7 +177,7 @@ module Faye
170
177
  @redis.del(key)
171
178
  @redis.exec.callback do |json_messages, deleted|
172
179
  next unless json_messages
173
- messages = json_messages.map { |json| Yajl::Parser.parse(json) }
180
+ messages = json_messages.map { |json| MultiJson.load(json) }
174
181
  @server.deliver(client_id, messages)
175
182
  end
176
183
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faye-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-28 00:00:00.000000000 Z
12
+ date: 2013-10-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
@@ -44,7 +44,7 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: 0.2.0
46
46
  - !ruby/object:Gem::Dependency
47
- name: yajl-ruby
47
+ name: multi_json
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
@@ -75,22 +75,40 @@ dependencies:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: websocket-driver
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
78
94
  description:
79
95
  email: jcoglan@gmail.com
80
96
  executables: []
81
97
  extensions: []
82
98
  extra_rdoc_files:
83
- - README.rdoc
99
+ - README.md
84
100
  files:
85
- - README.rdoc
86
- - CHANGELOG.txt
101
+ - CHANGELOG.md
102
+ - README.md
87
103
  - lib/faye/redis.rb
88
104
  homepage: http://github.com/faye/faye-redis-ruby
89
105
  licenses: []
90
106
  post_install_message:
91
107
  rdoc_options:
92
108
  - --main
93
- - README.rdoc
109
+ - README.md
110
+ - --markup
111
+ - markdown
94
112
  require_paths:
95
113
  - lib
96
114
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -112,4 +130,3 @@ signing_key:
112
130
  specification_version: 3
113
131
  summary: Redis backend engine for Faye
114
132
  test_files: []
115
- has_rdoc:
@@ -1,9 +0,0 @@
1
- === 0.1.1 / 2013-04-28
2
-
3
- * Improve garbage collection to avoid leaking Redis memory
4
-
5
-
6
- === 0.1.0 / 2012-02-26
7
-
8
- * Initial release: Redis backend for Faye 0.8
9
-
@@ -1,59 +0,0 @@
1
- = Faye::Redis {<img src="https://secure.travis-ci.org/faye/faye-redis-ruby.png" alt="Build Status" />}[http://travis-ci.org/faye/faye-redis-ruby]
2
-
3
- This plugin provides a Redis-based backend for the {Faye}[http://faye.jcoglan.com]
4
- messaging server. It allows a single Faye service to be distributed across many
5
- front-end web servers by storing state and routing messages through a
6
- {Redis}[http://redis.io] database server.
7
-
8
-
9
- == Usage
10
-
11
- Pass in the engine and any settings you need when setting up your Faye server.
12
-
13
- require 'faye'
14
- require 'faye/redis'
15
-
16
- bayeux = Faye::RackAdapter.new(
17
- :mount => '/',
18
- :timeout => 25,
19
- :engine => {
20
- :type => Faye::Redis,
21
- :host => 'redis.example.com',
22
- # more options
23
- }
24
- )
25
-
26
- The full list of settings is as follows.
27
-
28
- * <b><tt>:uri</tt></b> - redis URL (example: redis://:secretpassword@example.com:9000/4)
29
- * <b><tt>:host</tt></b> - hostname of your Redis instance
30
- * <b><tt>:port</tt></b> - port number, default is +6379+
31
- * <b><tt>:password</tt></b> - password, if +requirepass+ is set
32
- * <b><tt>:database</tt></b> - number of database to use, default is +0+
33
- * <b><tt>:namespace</tt></b> - prefix applied to all keys, default is <tt>''</tt>
34
- * <b><tt>:socket</tt></b> - path to Unix socket if +unixsocket+ is set
35
-
36
-
37
- == License
38
-
39
- (The MIT License)
40
-
41
- Copyright (c) 2011-2012 James Coglan
42
-
43
- Permission is hereby granted, free of charge, to any person obtaining a copy of
44
- this software and associated documentation files (the 'Software'), to deal in
45
- the Software without restriction, including without limitation the rights to use,
46
- copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
47
- Software, and to permit persons to whom the Software is furnished to do so,
48
- subject to the following conditions:
49
-
50
- The above copyright notice and this permission notice shall be included in all
51
- copies or substantial portions of the Software.
52
-
53
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
54
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
55
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
56
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
57
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
58
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
59
-