class Redis::Connection

Overview

The connection wraps the TCP connection to the Redis server.

Included Modules

Defined in:

connection.cr
graph.cr

Constructors

Instance Method Summary

Instance methods inherited from module Redis::Commands

blpop(*keys : String, timeout : Time::Span)
blpop(*keys : String, timeout : Int | Float)
blpop(*keys : String, timeout : String)
blpop
, brpop(keys : Enumerable(String), timeout : Int)
brpop(*keys : String, timeout : Time::Span)
brpop(*keys : String, timeout : Number)
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, expire(key : String, ttl : Int) expire, expireat(key : String, at : Time) expireat, flushdb flushdb, ft ft, get(key : String) get, hget(key : String, field : String) hget, hgetall(key : String) hgetall, hmget(key : String, *fields : String) hmget, hmset(key : String, data : Hash(String, String)) hmset, hset(key : String, field : String, value : String) hset, incr(key : String) incr, incrby(key : String, amount : Int | String) incrby, info info, json json, keys(pattern = "*") keys, llen(key : String) llen, lpop(key : String, count : String | Nil = nil) lpop, lpush(key : String, values : Enumerable(String))
lpush(key, *values : String)
lpush
, lrange(key : String, starting : String, ending : String) lrange, lrem(key : String, count : Int, value : String) lrem, mget(keys : Enumerable(String)) mget, mset(data : Hash(String, String)) mset, pexpire(key : String, ttl : Int) pexpire, pexpireat(key : String, at : Time) pexpireat, pttl(key : String) pttl, publish(channel : String, message : String) publish, rpop(key : String) rpop, rpoplpush(source : String, destination : String) rpoplpush, rpush(key, *values : String) rpush, run(command) run, sadd(key : String, *values : String) sadd, scan(cursor : String = "0", match : String | Nil = nil, count : String | Int | Nil = nil, type : String | Nil = nil) scan, scard(key : String) scard, sdiff(first : String, second : String) sdiff, set(key : String, value : String, ex : String | Int | Nil = nil, px : String | Int | Nil = nil, nx = false, xx = false, keepttl = false)
set(key, value, ex : Time, nx = false, xx = false, keepttl = false)
set(key, value, ex : Time::Span, nx = false, xx = false, keepttl = false)
set
, sinter(first : String, *others : String) sinter, sismember(key : String, value : String) sismember, smembers(key : String) smembers, srem(key : String, members : Enumerable(String))
srem(key : String, *values : String)
srem
, ts ts, ttl(key : String) ttl, type(key : String) type, unlink(*keys : String) unlink, xack(key : String, group : String, id : String)
xack(key : String, group : String, ids : Enumerable(String))
xack
, 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
, xautoclaim(key : String, group : String, consumer : String, min_idle_time : Time::Span, start : String, count : Int | String | Nil = nil) xautoclaim, xgroup(command : String, key : String, groupname : String)
xgroup(command : XGroup, key : String, groupname : String, *, id : String | Nil = nil, mkstream = false, consumer_name : String | Nil = nil)
xgroup(command : String, key : String, groupname : String, *args : String)
xgroup
, xgroup_create(key : String, groupname : String, *, id : String = "$", mkstream = false) xgroup_create, xgroup_create_consumer(key : String, groupname : String, consumer_name : String) xgroup_create_consumer, xlen(key : String) xlen, xpending(key : String, group : String, start : String, end finish : String, count : String | Int, idle : String | Time::Span | Nil = nil)
xpending(key : String, group : String)
xpending
, xrange(key : String, start min, end max, count = nil) xrange, xreadgroup(group : String, consumer : String, count : String | Int | Nil = nil, block : Time::Span | String | Int | Nil = nil, no_ack = false, streams : Hash(String, String) = {} of String => String)
xreadgroup(group : String, consumer : String, count : String | Int | Nil = nil, block : Time::Span | String | Int | Nil = nil, no_ack = false, streams : NamedTuple = NamedTuple.new)
xreadgroup
, zadd(key : String, score : String | Float, value : String)
zadd(key : String, values : Enumerable)
zadd
, zcard(key : String) zcard, zrange(key : String, starting : String | Int, ending : String | Int, with_scores : Bool = false) zrange, zrangebyscore(key : String, low : String | Float, high : String | Float, limit : Enumerable(String) | Nil = nil) zrangebyscore, zrem(key : String, value : String) zrem, zremrangebyrank(key : String, low : Int, high : Int) zremrangebyrank, zremrangebyscore(key : String, low : String | Float, high : String | Float) zremrangebyscore, zrevrange(key : String, starting : String | Int, ending : String | Int, with_scores : Bool = false) zrevrange

Constructor Detail

def self.new(uri : URI = URI.parse("redis:///")) #

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.


[View source]

Instance Method Detail

def close #

Close the connection to the server.


[View source]
def encode(command) #

[View source]
def flush #

Flush the connection buffer and make sure we've sent everything to the server.


[View source]
def multi(retries = 5, &) #

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

[View source]
def pipeline(&) #

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

[View source]
def psubscribe(*channels : String, &block : Subscription, self -> ) #

[View source]
def punsubscribe(*channels : String) #

[View source]
def read #

Read the next value from the server


[View source]
def readonly! : Nil #

[View source]
def run(command, retries = 5) : Value #

Execute the given command and return the result from the server. Commands must be an Enumerable.

run({"set", "foo", "bar"})

[View source]
def scan_each(match pattern : String | Nil = nil, count : String | Int | Nil = nil, type : String | Nil = nil, &) : Nil #

[View source]
def subscribe(*channels : String, &block : Subscription, self -> ) #

[View source]
def subscribe(*channels : String) #

[View source]
def unsubscribe(*channels : String) #

[View source]
def url #

[View source]