class URI::Redis

Constants

DEFAULT_DB
DEFAULT_PORT
VERSION

Public Class Methods

build(args) click to toggle source
Calls superclass method
# File lib/uri/redis.rb, line 10
def self.build(args)
  tmp = Util::make_components_hash(self, args)
  return super(tmp)
end
new(*arg) click to toggle source
Calls superclass method
# File lib/uri/redis.rb, line 15
def initialize(*arg)
  super(*arg)
end

Public Instance Methods

conf() click to toggle source

Returns a hash suitable for sending to ::new. The hash is generated from the host, port, db and password from the URI as well as any query vars.

e.g.

uri = URI.parse "redis://127.0.0.1/6/?timeout=5"
uri.conf
  # => {:db=>6, :timeout=>"5", :host=>"127.0.0.1", :port=>6379}
# File lib/uri/redis.rb, line 55
def conf
  hsh = {
    :host => host,
    :port => port,
    :db   => db
  }.merge parse_query(query)
  hsh[:password] = password if password
  hsh
end
db() click to toggle source
# File lib/uri/redis.rb, line 33
def db
  self.path ||= "/#{DEFAULT_DB}"
  (self.path.split('/')[1] || DEFAULT_DB).to_i
end
db=(val) click to toggle source
# File lib/uri/redis.rb, line 38
def db=(val)
  current_key = key
  self.path = "/#{val}"
  self.path << "/#{current_key}"
  self.path
end
key() click to toggle source
# File lib/uri/redis.rb, line 23
def key
  return if self.path.nil?
  self.path ||= "/#{DEFAULT_DB}"
  (self.path.split('/')[2..-1] || []).join('/')
end
key=(val) click to toggle source
# File lib/uri/redis.rb, line 29
def key=(val)
  self.path = '/' << [db, val].join('/')
end
request_uri() click to toggle source
# File lib/uri/redis.rb, line 19
def request_uri
  r = path_query
end
serverid() click to toggle source
# File lib/uri/redis.rb, line 65
def serverid
  'redis://%s:%s/%s' % [host, port, db]
end

Private Instance Methods

parse_query(qs, d = '&;') click to toggle source

Based on / stolen from: github.com/chneukirchen/rack/blob/master/lib/rack/utils.rb which was based on / stolen from Mongrel

# File lib/uri/redis.rb, line 73
def parse_query(qs, d = '&;')
  params = {}
  (qs || '').split(/[#{d}] */n).each do |p|
    k, v = p.split('=', 2).map { |str| str } # NOTE: uri_unescape
    k = k.to_sym
    if cur = params[k]
      if cur.class == Array
        params[k] << v
      else
        params[k] = [cur, v]
      end
    else
      params[k] = v
    end
  end
  params
end