module Redis::Commands::Deferred

Overview

Deferred command objects are ones that defer the execution of the command in some way. For example, Pipeline defers receiving the results of a command and Transaction defers the execution of sent commands by the server until the server receives the EXEC command.

Deferred objects may return anything from their run method.

Direct including types

Defined in:

commands/deferred.cr
topk.cr

Instance Method Summary

Instance Method Detail

def topk #

Returns a TopK to allow running TOPK.* commands in Redis.

require "redis/topk"

# Create a TopK data structure with a large width and depth to be more
# accurate with larger data sets.
redis.topk.reserve "most-ordered-items", 10,
  width: 1_000,
  depth: 1_000,
  decay: 0.9

# Run through all the line items in the database to get the product ids,
# storing them in the TopK in Redis.
LineItemQuery.new.product_ids.each do |product_id|
  redis.topk.add "most-ordered-items", product_id
end

# Get the most ordered products
ProductQuery.new.find(redis.topk.list("most-ordered-items"))

[View source]