salt.cache.redis_cache#
Redis#
Redis plugin for the Salt caching subsystem.
New in version 2017.7.0.
Changed in version 3005.
To enable this cache plugin, the master will need the python client for redis installed. This can be easily installed with pip:
salt \* pip.install redis>=6.1.0
As Redis provides a simple mechanism for very fast key-value store, in order to provide the necessary features for the Salt caching subsystem, the following conventions are used:
As the caching subsystem is organised as a tree, we need to store the caching path and identify the bank and its offspring. At the same time, Redis is linear and we need to avoid doing
keys <pattern>which is very inefficient as it goes through all the keys on the remote Redis server. Instead a SORTED SET of all banks is stored in a single value. This can act as an index for finding sub-banks. By default this key is prefixed with$BANKS_.Each bank is stored as a hash. It is a simple mechanism and allows for fast access to the data and of the keys. By default this key is prefixed with
$KEYS_.An additional hash is used to store the last update time of each cache key. By default this key is prefixed with
$TSTAMP_.
For example, to store the key my-key with value my-value under the bank
root-bank/sub-bank/leaf-bank, the following datastructures will be created.
127.0.0.1:6379> ZSCAN $BANKS_ 0
1) "0"
2) 1) "$KEYS_root-bank/sub-bank/leaf-bank/"
2) "0"
127.0.0.1:6379> HGETALL $KEYS_root-bank/sub-bank/leaf-bank/
1) "my-key"
2) "my-value"
127.0.0.1:6379> HGETALL $TSTAMP_root-bank/sub-bank/leaf-bank/
1) "my-key"
2) "1773671718"
There are three types of keys stored:
$BANKS_*is a Redis SORTED SET containing the list of all banks$KEYS_*is a Redis SET containing key, value pairs of the current bank.$TSTAMP_*stores the last updated timestamp of the key.
These prefixes and the separator can be adjusted using the configuration options:
- banks_prefix:
$BANK The prefix used for the name of the Redis key storing the sorted set of banks.
- keys_prefix:
$KEY The prefix used for Redis keys storing bank key/value pairs.
- timestamp_prefix:
$TSTAMP The prefix used for Redis keys storing timestamps of bank keys.
New in version 3005.
- separator:
_ The separator between the prefix and the key body.
The connection details can be specified using:
- host:
localhost The hostname of the Redis server.
- port:
6379 The Redis server port.
- cluster_mode:
False Whether cluster_mode is enabled or not
- cluster.startup_nodes:
A list of host, port dictionaries pointing to cluster members. At least one is required but multiple nodes are better
cache.redis.cluster.startup_nodes - host: redis-member-1 port: 6379 - host: redis-member-2 port: 6379
- cluster.skip_full_coverage_check:
False Some cluster providers restrict certain redis commands such as CONFIG for enhanced security. Set this option to true to skip checks that required advanced privileges.
Note
Most cloud hosted redis clusters will require this to be set to
True- db:
'0' The database index.
Note
The database index must be specified as string not as integer value!
- password:
Redis connection password.
unix_socket_path:
New in version 2018.3.1.
Path to a UNIX socket for access. Overrides host / port.
Configuration Example:
cache.redis.host: localhost
cache.redis.port: 6379
cache.redis.db: '0'
cache.redis.password: my pass
cache.redis.banks_prefix: #BANKS
cache.redis.keys_prefix: #KEYS
cache.redis.timestamp_prefix: #TSTAMP
cache.redis.separator: '_'
Cluster Configuration Example:
cache.redis.cluster_mode: true
cache.redis.cluster.skip_full_coverage_check: true
cache.redis.cluster.startup_nodes:
- host: redis-member-1
port: 6379
- host: redis-member-2
port: 6379
cache.redis.db: '0'
cache.redis.password: my pass
cache.redis.banks_prefix: #BANKS
cache.redis.keys_prefix: #KEYS
cache.redis.timestamp_prefix: #TSTAMP
cache.redis.separator: '_'
- salt.cache.redis_cache.contains(bank, key=None)#
Checks if the specified bank contains the specified key.
- salt.cache.redis_cache.fetch(bank, key)#
Fetch data from the Redis cache.
- salt.cache.redis_cache.flush(bank, key=None)#
Remove the key from the cache bank with all the key content. If no key is specified, remove the entire bank with all keys and sub-banks inside.
- salt.cache.redis_cache.init_kwargs(kwargs)#
Effectively a noop. Return an empty dictionary.
- salt.cache.redis_cache.list_(bank)#
Lists entries stored in the specified bank.
- salt.cache.redis_cache.store(bank, key, data)#
Store the data in a Redis key.
- salt.cache.redis_cache.updated(bank, key)#
Return the Unix Epoch timestamp of when the key was last updated. Return None if key is not found.