class Redis::Connection
- Redis::Connection
- Reference
- Object
Overview
The connection wraps the TCP connection to the Redis server.
Included Modules
Defined in:
connection.crConstant Summary
-
CRLF =
"\r\n"
Constructors
-
.new(uri : URI = URI.parse("redis:///"))
We receive all connection information in the URI.
Instance Method Summary
-
#close
Close the connection to the server.
-
#flush
Flush the connection buffer and make sure we've sent everything to the server.
-
#multi(&)
Execute a transaction within the server.
-
#pipeline(&)
Execute a pipeline of commands.
-
#read
Read the next value from the server
-
#run(command)
Execute the given command and return the result from the server.
- #subscribe(*channels : String, &block : Subscription, self -> )
- #unsubscribe(*channels : String)
Instance methods inherited from module Redis::Commands
brpop(*keys : String, timeout : Time::Span)brpop(*keys : String, timeout : Int | Float)
brpop(*keys : String, timeout : String) brpop, decr(key : String) decr, decrby(key : String, amount : Int | String) decrby, del(*keys : String) del, exists(*keys : String) exists, get(key : String) get, incr(key : String) incr, incrby(key : String, amount : Int | String) incrby, keys(pattern = "*") keys, lpush(key, *values) lpush, publish(channel : String, message : String) publish, rpop(key : String) rpop, rpoplpush(source : String, destination : String) rpoplpush, run(command) run, sadd(key : String, *values : String) sadd, scard(key : String) scard, sdiff(first : String, second : String) sdiff, set(key : String, value : String, ex = nil, px = nil, nx = false, xx = false, keepttl = false) : Nil set, sinter(first : String, *others : String) sinter, sismember(key : String, value : String) sismember, smembers(key : String) smembers, srem(key : String, *values : String) srem, xadd(key : String, id : String, maxlen, data : Hash(String, String))
xadd(key : String, id : String, data : Hash(String, String))
xadd(key : String, id : String, maxlen = nil, **data) xadd, xgroup(command : String, key : String, groupname : String)
xgroup(command : String, key : String, groupname : String, *args : String) xgroup, xlen(key : String) xlen, xrange(key : String, start min, end max, count = nil) xrange, xreadgroup(group : String, consumer : String, count : String | Int | Nil = nil, streams : NamedTuple = NamedTuple.new) xreadgroup
Constructor Detail
We receive all connection information in the URI.
SSL connections require specifying the rediss://
scheme.
Password authentication uses the URI password.
DB selection uses the URI path.
Instance Method Detail
Execute a transaction within the server. The transaction is automatically
committed at the end of the block or can be rolled back with
Transaction#discard
. Transactions are also rolled back if an exception
is raised.
redis.multi do |redis|
redis.set "foo", "bar"
redis.incr "counter"
raise "Oops!"
end
redis.get "foo" # => nil
redis.get "counter" # => nil
Execute a pipeline of commands. A pipeline sends all commands to the server before reading any of the results.
redis.pipeline do |redis|
redis.set "foo", "bar"
redis.incr "counter"
end
Execute the given command and return the result from the server. Commands must be an Enumerable
.
run({"set", "foo", "bar"})