community.general.redis_data 模块 – 在 Redis 中设置键值对
注意
此模块是 community.general 集合(版本 10.1.0)的一部分。
如果您正在使用 ansible
包,您可能已经安装了此集合。它不包含在 ansible-core
中。要检查是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install community.general
。您需要更多要求才能使用此模块,请参阅 要求 了解详细信息。
要在 playbook 中使用它,请指定:community.general.redis_data
。
community.general 3.7.0 中的新增功能
概要
在 Redis 数据库中设置键值对。
要求
执行此模块的主机上需要以下要求。
redis
certifi
参数
参数 |
注释 |
---|---|
根证书文件的路径。如果未设置且 |
|
客户端证书文件的路径。 |
|
客户端私钥文件的路径。 |
|
仅在键已存在时设置键。 选项
|
|
过期时间(毫秒)。设置此标志将始终导致数据库发生更改。 |
|
保留与键关联的生存时间。 选项
|
|
数据库键。 |
|
指定运行数据库的目标主机。 默认值: |
|
指定用于身份验证的密码。 当目标是 localhost 时,通常不使用。 |
|
指定要连接的端口。 默认值: |
|
指定用于身份验证的用户。 需要 redis >= 3.4.0。 |
|
仅在键尚不存在时设置键。 选项
|
|
键的状态。 选项
|
|
指定是否对连接使用 TLS。 选项
|
|
指定是否验证 TLS 证书。 仅应为个人控制的站点或以 选项
|
|
键应设置的值。 |
属性
属性 |
支持 |
描述 |
---|---|---|
支持: 完整 |
可以在 |
|
支持: 无 |
在差异模式下运行时,将返回有关已更改内容(或可能需要在 |
注意
注意
远程主机上需要
redis
Python 包。您可以使用 pip (pip install redis
) 或使用包管理器安装它。有关该库的信息,请访问 https://github.com/andymccurdy/redis-py。
另请参阅
另请参阅
- community.general.redis_data_incr
递增 Redis 中的键。
- community.general.redis_data_info
获取 Redis 数据库中键的值。
- community.general.redis
各种 redis 命令、副本和刷新。
示例
- name: Set key foo=bar on localhost with no username
community.general.redis_data:
login_host: localhost
login_password: supersecret
key: foo
value: bar
state: present
- name: Set key foo=bar if non existing with expiration of 30s
community.general.redis_data:
login_host: localhost
login_password: supersecret
key: foo
value: bar
non_existing: true
expiration: 30000
state: present
- name: Set key foo=bar if existing and keep current TTL
community.general.redis_data:
login_host: localhost
login_password: supersecret
key: foo
value: bar
existing: true
keep_ttl: true
- name: Set key foo=bar on redishost with custom ca-cert file
community.general.redis_data:
login_host: redishost
login_password: supersecret
login_user: someuser
validate_certs: true
ssl_ca_certs: /path/to/ca/certs
key: foo
value: bar
- name: Delete key foo on localhost with no username
community.general.redis_data:
login_host: localhost
login_password: supersecret
key: foo
state: absent
返回值
常见的返回值记录在 此处,以下是此模块特有的字段
键 |
描述 |
---|---|
简短的消息。 返回: 始终 示例: |
|