rapnd 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +49 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/bin/rapnd +58 -0
- data/lib/rapnd/daemon.rb +54 -0
- data/lib/rapnd/notification.rb +35 -0
- data/lib/rapnd.rb +6 -0
- data/rapnd.gemspec +81 -0
- data/spec/daemon_spec.rb +11 -0
- data/spec/notification_spec.rb +28 -0
- data/spec/redis-test.conf +115 -0
- data/spec/spec_helper.rb +20 -0
- metadata +167 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "hiredis", "~> 0.3.1"
|
4
|
+
gem "redis", "~> 2.2.0", :require => ["redis/connection/hiredis", "redis"]
|
5
|
+
gem 'active_support'
|
6
|
+
gem 'foreverb', :git => 'git://github.com/DAddYE/foreverb.git'
|
7
|
+
|
8
|
+
group :development do
|
9
|
+
gem 'mocha'
|
10
|
+
gem "rspec"
|
11
|
+
gem "bundler"
|
12
|
+
gem "jeweler"
|
13
|
+
gem "rcov"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/DAddYE/foreverb.git
|
3
|
+
revision: 97d921b0512fb9e1e472df7f54f568bbb6d9f704
|
4
|
+
specs:
|
5
|
+
foreverb (0.3.0)
|
6
|
+
thor (~> 0.14.6)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
active_support (3.0.0)
|
12
|
+
activesupport (= 3.0.0)
|
13
|
+
activesupport (3.0.0)
|
14
|
+
diff-lcs (1.1.3)
|
15
|
+
git (1.2.5)
|
16
|
+
hiredis (0.3.2)
|
17
|
+
jeweler (1.6.4)
|
18
|
+
bundler (~> 1.0)
|
19
|
+
git (>= 1.2.5)
|
20
|
+
rake
|
21
|
+
metaclass (0.0.1)
|
22
|
+
mocha (0.10.3)
|
23
|
+
metaclass (~> 0.0.1)
|
24
|
+
rake (0.9.3.beta.1)
|
25
|
+
rcov (0.9.11)
|
26
|
+
redis (2.2.2)
|
27
|
+
rspec (2.8.0)
|
28
|
+
rspec-core (~> 2.8.0)
|
29
|
+
rspec-expectations (~> 2.8.0)
|
30
|
+
rspec-mocks (~> 2.8.0)
|
31
|
+
rspec-core (2.8.0)
|
32
|
+
rspec-expectations (2.8.0)
|
33
|
+
diff-lcs (~> 1.1.2)
|
34
|
+
rspec-mocks (2.8.0)
|
35
|
+
thor (0.14.6)
|
36
|
+
|
37
|
+
PLATFORMS
|
38
|
+
ruby
|
39
|
+
|
40
|
+
DEPENDENCIES
|
41
|
+
active_support
|
42
|
+
bundler
|
43
|
+
foreverb!
|
44
|
+
hiredis (~> 0.3.1)
|
45
|
+
jeweler
|
46
|
+
mocha
|
47
|
+
rcov
|
48
|
+
redis (~> 2.2.0)
|
49
|
+
rspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Josh Symonds
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= rapnd
|
2
|
+
|
3
|
+
An extremely beta daemon that persists a connection to Apple's servers and sends messages to it, using redis for persistence.
|
4
|
+
|
5
|
+
== Contributing to rapnd
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 Josh Symonds. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "rapnd"
|
18
|
+
gem.homepage = "http://github.com/Veraticus/rapnd"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{redis APN daemon}
|
21
|
+
gem.description = %Q{redis APN daemon}
|
22
|
+
gem.email = "veraticus@gmail.com"
|
23
|
+
gem.authors = ["Josh Symonds"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rake/rdoctask'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "rapnd #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/rapnd
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
|
4
|
+
ARGV << '--help' if ARGV.empty?
|
5
|
+
|
6
|
+
require 'optparse'
|
7
|
+
require 'rapnd'
|
8
|
+
require 'rubygems' unless defined?(Gem)
|
9
|
+
require 'forever'
|
10
|
+
|
11
|
+
options = {}
|
12
|
+
OptionParser.new do |opts|
|
13
|
+
opts.banner = "Usage: rapnd [options]"
|
14
|
+
|
15
|
+
opts.on("--cert=MANDATORY", "Location of the cert pem file") do |cert|
|
16
|
+
options[:cert] = cert
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.on("--password=OPTIONAL", "Password for the cert pem file") do |password|
|
20
|
+
options[:password] = password
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.on("--redis_host=OPTIONAL", "Redis hostname") do |host|
|
24
|
+
options[:redis_host] = host
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on("--redis_port=OPTIONAL", "Redis port") do |port|
|
28
|
+
options[:redis_port] = port
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on("--environment=OPTIONAL", "Specify sandbox or production") do |env|
|
32
|
+
options[:env] = env
|
33
|
+
end
|
34
|
+
|
35
|
+
opts.on("--queue=OPTIONAL", "Name of the redis queue") do |queue|
|
36
|
+
options[:queue] = queue
|
37
|
+
end
|
38
|
+
|
39
|
+
opts.on("--foreground", "Run in the foreground") do |fore|
|
40
|
+
options[:foreground] = true
|
41
|
+
end
|
42
|
+
|
43
|
+
opts.on('--help', 'Show help') do |help|
|
44
|
+
puts opts
|
45
|
+
end
|
46
|
+
end.parse!
|
47
|
+
|
48
|
+
unless options[:foreground]
|
49
|
+
Forever.run do
|
50
|
+
log "#{options[:queue]}.log"
|
51
|
+
|
52
|
+
on_ready do
|
53
|
+
Rapnd::Daemon.new(options).run!
|
54
|
+
end
|
55
|
+
end
|
56
|
+
else
|
57
|
+
Rapnd::Daemon.new(options).run!
|
58
|
+
end
|
data/lib/rapnd/daemon.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'redis'
|
2
|
+
require 'openssl'
|
3
|
+
require 'socket'
|
4
|
+
require 'active_support/ordered_hash'
|
5
|
+
require 'active_support/json'
|
6
|
+
require 'base64'
|
7
|
+
|
8
|
+
module Rapnd
|
9
|
+
class Daemon
|
10
|
+
attr_accessor :redis, :host, :apple, :cert, :queue, :connected
|
11
|
+
|
12
|
+
def initialize(options = {})
|
13
|
+
puts 'Initializing daemon...'
|
14
|
+
options[:redis_host] ||= 'localhost'
|
15
|
+
options[:redis_port] ||= '6379'
|
16
|
+
options[:host] ||= 'gateway.sandbox.push.apple.com'
|
17
|
+
options[:queue] ||= 'rapnd_queue'
|
18
|
+
options[:password] ||= ''
|
19
|
+
raise 'No cert provided!' unless options[:cert]
|
20
|
+
|
21
|
+
@redis = Redis.new(:host => options[:redis_host], :port => options[:redis_port])
|
22
|
+
@queue = options[:queue]
|
23
|
+
@cert = options[:cert]
|
24
|
+
@host = options[:host]
|
25
|
+
puts 'Initialized!'
|
26
|
+
end
|
27
|
+
|
28
|
+
def connect!
|
29
|
+
puts 'Connecting...'
|
30
|
+
@context = OpenSSL::SSL::SSLContext.new
|
31
|
+
@context.cert = OpenSSL::X509::Certificate.new(File.read(@cert))
|
32
|
+
@context.key = OpenSSL::PKey::RSA.new(File.read(@cert), @password)
|
33
|
+
|
34
|
+
@sock = TCPSocket.new(@host, 2195)
|
35
|
+
self.apple = OpenSSL::SSL::SSLSocket.new(@sock, @context)
|
36
|
+
self.apple.sync = true
|
37
|
+
self.apple.connect
|
38
|
+
|
39
|
+
self.connected = true
|
40
|
+
puts 'Connected!'
|
41
|
+
|
42
|
+
return @sock, @ssl
|
43
|
+
end
|
44
|
+
|
45
|
+
def run!
|
46
|
+
notification = Rapnd::Notification.new(Marshal.load(@redis.blpop(self.queue, 0).last))
|
47
|
+
puts 'Notification popped.'
|
48
|
+
self.connect! unless self.connected
|
49
|
+
puts "Sending Apple: #{notification.json_payload}"
|
50
|
+
self.apple.write(notification.to_bytes)
|
51
|
+
self.run!
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Rapnd
|
2
|
+
class Notification
|
3
|
+
attr_accessor :badge, :alert, :sound, :custom, :device_token
|
4
|
+
|
5
|
+
def initialize(hash)
|
6
|
+
[:badge, :alert, :sound, :custom, :device_token].each do |k|
|
7
|
+
self.instance_variable_set("@#{k}".to_sym, hash[k]) if hash[k]
|
8
|
+
end
|
9
|
+
raise 'Must provide device token' if self.device_token.nil?
|
10
|
+
self.device_token = self.device_token.delete(' ')
|
11
|
+
end
|
12
|
+
|
13
|
+
def payload
|
14
|
+
p = Hash.new
|
15
|
+
[:badge, :alert, :sound, :custom].each do |k|
|
16
|
+
p[k] = send(k) if send(k)
|
17
|
+
end
|
18
|
+
custom = p.delete(:custom)
|
19
|
+
aps = {:aps => p}
|
20
|
+
aps.merge!(:custom => custom) if custom
|
21
|
+
aps
|
22
|
+
end
|
23
|
+
|
24
|
+
def json_payload
|
25
|
+
j = ActiveSupport::JSON.encode(payload)
|
26
|
+
raise PayloadInvalid.new("The payload is larger than allowed: #{j.length}") if j.size > 256
|
27
|
+
j
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_bytes
|
31
|
+
j = json_payload
|
32
|
+
[0, 0, 32, self.device_token, 0, j.bytesize, j].pack("cccH*cca*").force_encoding('ASCII-8BIT')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/rapnd.rb
ADDED
data/rapnd.gemspec
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "rapnd"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Josh Symonds"]
|
12
|
+
s.date = "2012-02-15"
|
13
|
+
s.description = "redis APN daemon"
|
14
|
+
s.email = "veraticus@gmail.com"
|
15
|
+
s.executables = ["rapnd"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".rspec",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"bin/rapnd",
|
30
|
+
"lib/rapnd.rb",
|
31
|
+
"lib/rapnd/daemon.rb",
|
32
|
+
"lib/rapnd/notification.rb",
|
33
|
+
"rapnd.gemspec",
|
34
|
+
"spec/daemon_spec.rb",
|
35
|
+
"spec/notification_spec.rb",
|
36
|
+
"spec/redis-test.conf",
|
37
|
+
"spec/spec_helper.rb"
|
38
|
+
]
|
39
|
+
s.homepage = "http://github.com/Veraticus/rapnd"
|
40
|
+
s.licenses = ["MIT"]
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = "1.8.10"
|
43
|
+
s.summary = "redis APN daemon"
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_runtime_dependency(%q<hiredis>, ["~> 0.3.1"])
|
50
|
+
s.add_runtime_dependency(%q<redis>, ["~> 2.2.0"])
|
51
|
+
s.add_runtime_dependency(%q<active_support>, [">= 0"])
|
52
|
+
s.add_runtime_dependency(%q<foreverb>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
54
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
55
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
57
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<hiredis>, ["~> 0.3.1"])
|
60
|
+
s.add_dependency(%q<redis>, ["~> 2.2.0"])
|
61
|
+
s.add_dependency(%q<active_support>, [">= 0"])
|
62
|
+
s.add_dependency(%q<foreverb>, [">= 0"])
|
63
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
64
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
65
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
66
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
67
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
68
|
+
end
|
69
|
+
else
|
70
|
+
s.add_dependency(%q<hiredis>, ["~> 0.3.1"])
|
71
|
+
s.add_dependency(%q<redis>, ["~> 2.2.0"])
|
72
|
+
s.add_dependency(%q<active_support>, [">= 0"])
|
73
|
+
s.add_dependency(%q<foreverb>, [">= 0"])
|
74
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
75
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
76
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
77
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
78
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
data/spec/daemon_spec.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Rapnd::Daemon" do
|
4
|
+
before do
|
5
|
+
@daemon = Rapnd::Daemon.new(:redis_port => 9876, :apn_cert => '')
|
6
|
+
end
|
7
|
+
|
8
|
+
it "initializes a redis connection" do
|
9
|
+
@daemon.redis.ping.should == "PONG"
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Rapnd::Notification" do
|
4
|
+
before do
|
5
|
+
@notification = Rapnd::Notification.new(:badge => 99, :alert => 'Big test time', :custom => 'This is a test!', :device_token => '1234 5')
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'removes whitespace from the device token' do
|
9
|
+
@notification.device_token.should == '12345'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "automatically assigns hash variables to instance variables" do
|
13
|
+
@notification.badge.should == 99
|
14
|
+
@notification.custom.should == 'This is a test!'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'creates a hash payload' do
|
18
|
+
@notification.payload.should == {:aps=>{:badge=>99, :alert=>"Big test time"}, :custom=>"This is a test!"}
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'jsonifies the hash payload' do
|
22
|
+
ActiveSupport::JSON.decode(@notification.json_payload).should == {"aps"=>{"badge"=>99, "alert"=>"Big test time"}, "custom"=>"This is a test!"}
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'turns into bytes sensibly' do
|
26
|
+
@notification.to_bytes.should == "\x00\x00 \x124P\x00G{\"aps\":{\"badge\":99,\"alert\":\"Big test time\"},\"custom\":\"This is a test!\"}"
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# Redis configuration file example
|
2
|
+
|
3
|
+
# By default Redis does not run as a daemon. Use 'yes' if you need it.
|
4
|
+
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
|
5
|
+
daemonize yes
|
6
|
+
|
7
|
+
# When run as a daemon, Redis write a pid file in /var/run/redis.pid by default.
|
8
|
+
# You can specify a custom pid file location here.
|
9
|
+
pidfile ./redis-test.pid
|
10
|
+
|
11
|
+
# Accept connections on the specified port, default is 6379
|
12
|
+
port 9876
|
13
|
+
|
14
|
+
# If you want you can bind a single interface, if the bind option is not
|
15
|
+
# specified all the interfaces will listen for connections.
|
16
|
+
#
|
17
|
+
# bind 127.0.0.1
|
18
|
+
|
19
|
+
# Close the connection after a client is idle for N seconds (0 to disable)
|
20
|
+
timeout 300
|
21
|
+
|
22
|
+
# Save the DB on disk:
|
23
|
+
#
|
24
|
+
# save <seconds> <changes>
|
25
|
+
#
|
26
|
+
# Will save the DB if both the given number of seconds and the given
|
27
|
+
# number of write operations against the DB occurred.
|
28
|
+
#
|
29
|
+
# In the example below the behaviour will be to save:
|
30
|
+
# after 900 sec (15 min) if at least 1 key changed
|
31
|
+
# after 300 sec (5 min) if at least 10 keys changed
|
32
|
+
# after 60 sec if at least 10000 keys changed
|
33
|
+
save 900 1
|
34
|
+
save 300 10
|
35
|
+
save 60 10000
|
36
|
+
|
37
|
+
# The filename where to dump the DB
|
38
|
+
dbfilename dump.rdb
|
39
|
+
|
40
|
+
# For default save/load DB in/from the working directory
|
41
|
+
# Note that you must specify a directory not a file name.
|
42
|
+
dir .
|
43
|
+
|
44
|
+
# Set server verbosity to 'debug'
|
45
|
+
# it can be one of:
|
46
|
+
# debug (a lot of information, useful for development/testing)
|
47
|
+
# notice (moderately verbose, what you want in production probably)
|
48
|
+
# warning (only very important / critical messages are logged)
|
49
|
+
loglevel debug
|
50
|
+
|
51
|
+
# Specify the log file name. Also 'stdout' can be used to force
|
52
|
+
# the demon to log on the standard output. Note that if you use standard
|
53
|
+
# output for logging but daemonize, logs will be sent to /dev/null
|
54
|
+
logfile stdout
|
55
|
+
|
56
|
+
# Set the number of databases. The default database is DB 0, you can select
|
57
|
+
# a different one on a per-connection basis using SELECT <dbid> where
|
58
|
+
# dbid is a number between 0 and 'databases'-1
|
59
|
+
databases 16
|
60
|
+
|
61
|
+
################################# REPLICATION #################################
|
62
|
+
|
63
|
+
# Master-Slave replication. Use slaveof to make a Redis instance a copy of
|
64
|
+
# another Redis server. Note that the configuration is local to the slave
|
65
|
+
# so for example it is possible to configure the slave to save the DB with a
|
66
|
+
# different interval, or to listen to another port, and so on.
|
67
|
+
|
68
|
+
# slaveof <masterip> <masterport>
|
69
|
+
|
70
|
+
################################## SECURITY ###################################
|
71
|
+
|
72
|
+
# Require clients to issue AUTH <PASSWORD> before processing any other
|
73
|
+
# commands. This might be useful in environments in which you do not trust
|
74
|
+
# others with access to the host running redis-server.
|
75
|
+
#
|
76
|
+
# This should stay commented out for backward compatibility and because most
|
77
|
+
# people do not need auth (e.g. they run their own servers).
|
78
|
+
|
79
|
+
# requirepass foobared
|
80
|
+
|
81
|
+
################################### LIMITS ####################################
|
82
|
+
|
83
|
+
# Set the max number of connected clients at the same time. By default there
|
84
|
+
# is no limit, and it's up to the number of file descriptors the Redis process
|
85
|
+
# is able to open. The special value '0' means no limts.
|
86
|
+
# Once the limit is reached Redis will close all the new connections sending
|
87
|
+
# an error 'max number of clients reached'.
|
88
|
+
|
89
|
+
# maxclients 128
|
90
|
+
|
91
|
+
# Don't use more memory than the specified amount of bytes.
|
92
|
+
# When the memory limit is reached Redis will try to remove keys with an
|
93
|
+
# EXPIRE set. It will try to start freeing keys that are going to expire
|
94
|
+
# in little time and preserve keys with a longer time to live.
|
95
|
+
# Redis will also try to remove objects from free lists if possible.
|
96
|
+
#
|
97
|
+
# If all this fails, Redis will start to reply with errors to commands
|
98
|
+
# that will use more memory, like SET, LPUSH, and so on, and will continue
|
99
|
+
# to reply to most read-only commands like GET.
|
100
|
+
#
|
101
|
+
# WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
|
102
|
+
# 'state' server or cache, not as a real DB. When Redis is used as a real
|
103
|
+
# database the memory usage will grow over the weeks, it will be obvious if
|
104
|
+
# it is going to use too much memory in the long run, and you'll have the time
|
105
|
+
# to upgrade. With maxmemory after the limit is reached you'll start to get
|
106
|
+
# errors for write operations, and this may even lead to DB inconsistency.
|
107
|
+
|
108
|
+
# maxmemory <bytes>
|
109
|
+
|
110
|
+
############################### ADVANCED CONFIG ###############################
|
111
|
+
|
112
|
+
# Glue small output buffers together in order to send small replies in a
|
113
|
+
# single TCP packet. Uses a bit more CPU but most of the times it is a win
|
114
|
+
# in terms of number of queries per second. Use 'yes' if unsure.
|
115
|
+
glueoutputbuf yes
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'rapnd'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.mock_with(:mocha)
|
12
|
+
config.before(:suite) do
|
13
|
+
`redis-server #{File.dirname(__FILE__)}/redis-test.conf`
|
14
|
+
end
|
15
|
+
config.after(:suite) do
|
16
|
+
processes = `ps -A -o pid,command | grep [r]edis-test`.split("\n")
|
17
|
+
pids = processes.map { |process| process.split(" ")[0] }
|
18
|
+
pids.each { |pid| Process.kill("KILL", pid.to_i) }
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rapnd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Josh Symonds
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: hiredis
|
16
|
+
requirement: &70240252371980 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.3.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70240252371980
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: redis
|
27
|
+
requirement: &70240251988520 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.2.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70240251988520
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: active_support
|
38
|
+
requirement: &70240251984900 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70240251984900
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: foreverb
|
49
|
+
requirement: &70240251983100 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70240251983100
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: mocha
|
60
|
+
requirement: &70240251996640 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70240251996640
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: &70240251992480 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70240251992480
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: bundler
|
82
|
+
requirement: &70240251990700 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70240251990700
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: jeweler
|
93
|
+
requirement: &70240251989760 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *70240251989760
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: rcov
|
104
|
+
requirement: &70240251951020 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: *70240251951020
|
113
|
+
description: redis APN daemon
|
114
|
+
email: veraticus@gmail.com
|
115
|
+
executables:
|
116
|
+
- rapnd
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files:
|
119
|
+
- LICENSE.txt
|
120
|
+
- README.rdoc
|
121
|
+
files:
|
122
|
+
- .document
|
123
|
+
- .rspec
|
124
|
+
- Gemfile
|
125
|
+
- Gemfile.lock
|
126
|
+
- LICENSE.txt
|
127
|
+
- README.rdoc
|
128
|
+
- Rakefile
|
129
|
+
- VERSION
|
130
|
+
- bin/rapnd
|
131
|
+
- lib/rapnd.rb
|
132
|
+
- lib/rapnd/daemon.rb
|
133
|
+
- lib/rapnd/notification.rb
|
134
|
+
- rapnd.gemspec
|
135
|
+
- spec/daemon_spec.rb
|
136
|
+
- spec/notification_spec.rb
|
137
|
+
- spec/redis-test.conf
|
138
|
+
- spec/spec_helper.rb
|
139
|
+
homepage: http://github.com/Veraticus/rapnd
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
post_install_message:
|
143
|
+
rdoc_options: []
|
144
|
+
require_paths:
|
145
|
+
- lib
|
146
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
148
|
+
requirements:
|
149
|
+
- - ! '>='
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
segments:
|
153
|
+
- 0
|
154
|
+
hash: -2604819759982542516
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
none: false
|
157
|
+
requirements:
|
158
|
+
- - ! '>='
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
requirements: []
|
162
|
+
rubyforge_project:
|
163
|
+
rubygems_version: 1.8.10
|
164
|
+
signing_key:
|
165
|
+
specification_version: 3
|
166
|
+
summary: redis APN daemon
|
167
|
+
test_files: []
|