redis – Various redis commands, slave and flush

Synopsis

  • Unified utility to interact with redis instances.

Requirements

The below requirements are needed on the host that executes this module.

  • redis

Parameters

Parameter Choices/Defaults Comments
command
- / required
    Choices:
  • config
  • flush
  • slave
The selected redis command
config (new in 1.6), ensures a configuration setting on an instance.
flush flushes all the instance or a specified db.
slave sets a redis instance in slave or master mode.
db
-
The database to flush (used in db mode) [flush command]
flush_mode
-
    Choices:
  • all ←
  • db
Type of flush (all the dbs in a redis instance or a specific one) [flush command]
login_host
-
Default:
"localhost"
The host running the database
login_password
-
The password used to authenticate with (usually not used)
login_port
-
Default:
6379
The port to connect to
master_host
-
The host of the master instance [slave command]
master_port
-
The port of the master instance [slave command]
name
-
A redis config key.
slave_mode
-
    Choices:
  • master
  • slave ←
the mode of the redis instance [slave command]
value
-
A redis config value.

Notes

Note

  • Requires the redis-py Python package on the remote host. You can install it with pip (pip install redis) or with a package manager. https://github.com/andymccurdy/redis-py
  • If the redis master instance we are making slave of is password protected this needs to be in the redis.conf in the masterauth variable

Examples

- name: Set local redis instance to be slave of melee.island on port 6377
  redis:
    command: slave
    master_host: melee.island
    master_port: 6377

- name: Deactivate slave mode
  redis:
    command: slave
    slave_mode: master

- name: Flush all the redis db
  redis:
    command: flush
    flush_mode: all

- name: Flush only one db in a redis instance
  redis:
    command: flush
    db: 1
    flush_mode: db

- name: Configure local redis to have 10000 max clients
  redis:
    command: config
    name: maxclients
    value: 10000

- name: Configure local redis to have lua time limit of 100 ms
  redis:
    command: config
    name: lua-time-limit
    value: 100

Status

Authors

  • Xabier Larrakoetxea (@slok)

Hint

If you notice any issues in this documentation, you can edit this document to improve it.