Saltstack using the Redis module for source code analysis

Source: Internet
Author: User
Tags redis cli redis server saltstack

Redis Module Path

/usr/lib/python2.6/site-packages/salt/modules/redismod.py

The Redis module first checks if a redis-powered Python driver is installed

# -*- coding: utf-8 -*-"Module to  Provide redis functionality to salt.  versionadded:: 2014.7.0:configuration: this module requires the redis  python module and uses the    following defaults which  may be overridden in the minion configuration:..  code-block:: yaml    redis.host:  ' localhost '      Redis.port: 6379    redis.db: 0    redis.password: none "' # import third party libstry:    import redis     HAS_REDIS = Trueexcept ImportError:    HAS_REDIS =  false__virtualname__ =  ' Redis ' 
Def __virtual__ (): ' Only load this module if Redis Python module is installed ' if Has_redis:retu RN __virtualname__ Else:return False

Redis Module name Redis that only returns Saltstack if Redis's Python driver is installed

def _connect (host=none, port=none, db=none,  Password=none):     "    Returns an instance of  the redis client     '     if not host:         host = __salt__[' config.option ' (' redis.host ')      if not port:        port = __salt__[' Config.option '] (' redis.port ')     if not db:         db = __salt__[' config.option ' (' redis.db ')     if not  password:        password = __salt__[' config.option '] (' Redis.password ')     return redis. Strictredis (Host, port, db, password) 

If you do not specify the IP of the Redis instance, the port and DB names and the password go to read the configuration file. Redis's Python drive is used here to connect



def bgrewriteaof (Host=none, Port=none, Db=none, Password=none): "Asynchronously rewrite the append-only file C LI Example:.. Code-block:: Bash Salt ' * ' redis.bgrewriteaof ' server = _connect (host, port, DB, password) return serve R.bgrewriteaof ()

Asynchronously rewrite the aof file


Test

$ sudo salt ' jialebi-qa-server ' redis.bgrewriteaof 127.0.0.1 6379 0 jialebi-qa-server:true
def bgsave (Host=none, Port=none, Db=none, Password=none): "Asynchronously Save the dataset to disk CLI Example :    .. Code-block:: Bash Salt ' * ' redis.bgsave ' server = _connect (host, port, DB, password) return Server.bgsa VE ()

Asynchronously saves data to disk

Test:

$ sudo salt ' jialebi-qa-server ' redis.bgsave 127.0.0.1 6379 0 jialebi-qa-server:true
def config_get (pattern= ' * ', Host=none, Port=none, Db=none, Password=none): ' Get Redis Server configuration values CLI Example:..  Code-block:: Bash Salt ' * ' redis.config_get salt ' * ' redis.config_get port ' server = _connect (host, Port, DB, password) return Server.config_get (pattern)

Get configuration information


Test:

$ sudo salt  ' jialebi-qa-server '  redis.config_get  ' * '  127.0.0.1 6379 0  jialebi-qa-server:    ----------    activerehashing:         yes    appendfsync:         everysec    appendonly:         no    auto-aof-rewrite-min-size:        67108864     auto-aof-rewrite-percentage:        100     bind:        127.0.0.1     client-output-buffer-limit:        normal 0 0 0  slave 268435456 67108864 60 pubsub 33554432 8388608 60     daemonize:        yes    databases:         16    dbfilename:        dump.rdb     dir:        /data/app_data/redis/data     hash-max-ziplist-entries:        512     hash-max-ziplist-value:        64     list-max-ziplist-entries:        512     List-max-ziplist-value:        64    logfile:         /data/app_data/redis/logs/redis.log     loglevel:        notice    lua-time-limit:         5000    masterauth:             maxclients:        10000    maxmemory:         0    maxmemory-policy:         volatile-lru    maxmemory-samples:         3    no-appendfsync-on-rewrite:         no    pidfile:        /var/run/redis.pid     port:        6379     rdbchecksum:        yes    rdbcompression:         yes    repl-ping-slave-period:         10    repl-timeout:        60     requirepass:            save:         900 1 300 10 60 10000     set-max-intset-entries:        512     Slave-priority:        100    slave-read-only:         yes    slave-serve-stale-data:         yes    slaveof:             slowlog-log-slower-than:         10000    slowlog-max-len:        128     stop-writes-on-bgsave-error:        yes    timeout:         0    unixsocket:             unixsocketperm:        0     watchdog-period:        0     zset-max-ziplist-entries:        128     Zset-max-ziplist-value:        64
$ sudo salt ' jialebi-qa-server ' redis.config_get ' maxmemory ' 127.0.0.1 6379 0 jialebi-qa-server:----------maxmemor y:0
def config_set (name, value, Host=none, Port=none, Db=none, Password=none): "Set Redis server configuration values CLI Example:.. Code-block:: Bash Salt ' * ' redis.config_set masterauth luv_kittens ' server = _connect (host, port, DB, pass Word) return Server.config_set (name, value)

Set the value of a parameter


Test

$ sudo salt ' jialebi-qa-server ' redis.config_set ' maxmemory ' 300000000 127.0.0.1 6379 0 jialebi-qa-server:true
def dbsize (Host=none, Port=none, Db=none, Password=none): "Return the number of the keys in the selected database CLI Example:.. Code-block:: Bash Salt ' * ' redis.dbsize ' server = _connect (host, port, DB, password) return SERVER.DBSI Ze ()

Returns the number of keys for the selected library

Test:

$ sudo salt  ' Jialebi-qa-server '  redis.dbsize  127.0.0.1 6379 3jialebi-qa-server:    12502 
Def delete (*keys, **connection_args):     "    deletes  the keys from redis, returns number of keys deleted     CLI EXAMPLE:   &NBSP, ....  code-block:: bash        salt  ' * '  redis.delete  foo     '     # get connection args from  keywords if set    conn_args = {}    for  arg in [' host ',  ' Port ',  ' db ',  ' password ']:         if arg in connection_args:             conn_args[arg] = connection_args[arg]    server = _ Connect (**conn_args)     return server.delete (*keys)

Delete a key

def exists (key, Host=none, Port=none, Db=none, Password=none): "' Return true if the key exists in Redis CLI Exa Mple:.. Code-block:: Bash Salt ' * ' redis.exists foo ' "Server = _connect (host, port, DB, password) return server. Exists (key)

Check if a key exists


Test

$ sudo salt ' jialebi-qa-server ' redis.exists foo 127.0.0.1 6379 0jialebi-qa-server:true




This article is from the Linux SA John blog, so be sure to keep this source http://john88wang.blog.51cto.com/2165294/1628981

Saltstack using the Redis module for source code analysis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.