community.general.redis_data_incr 模块 – 递增 Redis 中的键

注意

此模块是 community.general 集合(版本 10.1.0)的一部分。

如果您正在使用 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.general。您需要进一步的要求才能使用此模块,请参阅 要求 了解详细信息。

要在 Playbook 中使用它,请指定:community.general.redis_data_incr

community.general 4.0.0 中的新增功能

概要

  • 递增 Redis 数据库中的整数或浮点数键并获取新值。

  • 所有键的默认增量为 1。对于特定增量,请使用 increment_intincrement_float 选项。

要求

以下要求在执行此模块的主机上是必需的。

  • redis

  • certifi

参数

参数

注释

ca_certs

字符串

根证书文件的路径。如果未设置且 tls 设置为 true,则将使用 certifi ca 证书。

client_cert_file

字符串

在 community.general 9.3.0 中添加

客户端证书文件的路径。

client_key_file

字符串

在 community.general 9.3.0 中添加

客户端私钥文件的路径。

increment_float

浮点数

键要递增的浮点数金额。

这仅适用于在其字符串表示形式中包含浮点数值的键。

increment_int

整数

键要递增的整数金额。

key

字符串 / 必需

数据库键。

login_host

字符串

指定运行数据库的目标主机。

默认值: "localhost"

login_password

字符串

指定用于身份验证的密码。

当目标是 localhost 时,通常不使用。

login_port

整数

指定要连接的端口。

默认值: 6379

login_user

字符串

指定用于身份验证的用户。

需要 redis >= 3.4.0。

tls

布尔值

指定是否对连接使用 TLS。

选项

  • false

  • true ← (默认)

validate_certs

布尔值

指定是否验证 TLS 证书。

仅当个人控制的站点或使用 localhost 作为目标时,才应关闭此选项。

选项

  • false

  • true ← (默认)

属性

属性

支持

描述

check_mode

支持:部分

为了使 check_mode 工作,指定的 login_user 需要有权对键运行 GET 命令,否则模块将失败。

当使用 check_mode 时,模块将尝试计算 Redis 将返回的值。如果该键不存在,则将 0.0 用作值。

可以在 check_mode 中运行,并返回更改的状态预测而不修改目标。

diff_mode

支持:

当处于差异模式时,将返回已更改的内容(或可能需要在 check_mode 中更改的内容)的详细信息。

备注

注意

  • 需要在远程主机上安装 redis Python 包。您可以使用 pip (pip install redis) 或使用软件包管理器来安装它。有关该库的信息,请访问 https://github.com/andymccurdy/redis-py

另请参阅

另请参阅

community.general.redis_data

在 Redis 中设置键值对。

community.general.redis_data_info

获取 Redis 数据库中键的值。

community.general.redis

各种 redis 命令,副本和刷新。

示例

- name: Increment integer key foo on localhost with no username and print new value
  community.general.redis_data_incr:
    login_host: localhost
    login_password: supersecret
    key: foo
    increment_int: 1
  register: result
- name: Print new value
  debug:
    var: result.value

- name: Increment float key foo by 20.4
  community.general.redis_data_incr:
    login_host: redishost
    login_user: redisuser
    login_password: somepass
    key: foo
    increment_float: '20.4'

返回值

常用返回值记录在这里,以下是此模块特有的字段

描述

msg

字符串

一条简短的消息。

返回: 总是

示例: "将键: foo 增加了 20.4 65.9"

浮点数

键的递增值

返回: 成功时

示例: 4039.4

作者

  • Andreas Botzner (@paginabianca)