redis-rpc 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ module RedisRpc
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,45 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/redis-rpc/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'redis-rpc'
6
+ s.version = RedisRpc::VERSION
7
+ s.license = 'GPLv3'
8
+ s.authors = ['Phuong Nguyen', 'Nathan Farrington']
9
+ s.email = ['nathan@nathanfarrington.com']
10
+
11
+ s.homepage = 'http://github.com/phuongnd08/redis-rpc-ruby'
12
+ s.summary = 'Lightweight RPC for Redis'
13
+ s.description = <<-DESCRIPTION
14
+ RedisRpc is the easiest to use RPC library in the world. (No small claim!) It
15
+ has implementations in Ruby, PHP, and Python.
16
+
17
+ Redis is a powerful in-memory data structure server that is useful for building
18
+ fast distributed systems. Redis implements message queue functionality with its
19
+ use of list data structures and the `LPOP`, `BLPOP`, and `RPUSH` commands.
20
+ RedisRpc implements a lightweight RPC mechanism using Redis message queues to
21
+ temporarily hold RPC request and response messages. These messages are encoded
22
+ as JSON strings for portability.
23
+
24
+ Many other RPC mechanisms are either programming language specific (e.g.
25
+ Java RMI) or require boiler-plate code for explicit typing (e.g. Thrift).
26
+ RedisRpc was designed to be extremely easy to use by eliminating boiler-plate
27
+ code while also being programming language neutral. High performance was not
28
+ an initial goal of RedisRpc and other RPC libraries are likely to have better
29
+ performance. Instead, RedisRpc has better programmer performance; it lets you
30
+ get something working immediately.
31
+ DESCRIPTION
32
+ s.has_rdoc = false
33
+
34
+ s.files = `git ls-files`.split("\n")
35
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
36
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
37
+ s.require_paths = ["lib"]
38
+
39
+ s.add_runtime_dependency 'redis'
40
+ s.add_runtime_dependency 'multi_json', '~>1.3'
41
+
42
+ s.add_development_dependency 'bundler'
43
+ s.add_development_dependency 'rake'
44
+ s.add_development_dependency 'rspec'
45
+ end
@@ -0,0 +1,41 @@
1
+ require File.expand_path( '../spec_helper.rb', __FILE__ )
2
+ require File.expand_path( '../../examples/calc.rb', __FILE__ )
3
+
4
+ describe Calculator do
5
+ [true,false].each do |over_redisrpc|
6
+ context "when run #{( over_redisrpc ? 'over redisrpc' : 'locally')}" do
7
+
8
+ if( over_redisrpc )
9
+ let(:rpc_server_builder){ lambda{ RedisRpc::Server.new( Redis.new($REDIS_CONFIG), 'calc', Calculator.new ) } }
10
+ before(:each) do
11
+ @server_pid = fork{ rpc_server_builder.call.run }
12
+ end
13
+ after(:each){ Process.kill(9, @server_pid); rpc_server_builder.call.flush_queue! }
14
+ let(:calculator){ RedisRpc::Client.new( $REDIS,'calc', 1) }
15
+ else
16
+ let(:calculator){ Calculator.new }
17
+ end
18
+
19
+ it 'should calculate' do
20
+ calculator.val.should == 0.0
21
+ calculator.add(3).should == 3.0
22
+ calculator.sub(2).should == 1.0
23
+ calculator.mul(14).should == 14.0
24
+ calculator.div(7).should == 2.0
25
+ calculator.val.should == 2.0
26
+ calculator.clr.should == 0.0
27
+ calculator.val.should == 0.0
28
+ end
29
+
30
+ it 'should raise when missing method is called' do
31
+ expect{ calculator.a_missing_method }.to raise_error(
32
+ over_redisrpc ? RedisRpc::RemoteException : NoMethodError
33
+ )
34
+ end
35
+
36
+ it 'should raise timeout when execution expires' do
37
+ expect{ calculator.send(:sleep,2) }.to raise_error RedisRpc::TimeoutException
38
+ end if over_redisrpc
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ port 9736
2
+ daemonize yes
3
+ pidfile redis-test.pid
@@ -0,0 +1,56 @@
1
+ require 'bundler'
2
+ begin
3
+ Bundler.require(:default,:development)
4
+ rescue Bundler::BundlerError => e
5
+ $stderr.puts e.message
6
+ $stderr.puts "Run `bundle install` to install missing gems"
7
+ exit e.status_code
8
+ end
9
+
10
+ def MultiJson.default_adapter
11
+ :ok_json
12
+ end
13
+
14
+
15
+ RSpec.configure do |config|
16
+ config.before :suite do
17
+ raise 'redis-server must be on your path to run this test' if `which redis-server`.empty?
18
+ $REDIS_CONF_PATH = File.expand_path('../redis-test.conf',__FILE__)
19
+
20
+ redis_conf_contents = File.read($REDIS_CONF_PATH)
21
+ raise "pidfile must be specified in #{$REDIS_CONF_PATH}" unless redis_conf_contents['pidfile']
22
+
23
+ $REDIS_CONFIG = {
24
+ :host => 'localhost',
25
+ :port => (redis_conf_contents.match(/port ([0-9]+)/)[1].to_i rescue 6379),
26
+ :db => 15 # we'll be flushing regularly; db 15 is traditionally reserved for test
27
+ }
28
+
29
+ $stdout.write "Starting Redis on port #{$REDIS_CONFIG[:port]}... "; $stdout.flush
30
+ `redis-server #{$REDIS_CONF_PATH}`
31
+ puts 'Done.'
32
+
33
+ $REDIS = Redis.new($REDIS_CONFIG)
34
+ begin
35
+ $REDIS.ping
36
+ rescue Timeout::Error, Errno::ECONNREFUSED
37
+ retries ||= 3
38
+ sleep 1 and retry unless (retries-=1).zero?
39
+ $stderr.puts 'Could not connect to Redis after 3 tries.'
40
+ exit
41
+ end
42
+ end
43
+
44
+ config.around :each do |example|
45
+ $REDIS.flushdb
46
+ example.call
47
+ end
48
+
49
+ config.after :suite do
50
+ pidfile = (File.read($REDIS_CONF_PATH).match(/pidfile (.+)$/)[1].chomp rescue nil)
51
+ $stdout.write "\nKilling test redis server... "; $stdout.flush
52
+ Process.kill("KILL", File.read(pidfile).chomp.to_i )
53
+ File.unlink(pidfile)
54
+ puts 'Done.'
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redis-rpc
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Phuong Nguyen
8
+ - Nathan Farrington
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2018-09-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: redis
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: multi_json
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.3'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.3'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ description: |2
85
+ RedisRpc is the easiest to use RPC library in the world. (No small claim!) It
86
+ has implementations in Ruby, PHP, and Python.
87
+
88
+ Redis is a powerful in-memory data structure server that is useful for building
89
+ fast distributed systems. Redis implements message queue functionality with its
90
+ use of list data structures and the `LPOP`, `BLPOP`, and `RPUSH` commands.
91
+ RedisRpc implements a lightweight RPC mechanism using Redis message queues to
92
+ temporarily hold RPC request and response messages. These messages are encoded
93
+ as JSON strings for portability.
94
+
95
+ Many other RPC mechanisms are either programming language specific (e.g.
96
+ Java RMI) or require boiler-plate code for explicit typing (e.g. Thrift).
97
+ RedisRpc was designed to be extremely easy to use by eliminating boiler-plate
98
+ code while also being programming language neutral. High performance was not
99
+ an initial goal of RedisRpc and other RPC libraries are likely to have better
100
+ performance. Instead, RedisRpc has better programmer performance; it lets you
101
+ get something working immediately.
102
+ email:
103
+ - nathan@nathanfarrington.com
104
+ executables: []
105
+ extensions: []
106
+ extra_rdoc_files: []
107
+ files:
108
+ - ".gitignore"
109
+ - CHANGELOG.markdown
110
+ - Gemfile
111
+ - Gemfile.lock
112
+ - LICENSE
113
+ - README.markdown
114
+ - Rakefile
115
+ - VERSION
116
+ - docs/github-flavored-markdown.rb
117
+ - docs/redisrpc_example.ai
118
+ - docs/redisrpc_example.png
119
+ - docs/redisrpc_example.svg
120
+ - examples/calc.rb
121
+ - examples/client.rb
122
+ - examples/server.rb
123
+ - lib/redis-rpc.rb
124
+ - lib/redis-rpc/version.rb
125
+ - redis-rpc.gemspec
126
+ - spec/calculator_spec.rb
127
+ - spec/redis-test.conf
128
+ - spec/spec_helper.rb
129
+ homepage: http://github.com/phuongnd08/redis-rpc-ruby
130
+ licenses:
131
+ - GPLv3
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.4.5.2
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: Lightweight RPC for Redis
153
+ test_files:
154
+ - spec/calculator_spec.rb
155
+ - spec/redis-test.conf
156
+ - spec/spec_helper.rb