class Keymap::ConnectionAdapters::RedisAdapter

Attributes

config[R]

Public Class Methods

new(connection, pool, config) click to toggle source
# File lib/keymap/connection_adapters/redis_adapter.rb, line 20
def initialize(connection, pool, config)
  super(nil)
  @config = config
  reconnect!
end

Public Instance Methods

active?() click to toggle source
# File lib/keymap/connection_adapters/redis_adapter.rb, line 30
def active?
  return false unless @connection
  @connection.ping == "PONG"
end
adapter_name() click to toggle source
# File lib/keymap/connection_adapters/redis_adapter.rb, line 26
def adapter_name
  'redis'
end
begin_db_transaction() click to toggle source
# File lib/keymap/connection_adapters/redis_adapter.rb, line 61
def begin_db_transaction
  raw_connection.multi
end
commit_db_transaction() click to toggle source
# File lib/keymap/connection_adapters/redis_adapter.rb, line 65
def commit_db_transaction
  raw_connection.exec
end
delete(id) click to toggle source
# File lib/keymap/connection_adapters/redis_adapter.rb, line 73
def delete(id)
  raw_connection.del(id) != 0
end
disconnect!() click to toggle source

Disconnects from the database if already connected. Otherwise, this method does nothing.

# File lib/keymap/connection_adapters/redis_adapter.rb, line 45
def disconnect!
  super
  unless @connection.nil?
    @connection.quit
    @connection = nil
  end
end
hash(id) click to toggle source
# File lib/keymap/connection_adapters/redis_adapter.rb, line 77
def hash (id)
  RedisHash.new(raw_connection, id)
end
list(id) click to toggle source
# File lib/keymap/connection_adapters/redis_adapter.rb, line 81
def list (id)
  # todo idea: add an optional argument where we specify the data type for elements in the collection
  RedisList.new(raw_connection, id)
end
reconnect!() click to toggle source
# File lib/keymap/connection_adapters/redis_adapter.rb, line 35
def reconnect!
  disconnect!
  connect
  super
end
Also aliased as: reset!
reset!() click to toggle source
Alias for: reconnect!
rollback_db_transaction() click to toggle source
# File lib/keymap/connection_adapters/redis_adapter.rb, line 69
def rollback_db_transaction
  raw_connection.discard
end

Private Instance Methods

connect() click to toggle source
# File lib/keymap/connection_adapters/redis_adapter.rb, line 55
def connect
  @connection = Redis.new(config)
end