Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 3af20658ec
Fetching contributors…

Cannot retrieve contributors at this time

file 50 lines (40 sloc) 1.281 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
# Copyright (C) 2011 by LivingSocial, Inc.
require 'redi/pool'

class Redi

  ### these commands are complicated to distribute across a pool and so
  ### for now are unimplemented. Translation: we are lazy.
  UNIMPLEMENTED_COMMANDS = %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
]

  ### raise exceptions on unimplemented/unknown commands, delegate
  ### everything else down to the actual Redis connections
  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

  def self.flushdb
    pool.flushdb
  end

  def self.flushall
    pool.flushall
  end

  def self.pool
    @pool ||= Pool.new(self.config)
  end

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

  def self.config
    @config
  end

end
Something went wrong with that request. Please try again.