Redis of common operations

Redis of common operations

1. redis client login

  1. Local use redis client login

    redis-cli
  2. Use client login on the remote server

    # 格式
    redis-cli -h host -p port -a password

2. Set password

  1. Configure the password in the configuration file (even restart the service can be effective)

    # 编辑redis的配置文件 redis.conf
    requirepass ${密码}
    
    # 重启redis服务,在redis服务中执行:
    shutdown
    
    # 登录时,使用密码:
    redis-cli -p 6379 -a ${密码}
    
    # 登录后,使用密码:
    redis-cli -p 6379
    
    redis 127.0.0.1:6379> auth ${密码}
    OK
  2. Set in memory (redis after the restart, password expiration)

    redis 127.0.0.1:6379> config set requirepass ${密码}
    
    # 查询密码:
    redis 127.0.0.1:6379> config get requirepass
    (error) ERR operation not permitted
    
    # 密码验证:
    redis 127.0.0.1:6379> auth test123
    OK
    
    # 再次查询
    redis 127.0.0.1:6379> config get requirepass
    1) "requirepass"
    2) "test123"

3. Get redis configuration

  1. Get all of the configuration redis

    CONFIG GET *
  2. Configuration changes reids

    127.0.0.1:6379> CONFIG GET loglevel
    1) "loglevel"
    2) "notice"
    
    # 更改
    127.0.0.1:6379> CONFIG GET loglevel
    1) "loglevel"
    2) "notice"
    127.0.0.1:6379> CONFIG SET loglevel "notice"
    OK
    127.0.0.1:6379> CONFIG GET loglevel
    1) "loglevel"
    2) "notice"

4. redis键(key)

Key redis redis key commands for managing the

grammar

The basic syntax redis key command is as follows:

redis 127.0.0.1:6379> COMMAND KEY_NAME

Examples

127.0.0.1:6379> set name "hello world"
OK
127.0.0.1:6379> get name
"hello world"
127.0.0.1:6379> del name
(integer) 1
127.0.0.1:6379> get name
(nil)

In the above example is a command del, name is a bond. If the key is deleted successfully, after executing the command output (integer) 1, otherwise the output (integer) 0

Redis keys (yellow focus)

command description
==del key== This command deletes the user key in the key presence
dump key Serialization the existence of a given key
==exists key== Check whether there is a given key
==expire key seconds== For a given setting key expiration time, in seconds stage
==expireat key timestamp== Expireat similar effect and expire, are used to set the expiration time for the key. Unlike expireat time parameters are accepted command unix timestamp
pexpire key milliseconds Key expiration time setting in milliseconds
pexpire key milliseconds-timestamp Key expiration timestamps provided, in milliseconds
==keys pattern== Find all match a given pattern key, such as keys a *
move key db Key to move the current database to which a given database db
==persist key== Removes the key expiration time, key will endure
pttl key Milliseconds returns the remaining expiration time of the key.
==rename key newkey== Modify the name of the key
renamenx key newkey Only when newkey does not exist, the key renamed newkey
type key Returns the type of the stored key value
randomkey It returns a random key from the current database

More commands, refer to: https://redis.io/commands

Guess you like

Origin www.cnblogs.com/plf-Jack/p/11025109.html