写入Redis有序集合

在下面的示例中,数据从名为invoice的源表中捕获,并写入Redis有序集合。connection是一个可选参数,指的是在config.yaml中定义的相应连接名称。当您为作业指定data_type参数时,它会覆盖在config.yaml中定义的系统范围设置target_data_type

在写入有序集合时,您必须提供两个额外的参数,memberscore。这些参数指定了将用作成员和分数的字段名称,以向有序集合添加元素。在这种情况下,结果将是一个基于键表达式的名为 invoices:sorted 的 Redis 有序集合,并且每个集合成员的过期时间为 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      

由于Redis中的有序集合本质上是排序的,您可以使用以下命令轻松获取按发票总金额排序的前N张发票(范围0..9获取前10张发票):

ZREVRANGE invoices:sorted 0 9 WITHSCORES
RATE THIS PAGE
Back to top ↑