写入 Redis 排序集
在下面的示例中,数据是从名为invoice
并写入 Redis 排序集。这connection
是一个可选参数,它引用config.yaml
.什么时候
您指定data_type
参数,它会覆盖系统范围的设置target_data_type
定义于config.yaml
.
写入排序集时,必须提供两个附加参数member
和score
.这些选项指定将用作成员的字段名称,以及用于将元素添加到排序集的分数。在这种情况下,结果将是名为invoices:sorted
基于 key 表达式,每个 Set 成员的过期时间为 100 秒。如果您不提供expire
参数,则密钥永远不会过期。
source:
server_name: chinook
schema: public
table: invoice
output:
- uses: redis.write
with:
connection: target
data_type: sorted_set
key:
expression: "`invoices:sorted`"
language: jmespath
args:
score: Total
member: InvoiceId
expire: 100
Since sorted sets in Redis are inherently sorted, you can easily get the top N invoices by total invoice amount using the command below (the range 0..9 gets the top 10 invoices):
ZREVRANGE invoices:sorted 0 9 WITHSCORES