# salt.modules.redis

Module to provide redis functionality to Salt

Added in version 2014.7.0.

configuration:

  This module requires the redis python module and uses the following defaults which may be overridden in the minion configuration:

    redis.host: 'salt'
    redis.port: 6379
    redis.db: 0
    redis.password: None

salt.modules.redismod.bgrewriteaof(host=None, port=None, db=None, password=None)

  Asynchronously rewrite the append-only file

  CLI Example:

      salt '*' redis.bgrewriteaof

salt.modules.redismod.bgsave(host=None, port=None, db=None, password=None)

  Asynchronously save the dataset to disk

  CLI Example:

      salt '*' redis.bgsave

salt.modules.redismod.config_get(pattern='*', host=None, port=None, db=None, password=None)

  Get redis server configuration values

  CLI Example:

      salt '*' redis.config_get
      salt '*' redis.config_get port

salt.modules.redismod.config_set(name, value, host=None, port=None, db=None, password=None)

  Set redis server configuration values

  CLI Example:

      salt '*' redis.config_set masterauth luv_kittens

salt.modules.redismod.dbsize(host=None, port=None, db=None, password=None)

  Return the number of keys in the selected database

  CLI Example:

      salt '*' redis.dbsize

salt.modules.redismod.delete(*keys, **connection_args)

  Deletes the keys from redis, returns number of keys deleted

  CLI Example:

      salt '*' redis.delete foo

salt.modules.redismod.exists(key, host=None, port=None, db=None, password=None)

  Return true if the key exists in redis

  CLI Example:

      salt '*' redis.exists foo

salt.modules.redismod.expire(key, seconds, host=None, port=None, db=None, password=None)

  Set a keys time to live in seconds

  CLI Example:

      salt '*' redis.expire foo 300

salt.modules.redismod.expireat(key, timestamp, host=None, port=None, db=None, password=None)

  Set a keys expire at given UNIX time

  CLI Example:

      salt '*' redis.expireat foo 1400000000

salt.modules.redismod.flushall(host=None, port=None, db=None, password=None)

  Remove all keys from all databases

  CLI Example:

      salt '*' redis.flushall

salt.modules.redismod.flushdb(host=None, port=None, db=None, password=None)

  Remove all keys from the selected database

  CLI Example:

      salt '*' redis.flushdb

salt.modules.redismod.get_key(key, host=None, port=None, db=None, password=None)

  Get redis key value

  CLI Example:

      salt '*' redis.get_key foo

salt.modules.redismod.get_master_ip(host=None, port=None, password=None)

  Get host information about slave

  Added in version 2016.3.0.

  CLI Example:

      salt '*' redis.get_master_ip

salt.modules.redismod.hdel(key, *fields, **options)

  Delete one of more hash fields.

  Added in version 2017.7.0.

  CLI Example:

      salt '*' redis.hdel foo_hash bar_field1 bar_field2

salt.modules.redismod.hexists(key, field, host=None, port=None, db=None, password=None)

  Determine if a hash fields exists.

  Added in version 2017.7.0.

  CLI Example:

      salt '*' redis.hexists foo_hash bar_field

salt.modules.redismod.hget(key, field, host=None, port=None, db=None, password=None)

  Get specific field value from a redis hash, returns dict

  CLI Example:

      salt '*' redis.hget foo_hash bar_field

salt.modules.redismod.hgetall(key, host=None, port=None, db=None, password=None)

  Get all fields and values from a redis hash, returns dict

  CLI Example:

      salt '*' redis.hgetall foo_hash

salt.modules.redismod.hincrby(key, field, increment=1, host=None, port=None, db=None, password=None)

  Increment the integer value of a hash field by the given number.

  Added in version 2017.7.0.

  CLI Example:

      salt '*' redis.hincrby foo_hash bar_field 5

salt.modules.redismod.hincrbyfloat(key, field, increment=1.0, host=None, port=None, db=None, password=None)

  Increment the float value of a hash field by the given number.

  Added in version 2017.7.0.

  CLI Example:

      salt '*' redis.hincrbyfloat foo_hash bar_field 5.17

salt.modules.redismod.hlen(key, host=None, port=None, db=None, password=None)

  Returns number of fields of a hash.

  Added in version 2017.7.0.

  CLI Example:

      salt '*' redis.hlen foo_hash

salt.modules.redismod.hmget(key, *fields, **options)

  Returns the values of all the given hash fields.

  Added in version 2017.7.0.

  CLI Example:

      salt '*' redis.hmget foo_hash bar_field1 bar_field2

salt.modules.redismod.hmset(key, **fieldsvals)

  Sets multiple hash fields to multiple values.

  Added in version 2017.7.0.

  CLI Example:

      salt '*' redis.hmset foo_hash bar_field1=bar_value1 bar_field2=bar_value2

salt.modules.redismod.hscan(key, cursor=0, match=None, count=None, host=None, port=None, db=None, password=None)

  Incrementally iterate hash fields and associated values.

  Added in version 2017.7.0.

  CLI Example:

      salt '*' redis.hscan foo_hash match='field_prefix_*' count=1

salt.modules.redismod.hset(key, field, value, host=None, port=None, db=None, password=None)

  Set the value of a hash field.

  Added in version 2017.7.0.

  CLI Example:

      salt '*' redis.hset foo_hash bar_field bar_value

salt.modules.redismod.hsetnx(key, field, value, host=None, port=None, db=None, password=None)

  Set the value of a hash field only if the field does not exist.

  Added in version 2017.7.0.

  CLI Example:

      salt '*' redis.hsetnx foo_hash bar_field bar_value

salt.modules.redismod.hvals(key, host=None, port=None, db=None, password=None)

  Return all the values in a hash.

  Added in version 2017.7.0.

  CLI Example:

      salt '*' redis.hvals foo_hash bar_field1 bar_value1

salt.modules.redismod.info(host=None, port=None, db=None, password=None)

  Get information and statistics about the server

  CLI Example:

      salt '*' redis.info

salt.modules.redismod.key_type(key, host=None, port=None, db=None, password=None)

  Get redis key type

  CLI Example:

      salt '*' redis.type foo

salt.modules.redismod.keys(pattern='*', host=None, port=None, db=None, password=None)

  Get redis keys, supports glob style patterns

  CLI Example:

      salt '*' redis.keys
      salt '*' redis.keys test*

salt.modules.redismod.lastsave(host=None, port=None, db=None, password=None)

  Get the UNIX time in seconds of the last successful save to disk

  CLI Example:

      salt '*' redis.lastsave

salt.modules.redismod.llen(key, host=None, port=None, db=None, password=None)

  Get the length of a list in Redis

  CLI Example:

      salt '*' redis.llen foo_list

salt.modules.redismod.lrange(key, start, stop, host=None, port=None, db=None, password=None)

  Get a range of values from a list in Redis

  CLI Example:

      salt '*' redis.lrange foo_list 0 10

salt.modules.redismod.ping(host=None, port=None, db=None, password=None)

  Ping the server, returns False on connection errors

  CLI Example:

      salt '*' redis.ping

salt.modules.redismod.save(host=None, port=None, db=None, password=None)

  Synchronously save the dataset to disk

  CLI Example:

      salt '*' redis.save

salt.modules.redismod.sentinel_get_master_ip(master, host=None, port=None, password=None)

  Get ip for sentinel master

  Added in version 2016.3.0.

  CLI Example:

      salt '*' redis.sentinel_get_master_ip 'mymaster'

salt.modules.redismod.set_key(key, value, host=None, port=None, db=None, password=None)

  Set redis key value

  CLI Example:

      salt '*' redis.set_key foo bar

salt.modules.redismod.shutdown(host=None, port=None, db=None, password=None)

  Synchronously save the dataset to disk and then shut down the server

  CLI Example:

      salt '*' redis.shutdown

salt.modules.redismod.slaveof(master_host=None, master_port=None, host=None, port=None, db=None, password=None)

  Make the server a slave of another instance, or promote it as master

  CLI Example:

      # Become slave of redis-n01.example.com:6379
      salt '*' redis.slaveof redis-n01.example.com 6379
      salt '*' redis.slaveof redis-n01.example.com
      # Become master
      salt '*' redis.slaveof

salt.modules.redismod.smembers(key, host=None, port=None, db=None, password=None)

  Get members in a Redis set

  CLI Example:

      salt '*' redis.smembers foo_set

salt.modules.redismod.time(host=None, port=None, db=None, password=None)

  Return the current server UNIX time in seconds

  CLI Example:

      salt '*' redis.time

salt.modules.redismod.zcard(key, host=None, port=None, db=None, password=None)

  Get the length of a sorted set in Redis

  CLI Example:

      salt '*' redis.zcard foo_sorted

salt.modules.redismod.zrange(key, start, stop, host=None, port=None, db=None, password=None)

  Get a range of values from a sorted set in Redis by index

  CLI Example:

      salt '*' redis.zrange foo_sorted 0 10