module Redis::Commands

Overview

All Redis commands are defined in this module. Any paradigm that needs to use these commands simply overrides #run, which takes a single command object, which must be an Enumerable.

TODO Add more Redis commands from https://redis.io/commands

Included Modules

Direct including types

Defined in:

commands.cr
commands/hash.cr
json.cr
search.cr
time_series.cr

Instance Method Summary

Instance methods inherited from module Redis::Commands::Stream

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, xdel(key : String, ids : Enumerable(String))
xdel(key : String, *ids : String)
xdel
, 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

Instance methods inherited from module Redis::Commands::SortedSet

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

Instance methods inherited from module Redis::Commands::Set

sadd(key : String, *values : String) sadd, scard(key : String) scard, sdiff(first : String, second : String) sdiff, 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

Instance methods inherited from module Redis::Commands::List

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
, 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, start : String, finish : String) lrange, lrem(key : String, count : Int, value : String) lrem, rpop(key : String) rpop, rpoplpush(source : String, destination : String) rpoplpush, rpush(key, *values : String) rpush

Instance methods inherited from module Redis::Commands::Hash

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, data : ::Hash(String, String))
hset(key : String, *fields : String)
hset(key : String, **fields : String)
hset

Instance Method Detail

def decr(key : String) #

Atomically decrement and return the integer value for the specified key, creating it if it does not exist

redis.del "counter"
redis.decr "counter" # => -1

[View source]
def decrby(key : String, amount : Int | String) #

Atomically decrement and return the integer value for the specified key by the specified amount, creating it if it does not exist

redis.del "counter"
redis.decrby "counter", 2 # => -2

[View source]
def del(*keys : String) #

Delete all specified keys and return the number of keys deleted.

redis.set "foo", "12"
redis.del "foo", "bar" # => 1
redis.del "foo", "bar" # => 0

[View source]
def exists(*keys : String) #

Return the number of specified keys that exist

redis.exists("foo", "bar") # => 0
redis.set "foo", "exists now"
redis.exists("foo", "bar") # => 1
redis.set "bar", "also exists now"
redis.exists("foo", "bar") # => 2

[View source]
def expire(key : String, ttl : Int) #

[View source]
def expireat(key : String, at : Time) #

[View source]
def flushdb #

[View source]
def ft #

EXPERIMENTAL RediSearch support is still under development. Some APIs may change while details are discovered.


[View source]
def get(key : String) #

Get the value for the specified key

redis.set "foo", "bar"
redis.get("foo") # => "bar"

[View source]
def incr(key : String) #

Atomically increment and return the integer value for the specified key, creating it if it does not exist

redis.del "counter"
redis.incr "counter" # => 1

[View source]
def incrby(key : String, amount : Int | String) #

Atomically increment and return the integer value for the specified key by the specified amount, creating it if it does not exist

redis.del "counter"
redis.incrby "counter", 2 # => 2

[View source]
def info #

[View source]
def json #

Return a Redis::JSON instance that wraps the current Redis::Client or Redis::Cluster.

EXPERIMENTAL Support for the RedisJSON module is still under development and subject to change.


[View source]
def keys(pattern = "*") #

Get the keys whose names follow the specified glob pattern. If a pattern is not specified, it will return all keys by default. Be careful when using this command on Redis servers with a lot of traffic and millions of keys.

redis.keys       # => ["foo", "bar", "baz"]
redis.keys("f*") # => ["foo"]
redis.keys("b*") # => ["bar", "baz"]

[View source]
def mget(keys : Enumerable(String)) #

[View source]
def mset(data : Hash(String, String)) #

[View source]
def pexpire(key : String, ttl : Int) #

[View source]
def pexpireat(key : String, at : Time) #

[View source]
def pttl(key : String) #

[View source]
def publish(channel : String, message : String) #

[View source]
abstract def run(command) #

Execute the given command and return the result from the server. Commands must be an Enumerable and its size method must be re-entrant.

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

[View source]
def scan(cursor : String = "0", match : String | Nil = nil, count : String | Int | Nil = nil, type : String | Nil = nil) #

[View source]
def set(key : String, value : String, ex : String | Int | Nil = nil, px : String | Int | Nil = nil, nx = false, xx = false, keepttl = false) #

Set a given key to a given value, optionally specifying time-to-live (TTL).

  • ex: TTL in seconds (mnemonic: "ex" = "expiration")
  • px: TTL in milliseconds
  • nx: Only set this key if it does not exist (mnemonic: "nx" = it does "not exist")
  • xx: only set this key if it does exist (mnemonic: "xx" = it "exists exists" — look, I don't make the rules)
  • keepttl: If there is a TTL already set on the key, retain that TTL instead of overwriting it
redis.set "foo", "bar", ex: 1
redis.get("foo") # => "bar"
sleep 1.second
redis.get("foo") # => nil

[View source]
def set(key, value, ex : Time, nx = false, xx = false, keepttl = false) #

[View source]
def set(key, value, ex : Time::Span, nx = false, xx = false, keepttl = false) #

[View source]
def ts #

Return a Redis::TimeSeries that wraps the current Redis::Client or Redis::Cluster.


[View source]
def ttl(key : String) #

[View source]
def type(key : String) #

[View source]
def unlink(keys : Enumerable(String)) #

[View source]
def unlink(*keys : String) #

[View source]