defunkt-redis 0.2 → 0.2.1
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/README.markdown +2 -0
- data/lib/redis.rb +27 -12
- data/spec/redis_spec.rb +14 -3
- metadata +2 -2
    
        data/README.markdown
    CHANGED
    
    | @@ -10,6 +10,8 @@ Redis is a key value store with some interesting features: | |
| 10 10 |  | 
| 11 11 | 
             
            See [redis on code.google.com](http://code.google.com/p/redis/wiki/README) for more information.
         | 
| 12 12 |  | 
| 13 | 
            +
            See the build on [RunCodeRun](http://runcoderun.com/rsanheim/redis-rb)
         | 
| 14 | 
            +
             | 
| 13 15 | 
             
            ## Dependencies
         | 
| 14 16 |  | 
| 15 17 | 
             
            1. rspec - 
         | 
    
        data/lib/redis.rb
    CHANGED
    
    | @@ -101,13 +101,14 @@ class Redis | |
| 101 101 | 
             
              }
         | 
| 102 102 |  | 
| 103 103 | 
             
              def initialize(options = {})
         | 
| 104 | 
            -
                @host | 
| 105 | 
            -
                @port | 
| 106 | 
            -
                @db | 
| 107 | 
            -
                @timeout | 
| 108 | 
            -
                @password | 
| 109 | 
            -
                @logger | 
| 110 | 
            -
                @namespace | 
| 104 | 
            +
                @host        = options[:host]     || '127.0.0.1'
         | 
| 105 | 
            +
                @port        = (options[:port]    || 6379).to_i
         | 
| 106 | 
            +
                @db          = (options[:db]      || 0).to_i
         | 
| 107 | 
            +
                @timeout     = (options[:timeout] || 5).to_i
         | 
| 108 | 
            +
                @password    = options[:password]
         | 
| 109 | 
            +
                @logger      = options[:logger]
         | 
| 110 | 
            +
                @namespace   = options[:namespace]
         | 
| 111 | 
            +
                @thread_safe = options[:thread_safe]
         | 
| 111 112 |  | 
| 112 113 | 
             
                @logger.info { self.to_s } if @logger
         | 
| 113 114 | 
             
              end
         | 
| @@ -206,14 +207,26 @@ class Redis | |
| 206 207 | 
             
                  command << "#{bulk}\r\n" if bulk
         | 
| 207 208 | 
             
                end
         | 
| 208 209 |  | 
| 209 | 
            -
                @ | 
| 210 | 
            +
                results = if @thread_safe
         | 
| 211 | 
            +
                  with_mutex { process_command(command, argvv) }
         | 
| 212 | 
            +
                else
         | 
| 213 | 
            +
                  process_command(command, argvv)
         | 
| 214 | 
            +
                end
         | 
| 210 215 |  | 
| 211 | 
            -
                 | 
| 216 | 
            +
                return pipeline ? results : results[0]
         | 
| 217 | 
            +
              end
         | 
| 218 | 
            +
             | 
| 219 | 
            +
              def process_command(command, argvv)
         | 
| 220 | 
            +
                @sock.write(command)
         | 
| 221 | 
            +
                argvv.map do |argv|
         | 
| 212 222 | 
             
                  processor = REPLY_PROCESSOR[argv[0]]
         | 
| 213 223 | 
             
                  processor ? processor.call(read_reply) : read_reply
         | 
| 214 224 | 
             
                end
         | 
| 225 | 
            +
              end
         | 
| 215 226 |  | 
| 216 | 
            -
             | 
| 227 | 
            +
              def with_mutex(&block)
         | 
| 228 | 
            +
                @mutex ||= Mutex.new
         | 
| 229 | 
            +
                @mutex.synchronize &block
         | 
| 217 230 | 
             
              end
         | 
| 218 231 |  | 
| 219 232 | 
             
              def select(*args)
         | 
| @@ -255,10 +268,12 @@ class Redis | |
| 255 268 | 
             
              # Similar to memcache.rb's #get_multi, returns a hash mapping
         | 
| 256 269 | 
             
              # keys to values.
         | 
| 257 270 | 
             
              def mapped_mget(*keys)
         | 
| 258 | 
            -
                 | 
| 271 | 
            +
                result = {}
         | 
| 272 | 
            +
                mget(*keys).each do |value|
         | 
| 259 273 | 
             
                  key = keys.shift
         | 
| 260 | 
            -
                   | 
| 274 | 
            +
                  result.merge!(key => value) unless value.nil?
         | 
| 261 275 | 
             
                end
         | 
| 276 | 
            +
                result
         | 
| 262 277 | 
             
              end
         | 
| 263 278 |  | 
| 264 279 | 
             
              def mget(*keys)
         | 
    
        data/spec/redis_spec.rb
    CHANGED
    
    | @@ -1,4 +1,5 @@ | |
| 1 1 | 
             
            require File.dirname(__FILE__) + '/spec_helper'
         | 
| 2 | 
            +
            require 'redis/raketasks'
         | 
| 2 3 | 
             
            require 'logger'
         | 
| 3 4 |  | 
| 4 5 | 
             
            class Foo
         | 
| @@ -14,10 +15,16 @@ end | |
| 14 15 |  | 
| 15 16 | 
             
            describe "redis" do
         | 
| 16 17 | 
             
              before(:all) do
         | 
| 18 | 
            +
                result = RedisRunner.start_detached
         | 
| 19 | 
            +
                raise("Could not start redis-server, aborting") unless result
         | 
| 20 | 
            +
                
         | 
| 21 | 
            +
                # yea, this sucks, but it seems like sometimes we try to connect too quickly w/o it
         | 
| 22 | 
            +
                sleep 1 
         | 
| 23 | 
            +
                
         | 
| 17 24 | 
             
                # use database 15 for testing so we dont accidentally step on you real data
         | 
| 18 | 
            -
                @r = Redis.new :db => 15
         | 
| 25 | 
            +
                @r = Redis.new :db => 15 
         | 
| 19 26 | 
             
              end
         | 
| 20 | 
            -
             | 
| 27 | 
            +
              
         | 
| 21 28 | 
             
              before(:each) do
         | 
| 22 29 | 
             
                @r['foo'] = 'bar'
         | 
| 23 30 | 
             
              end
         | 
| @@ -27,7 +34,11 @@ describe "redis" do | |
| 27 34 | 
             
              end
         | 
| 28 35 |  | 
| 29 36 | 
             
              after(:all) do
         | 
| 30 | 
            -
                 | 
| 37 | 
            +
                begin
         | 
| 38 | 
            +
                  @r.quit
         | 
| 39 | 
            +
                ensure
         | 
| 40 | 
            +
                  RedisRunner.stop
         | 
| 41 | 
            +
                end
         | 
| 31 42 | 
             
              end
         | 
| 32 43 |  | 
| 33 44 | 
             
              it "should be able connect without a timeout" do
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: defunkt-redis
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              version:  | 
| 4 | 
            +
              version: 0.2.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors: 
         | 
| 7 7 | 
             
            - Ezra Zygmuntowicz
         | 
| @@ -14,7 +14,7 @@ autorequire: | |
| 14 14 | 
             
            bindir: bin
         | 
| 15 15 | 
             
            cert_chain: []
         | 
| 16 16 |  | 
| 17 | 
            -
            date: 2009- | 
| 17 | 
            +
            date: 2009-09-21 00:00:00 -07:00
         | 
| 18 18 | 
             
            default_executable: 
         | 
| 19 19 | 
             
            dependencies: []
         | 
| 20 20 |  |