Class: Redi

Inherits:
Object
  • Object
show all
Defined in:
lib/redi/mock.rb,
lib/redi.rb,
lib/redi/pool.rb,
lib/redi/version.rb

Overview

provide a key to name to host:port mapping

should have a larger keyspace than servers, this allows scaling up the servers without changing the keyspace mapping

sample configuration:

  • :host: :port: :db: :buckets: 0 - 64

  • :host: :port: :db: :buckets: 65 - 127

Defined Under Namespace

Classes: Mock, Pool

Constant Summary collapse

UNIMPLEMENTED_COMMANDS =

these commands are complicated to distribute across a pool and so for now are unimplemented. Translation: we are lazy.

%w[
  keys move object randomkey rename renamenx eval
  mget mset msetnx
  brpoplpush rpoplpush
  sdiff sdiffstore sinter sinterstore smove sunion sunionstore
  zinterstore zunionstore
  psubscribe publish punsubscribe subscribe unsubscribe
  discard exec multi unwatch watch
  auth echo ping quit select
  bgrewriteaof bgsave config dbsize debug info lastsave monitor save shutdown slaveof slowlog sync
]
VERSION =
"0.0.8"

Class Method Summary collapse

Class Method Details

.configObject



46
47
48
# File 'lib/redi.rb', line 46

def self.config
  @config
end

.config=(config) ⇒ Object



42
43
44
# File 'lib/redi.rb', line 42

def self.config=(config)
  @config = config
end

.flushallObject



33
34
35
# File 'lib/redi.rb', line 33

def self.flushall
  pool.flushall
end

.flushdbObject



29
30
31
# File 'lib/redi.rb', line 29

def self.flushdb
  pool.flushdb
end

.method_missing(cmd, *args) ⇒ Object

raise exceptions on unimplemented/unknown commands, delegate everything else down to the actual Redis connections



21
22
23
24
25
26
27
# File 'lib/redi.rb', line 21

def self.method_missing( cmd, *args )
  if UNIMPLEMENTED_COMMANDS.include?( cmd.to_s )
    raise NotImplementedError, "#{cmd} has not yet been implemented. Patches welcome!"
  end

  pool.redis_by_key( args.first ).send( cmd, *args )
end

.mock!Object



7
8
9
# File 'lib/redi/mock.rb', line 7

def self.mock!
  pool(true).mock!
end

.pool(mock = false) ⇒ Object



37
38
39
40
# File 'lib/redi.rb', line 37

def self.pool(mock=false)
  require 'redi/mock' if mock
  @pool ||= Pool.new(self.config,mock)
end