redisrpc 0.3.4 → 0.3.5
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.
- data/lib/redisrpc.rb +21 -22
 - metadata +15 -4
 
    
        data/lib/redisrpc.rb
    CHANGED
    
    | 
         @@ -13,7 +13,8 @@ 
     | 
|
| 
       13 
13 
     | 
    
         
             
            # You should have received a copy of the GNU General Public License
         
     | 
| 
       14 
14 
     | 
    
         
             
            # along with this program.  If not, see <http://www.gnu.org/licenses/>.
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
            require ' 
     | 
| 
      
 16 
     | 
    
         
            +
            require File.expand_path('../redisrpc/version',__FILE__)
         
     | 
| 
      
 17 
     | 
    
         
            +
            require 'multi_json'
         
     | 
| 
       17 
18 
     | 
    
         | 
| 
       18 
19 
     | 
    
         
             
            require 'redis'
         
     | 
| 
       19 
20 
     | 
    
         | 
| 
         @@ -31,19 +32,12 @@ module RedisRPC 
     | 
|
| 
       31 
32 
     | 
    
         
             
                class FunctionCall
         
     | 
| 
       32 
33 
     | 
    
         | 
| 
       33 
34 
     | 
    
         
             
                    def initialize(args={})
         
     | 
| 
       34 
     | 
    
         
            -
                        @ 
     | 
| 
      
 35 
     | 
    
         
            +
                        @method = args['name'].to_sym
         
     | 
| 
       35 
36 
     | 
    
         
             
                        @args = args['args']
         
     | 
| 
       36 
37 
     | 
    
         
             
                    end
         
     | 
| 
       37 
38 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
                     
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
                        if @args != nil
         
     | 
| 
       41 
     | 
    
         
            -
                            argstring += ' '
         
     | 
| 
       42 
     | 
    
         
            -
                            argstring += @args.join ','
         
     | 
| 
       43 
     | 
    
         
            -
                        end
         
     | 
| 
       44 
     | 
    
         
            -
                        return @name + argstring
         
     | 
| 
       45 
     | 
    
         
            -
                    end
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
      
 39 
     | 
    
         
            +
                    attr_reader :method
         
     | 
| 
      
 40 
     | 
    
         
            +
                    attr_reader :args
         
     | 
| 
       47 
41 
     | 
    
         
             
                end
         
     | 
| 
       48 
42 
     | 
    
         | 
| 
       49 
43 
     | 
    
         | 
| 
         @@ -59,7 +53,7 @@ module RedisRPC 
     | 
|
| 
       59 
53 
     | 
    
         
             
                        function_call = {'name' => sym.to_s, 'args' => args}
         
     | 
| 
       60 
54 
     | 
    
         
             
                        response_queue = @message_queue + ':rpc:' + rand_string
         
     | 
| 
       61 
55 
     | 
    
         
             
                        rpc_request = {'function_call' => function_call, 'response_queue' => response_queue}
         
     | 
| 
       62 
     | 
    
         
            -
                        message =  
     | 
| 
      
 56 
     | 
    
         
            +
                        message = MultiJson.dump rpc_request
         
     | 
| 
       63 
57 
     | 
    
         
             
                        if $DEBUG
         
     | 
| 
       64 
58 
     | 
    
         
             
                            $stderr.puts 'RPC Request: ' + message
         
     | 
| 
       65 
59 
     | 
    
         
             
                        end
         
     | 
| 
         @@ -75,7 +69,7 @@ module RedisRPC 
     | 
|
| 
       75 
69 
     | 
    
         
             
                            end
         
     | 
| 
       76 
70 
     | 
    
         
             
                            $stderr.puts 'RPC Response: ' + message
         
     | 
| 
       77 
71 
     | 
    
         
             
                        end
         
     | 
| 
       78 
     | 
    
         
            -
                        rpc_response =  
     | 
| 
      
 72 
     | 
    
         
            +
                        rpc_response = MultiJson.load message
         
     | 
| 
       79 
73 
     | 
    
         
             
                        exception = rpc_response['exception']
         
     | 
| 
       80 
74 
     | 
    
         
             
                        if exception != nil
         
     | 
| 
       81 
75 
     | 
    
         
             
                            raise RemoteException, exception
         
     | 
| 
         @@ -84,10 +78,10 @@ module RedisRPC 
     | 
|
| 
       84 
78 
     | 
    
         
             
                            raise RemoteException, 'Malformed RPC Response message: ' + rpc_response
         
     | 
| 
       85 
79 
     | 
    
         
             
                        end
         
     | 
| 
       86 
80 
     | 
    
         
             
                        return rpc_response['return_value']
         
     | 
| 
       87 
     | 
    
         
            -
                    end 
     | 
| 
      
 81 
     | 
    
         
            +
                    end
         
     | 
| 
       88 
82 
     | 
    
         | 
| 
       89 
     | 
    
         
            -
                    def rand_string(size=8 
     | 
| 
       90 
     | 
    
         
            -
                        return ( 
     | 
| 
      
 83 
     | 
    
         
            +
                    def rand_string(size=8)
         
     | 
| 
      
 84 
     | 
    
         
            +
                        return rand(36**size).to_s(36).upcase.rjust(size,'0')
         
     | 
| 
       91 
85 
     | 
    
         
             
                    end
         
     | 
| 
       92 
86 
     | 
    
         | 
| 
       93 
87 
     | 
    
         
             
                    def respond_to?(sym)
         
     | 
| 
         @@ -106,25 +100,22 @@ module RedisRPC 
     | 
|
| 
       106 
100 
     | 
    
         
             
                    end
         
     | 
| 
       107 
101 
     | 
    
         | 
| 
       108 
102 
     | 
    
         
             
                    def run
         
     | 
| 
       109 
     | 
    
         
            -
                        # Flush the message queue.
         
     | 
| 
       110 
     | 
    
         
            -
                        @redis_server.del @message_queue
         
     | 
| 
       111 
103 
     | 
    
         
             
                        loop do
         
     | 
| 
       112 
104 
     | 
    
         
             
                            message_queue, message = @redis_server.blpop @message_queue, 0
         
     | 
| 
       113 
105 
     | 
    
         
             
                            if $DEBUG
         
     | 
| 
       114 
106 
     | 
    
         
             
                                fail 'assertion failed' if message_queue != @message_queue
         
     | 
| 
       115 
107 
     | 
    
         
             
                                $stderr.puts 'RPC Request: ' + message
         
     | 
| 
       116 
108 
     | 
    
         
             
                            end
         
     | 
| 
       117 
     | 
    
         
            -
                            rpc_request =  
     | 
| 
      
 109 
     | 
    
         
            +
                            rpc_request = MultiJson.load message
         
     | 
| 
       118 
110 
     | 
    
         
             
                            response_queue = rpc_request['response_queue']
         
     | 
| 
       119 
111 
     | 
    
         
             
                            function_call = FunctionCall.new(rpc_request['function_call'])
         
     | 
| 
       120 
     | 
    
         
            -
                            code = '@local_object.' + function_call.as_ruby_code
         
     | 
| 
       121 
112 
     | 
    
         
             
                            begin
         
     | 
| 
       122 
     | 
    
         
            -
                                return_value =  
     | 
| 
      
 113 
     | 
    
         
            +
                                return_value = @local_object.send( function_call.method, *function_call.args )
         
     | 
| 
       123 
114 
     | 
    
         
             
                                rpc_response = {'return_value' => return_value}
         
     | 
| 
       124 
115 
     | 
    
         
             
                            rescue => err
         
     | 
| 
       125 
116 
     | 
    
         
             
                                rpc_response = {'exception' => err}
         
     | 
| 
       126 
117 
     | 
    
         
             
                            end
         
     | 
| 
       127 
     | 
    
         
            -
                            message =  
     | 
| 
      
 118 
     | 
    
         
            +
                            message = MultiJson.dump rpc_response
         
     | 
| 
       128 
119 
     | 
    
         
             
                            if $DEBUG
         
     | 
| 
       129 
120 
     | 
    
         
             
                                $stderr.puts 'RPC Response: ' + message
         
     | 
| 
       130 
121 
     | 
    
         
             
                            end
         
     | 
| 
         @@ -132,6 +123,14 @@ module RedisRPC 
     | 
|
| 
       132 
123 
     | 
    
         
             
                        end
         
     | 
| 
       133 
124 
     | 
    
         
             
                    end
         
     | 
| 
       134 
125 
     | 
    
         | 
| 
      
 126 
     | 
    
         
            +
                    def run!
         
     | 
| 
      
 127 
     | 
    
         
            +
                        flush_queue!
         
     | 
| 
      
 128 
     | 
    
         
            +
                        run
         
     | 
| 
      
 129 
     | 
    
         
            +
                    end
         
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
      
 131 
     | 
    
         
            +
                    def flush_queue!
         
     | 
| 
      
 132 
     | 
    
         
            +
                        @redis_server.del @message_queue
         
     | 
| 
      
 133 
     | 
    
         
            +
                    end
         
     | 
| 
       135 
134 
     | 
    
         
             
                end
         
     | 
| 
       136 
135 
     | 
    
         | 
| 
       137 
136 
     | 
    
         | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: redisrpc
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.3. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.3.5
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,11 +9,11 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2012-04- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2012-04-20 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: redis
         
     | 
| 
       16 
     | 
    
         
            -
              requirement: & 
     | 
| 
      
 16 
     | 
    
         
            +
              requirement: &2156634200 !ruby/object:Gem::Requirement
         
     | 
| 
       17 
17 
     | 
    
         
             
                none: false
         
     | 
| 
       18 
18 
     | 
    
         
             
                requirements:
         
     | 
| 
       19 
19 
     | 
    
         
             
                - - <
         
     | 
| 
         @@ -21,7 +21,18 @@ dependencies: 
     | 
|
| 
       21 
21 
     | 
    
         
             
                    version: 3.0.0
         
     | 
| 
       22 
22 
     | 
    
         
             
              type: :runtime
         
     | 
| 
       23 
23 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       24 
     | 
    
         
            -
              version_requirements: * 
     | 
| 
      
 24 
     | 
    
         
            +
              version_requirements: *2156634200
         
     | 
| 
      
 25 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 26 
     | 
    
         
            +
              name: multi_json
         
     | 
| 
      
 27 
     | 
    
         
            +
              requirement: &2156633700 !ruby/object:Gem::Requirement
         
     | 
| 
      
 28 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 29 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 30 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 31 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 32 
     | 
    
         
            +
                    version: '1.3'
         
     | 
| 
      
 33 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 34 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 35 
     | 
    
         
            +
              version_requirements: *2156633700
         
     | 
| 
       25 
36 
     | 
    
         
             
            description: ! 'RedisRPC is the easiest to use RPC library in the world. (No small
         
     | 
| 
       26 
37 
     | 
    
         
             
              claim!) It
         
     | 
| 
       27 
38 
     | 
    
         |