class Oxblood::Session

Implements usual Request/Response protocol. Error responses will be raised.

@note {Session} don't maintain threadsafety! In multithreaded environment

please use {Pool}

@example

conn = Oxblood::Connection.new
session = Oxblood::Session.new(conn)
session.ping # => 'PONG'

Attributes

connection[R]

Public Class Methods

new(connection) click to toggle source
# File lib/oxblood/session.rb, line 20
def initialize(connection)
  @connection = connection
end

Public Instance Methods

pipelined() { |pipeline| ... } click to toggle source

Send queries using pipelining. Sync operation will be executed automatically at the end of a block.

@see redis.io/topics/pipelining

@yield [pipeline] provide {Pipeline} to a block @yieldreturn [Array] responses from all executed operations

@example

session = Oxblood::Session.new(Oxblood::Connection.new)
session.pipelined do |pipeline|
  pipeline.set('hello', 'world')
  pipeline.get('hello')
end # => ['OK', 'world']
# File lib/oxblood/session.rb, line 38
def pipelined
  pipeline = Pipeline.new(connection)
  yield pipeline
  pipeline.sync
end
run_command(*command) click to toggle source

Send command to Redis server and read response from it. Useful for executing unimplemented in adapter Redis commands.

@example

session.run_command(:CLIENT, :SETNAME, 'cust-name') => 'OK'

@param [Array] command Array of command name with it's args

# File lib/oxblood/session.rb, line 51
def run_command(*command)
  connection.run_command(*command)
end

Private Instance Methods

error?(response) click to toggle source
# File lib/oxblood/session.rb, line 62
def error?(response)
  Protocol::RError === response
end
run(*command) click to toggle source
# File lib/oxblood/session.rb, line 57
def run(*command)
  response = @connection.run_command(*command)
  error?(response) ? (raise response) : response
end