Detail the Redis command and key _ power node Java college collation
- 2020-06-01 11:17:00
- OfStack
The Redis command is used to perform certain operations on the redis server.
To run a command on an Redis server, you need an Redis client. The Redis client is in the Redis package, which we have already installed and used before.
grammar
The basic syntax of Redis client is as follows:
$redis-cli
example
The following example shows how to use the Redis client.
To start the redis client, open the terminal and enter the command Redis command line: redis-cli. This will connect to the local server and you can now run the various commands.
$redis-cli
redis 127.0.0.1:6379>
redis 127.0.0.1:6379> PING
PONG
In the above example, we connect to the Redis server running on the local machine and execute the ping command to check if the server is running.
Run the command on the remote server
To run the command on the Redis remote server, you need to connect to the server via the same client, redis-cli
grammar
$ redis-cli -h host -p port -a password
For example,
The following example demonstrates how to connect to a remote server on Redis host: 127.0.0.1, port: 6379, and add the authentication password: mypass.
$redis-cli -h 127.0.0.1 -p 6379 -a "mypass"
redis 127.0.0.1:6379>
redis 127.0.0.1:6379> PING
PONG
The keys command of Redis is used to manage keys. The keys command syntax using Redis is as follows:
grammar
redis 127.0.0.1:6379> COMMAND KEY_NAME
example
redis 127.0.0.1:6379> SET yiibai redis
OK
redis 127.0.0.1:6379> DEL yiibai
(integer) 1
In the example above, DEL is the command and yiibai is the key. If the key is deleted then the output command will be (integer) 1, otherwise it will be (integer) 0
Key command for Redis
The following table shows the basic commands for the keys:
S.N.
|
命令 & 描述
|
1
|
DEL key
此命令删除键,如果存在 |
2
|
DUMP key
该命令返回存储在指定键的值的序列化版本。 |
3
|
EXISTS key
此命令检查该键是否存在。 |
4
|
EXPIRE key seconds
指定键的过期时间 |
5
|
EXPIREAT key timestamp
指定的键过期时间。在这里,时间是在Unix时间戳格式 |
6
|
PEXPIRE key milliseconds
设置键以毫秒为单位到期 |
7
|
PEXPIREAT key milliseconds-timestamp
设置键在Unix时间戳指定为毫秒到期 |
8
|
KEYS pattern
查找与指定模式匹配的所有键 |
9
|
MOVE key db
移动键到另1个数据库 |
10
|
PERSIST key
移除过期的键 |
11
|
PTTL key
以毫秒为单位获取剩余时间的到期键。 |
12
|
TTL key
获取键到期的剩余时间。 |
13
|
RANDOMKEY
从Redis返回随机键 |
14
|
RENAME key newkey
更改键的名称 |
15
|
RENAMENX key newkey
重命名键,如果新的键不存在 |
16
|
TYPE key
返回存储在键的数据类型的值。 |
string
grammar
redis 127.0.0.1:6379> COMMAND KEY_NAME
example
redis 127.0.0.1:6379> SET yiibai redis
OK
redis 127.0.0.1:6379> GET yiibai
"redis"
In the example above, set and get are commands, while yiibai is the key.
Redis string command
The following table shows some basic commands for managing strings at Redis:
S.N.
|
命令 & 描述
|
1
|
SET key value
此命令用于在指定键设置值 |
2
|
GET key
键对应的值。 |
3
|
GETRANGE key start end
得到字符串的子字符串存放在1个键 |
4
|
GETSET key value
设置键的字符串值,并返回旧值 |
5
|
GETBIT key offset
返回存储在键位值的字符串值的偏移 |
6
|
MGET key1 [key2..]
得到所有的给定键的值 |
7
|
SETBIT key offset value
设置或清除该位在存储在键的字符串值偏移 |
8
|
SETEX key seconds value
键到期时设置值 |
9
|
SETNX key value
设置键的值,只有当该键不存在 |
10
|
SETRANGE key offset value
覆盖字符串的1部分从指定键的偏移 |
11
|
STRLEN key
得到存储在键的值的长度 |
12
|
MSET key value [key value ...]
设置多个键和多个值 |
13
|
MSETNX key value [key value ...]
设置多个键多个值,只有在当没有按键的存在时 |
14
|
PSETEX key milliseconds value
设置键的毫秒值和到期时间 |
15
|
INCR key
增加键的整数值1次 |
16
|
INCRBY key increment
由给定的数量递增键的整数值 |
17
|
INCRBYFLOAT key increment
由给定的数量递增键的浮点值 |
18
|
DECR key
递减键1次的整数值 |
19
|
DECRBY key decrement
由给定数目递减键的整数值 |
20
|
APPEND key value
追加值到1个键 |
conclusion