为何 Connection 设计为 class 内的 module,这样有何作用呢?
class Redis
module Connection
class Memory
include Redis::Connection::CommandHelper
include FakeRedis
include SortMethod
include TransactionCommands
include CommandExecutor
attr_accessor :options
# Tracks all databases for all instances across the current process.
# We have to be able to handle two clients with the same host/port accessing
# different databases at once without overwriting each other. So we store our
# "data" outside the client instances, in this class level instance method.
# Client instances access it with a key made up of their host/port, and then select
# which DB out of the array of them they want. Allows the access we need.
def self.databases
@databases ||= Hash.new {|h,k| h[k] = [] }
end
# Used for resetting everything in specs
def self.reset_all_databases
@databases = nil
end
def self.connect(options = {})
new(options)
end
def initialize(options = {})
self.options = options
end