Class: Oxblood::Pipeline

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

Overview

Redis pipeling class. Commands won’t be send until #sync is called. Error responses won’t be raises and should be checked manually in the responses array.

Examples:

Basic workflow

pipeline = Pipeline.new(connection)
pipeline.echo('ping')
pipeline.ping
pipeline.echo('!')
pipeline.sync # => ["ping", "PONG", "!"]

See Also:

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, #zlexcount, #zrange, #zrangebyscore, #zrank, #zrem, #zremrangebyrank, #zremrangebyscore, #zrevrange, #zrevrangebyscore, #zrevrank, #zscore

Methods included from Commands::Sets

#sadd, #scard, #sdiff, #sdiffstore, #sinter, #sinterstore, #sismember, #smembers, #smove, #spop, #srandmember, #srem, #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, #ttl, #type

Methods included from Commands::Server

#flushdb, #info

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, #hset, #hsetnx, #hstrlen, #hvals

Constructor Details

#initialize(connection) ⇒ Pipeline

Returns a new instance of Pipeline.



21
22
23
24
# File 'lib/oxblood/pipeline.rb', line 21

def initialize(connection)
  @connection = connection
  @commands = Array.new
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



19
20
21
# File 'lib/oxblood/pipeline.rb', line 19

def connection
  @connection
end

Instance Method Details

#syncArray

Sends all commands at once and reads responses

Returns:

  • (Array)

    of responses



28
29
30
31
32
33
34
# File 'lib/oxblood/pipeline.rb', line 28

def sync
  serialized_commands = @commands.map { |c| Protocol.build_command(*c) }
  connection.socket.write(serialized_commands.join)
  Array.new(@commands.size) { connection.read_response }
ensure
  @commands.clear
end