Class: Oxblood::Session

Inherits:
Object
  • Object
show all
Includes:
Commands
Defined in:
lib/oxblood/session.rb

Overview

Note:

Session don’t maintain threadsafety! In multithreaded environment please use Pool

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

Examples:

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Commands::Transactions

#discard, #exec, #multi, #unwatch, #watch

Methods included from Commands::SortedSets

#zadd, #zcard, #zcount, #zincrby, #zinterstore, #zlexcount, #zrange, #zrangebylex, #zrangebyscore, #zrank, #zrem, #zremrangebylex, #zremrangebyrank, #zremrangebyscore, #zrevrange, #zrevrangebylex, #zrevrangebyscore, #zrevrank, #zscan, #zscore, #zunionstore

Methods included from Commands::Scripting

#eval, #evalsha, #script_debug, #script_exists, #script_flush, #script_kill, #script_load

Methods included from Commands::Sets

#sadd, #scard, #sdiff, #sdiffstore, #sinter, #sinterstore, #sismember, #smembers, #smove, #spop, #srandmember, #srem, #sscan, #sunion, #sunionstore

Methods included from Commands::Lists

#blpop, #brpop, #brpoplpush, #lindex, #linsert, #llen, #lpop, #lpush, #lpushx, #lrange, #lrem, #lset, #ltrim, #rpop, #rpoplpush, #rpush, #rpushx

Methods included from Commands::Keys

#del, #dump, #exists, #expire, #expireat, #keys, #move, #object, #persist, #pexpire, #pexpireat, #pttl, #randomkey, #rename, #renamenx, #restore, #scan, #ttl, #type

Methods included from Commands::Server

#bgrewriteaof, #bgsave, #client_getname, #client_kill, #client_list, #client_pause, #client_setname, #command, #command_count, #command_getkeys, #command_info, #config_get, #config_resetstat, #config_rewrite, #config_set, #dbsize, #flushall, #flushdb, #info, #lastsave, #role, #save, #shutdown, #slaveof, #slowlog, #time

Methods included from Commands::Geo

#geoadd, #geodist, #geohash, #geopos, #georadius, #georadiusbymember

Methods included from Commands::Connection

#auth, #echo, #ping, #quit, #select

Methods included from Commands::Strings

#append, #bitcount, #bitop, #bitpos, #decr, #decrby, #get, #getbit, #getrange, #getset, #incr, #incrby, #incrbyfloat, #mget, #mset, #msetnx, #psetex, #set, #setbit, #setex, #setnx, #setrange, #strlen

Methods included from Commands::HyperLogLog

#pfadd, #pfcount, #pfmerge

Methods included from Commands::Hashes

#hdel, #hexists, #hget, #hgetall, #hincrby, #hincrbyfloat, #hkeys, #hlen, #hmget, #hmset, #hscan, #hset, #hsetnx, #hstrlen, #hvals

Constructor Details

#initialize(connection) ⇒ Session

Returns a new instance of Session.



20
21
22
# File 'lib/oxblood/session.rb', line 20

def initialize(connection)
  @connection = connection
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



18
19
20
# File 'lib/oxblood/session.rb', line 18

def connection
  @connection
end

Instance Method Details

#pipelined {|pipeline| ... } ⇒ Object

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

Examples:

session = Oxblood::Session.new(Oxblood::Connection.new)
session.pipelined do |pipeline|
  pipeline.set('hello', 'world')
  pipeline.get('hello')
end # => ['OK', 'world']

Yields:

  • (pipeline)

    provide Pipeline to a block

Yield Returns:

  • (Array)

    responses from all executed operations

See Also:



38
39
40
41
42
# File 'lib/oxblood/session.rb', line 38

def pipelined
  pipeline = Pipeline.new(connection)
  yield pipeline
  pipeline.sync
end

#run_command(*command) ⇒ Object

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

Examples:

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

Parameters:

  • command (Array)

    Array of command name with it’s args



51
52
53
# File 'lib/oxblood/session.rb', line 51

def run_command(*command)
  connection.run_command(*command)
end