module
Redis::Commands::Immediate
Overview
Immediate objects are ones that execute commands on the server and return
their results immediately. This allows the caller to know that it can
go to work on the results directly. The counterpart to this is the Deferred
type.
client = Redis::Client.new
p! typeof(client.get("foo")) # => (String | Nil)
client.pipeline do |pipeline|
p! typeof(pipeline.get("foo")) # => Redis::Future
end
client.multi do |txn|
p! typeof(txn.get("foo")) # => Nil
end
Objects that include this mixin must return a Redis::Value from their run
method. This mixin overrides various Redis command methods to downcast the
return types to only the types that the Redis server is known to return.
Direct including types
Defined in:
commands/immediate.crMacro Summary
Instance Method Summary
-
#get!(key : String) : String
Returns the value of the string stored in
key, asserting that it exists.
Macro Detail
Instance Method Detail
def get!(key : String) : String
#
Returns the value of the string stored in key, asserting that it exists.
require "redis"
require "msgpack" # Storing MessagePack data
struct Cart
include MessagePack::Serializable
getter user_id : Int64
getter items : Array(Item)
struct Item
include MessagePack::Serializable
getter id : Int64
getter product_id : Int64
getter quantity : Int32
getter unit_price_cents : Int64
end
end
p! Cart.from_msgpack(redis.get!("cart:123"))