Redis provides a rich command to manipulate databases and various data types, which can be used on Linux endpoints. In programming, such as various language packs, these commands have a corresponding method. The following is a summary of the commands provided by Redis.
Related articles:
redis Common Command Manual: key-Value related commands
1. Ping
To test whether the connection survives:
Redis127.0.0.1:6379> Ping
PONG
Before executing the following command, we stop the Redis server
Redis 127.0.0.1:6379> Ping
Could not connect to Redis at 127.0.0.1:6379:connection refused
Before executing the following command, we start the Redis server
Not connected> Ping
PONG
Redis 127.0.0.1:6379>
The first ping indicates that the connection is normal;
Before the second ping, we stopped the Redis server, then the ping was unsuccessful;
Before the third Ping, we started the Redis server, and the ping was successful.
2. Echo
Print some content at the command line:
Redis127.0.0.1:6379> Echo Hongwan
"Hongwan"
Redis 127.0.0.1:6379>
3. Select
Select the database. Redis database number from 0~15, we can select any database to access the data.
Redis127.0.0.1:6379> Select 1
Ok
Redis 127.0.0.1:6379[1]> Select 16
(Error) ERR Invalid DB Index
Redis 127.0.0.1:6379[16]>
When selecting 16 o'clock, an error indicates that there is no database numbered 16.
4. Quit
Exits the connection.
Redis127.0.0.1:6379> quit
[Email protected] redis-2.2.12]#
5, Dbsize
Returns the number of keys in the current database.
Redis127.0.0.1:6379> dbsize
(integer) 18
Redis 127.0.0.1:6379>
The results show that there are 18 keys in this library.
6. Info
Gets the information and statistics of the server.
Redis127.0.0.1:6379> Info
redis_version:2.2.12
redis_git_sha1:00000000
redis_git_dirty:0
Arch_bits:32
Multiplexing_api:epoll
process_id:28480
uptime_in_seconds:2515
uptime_in_days:0
.
.
.
Redis 127.0.0.1:6379>
This result is used to describe the underlying information for the server, including version, startup time, and so on.
7. Monitor
A real-time dump of the received request.
Redis127.0.0.1:6379> config get dir
1) "dir"
2) "/root/4setup/redis-2.2.12"
Redis 127.0.0.1:6379>
As you can see from the results, this server currently accepts the command "keys *" and "get Addr".
8. config get
Gets the server configuration information.
Redis127.0.0.1:6379> config get dir
1) "dir"
2) "/root/4setup/redis-2.2.12"
Redis 127.0.0.1:6379>
In this example, we get the value of the dir parameter configuration, and if you want to get the configuration value of all the parameter data is also very simple, just execute "config get *" To display all the values.
9, Flushdb
Deletes all keys in the currently selected database.
Redis127.0.0.1:6379> Dbsize
(integer) 18
Redis 127.0.0.1:6379> flushdb
Ok
Redis 127.0.0.1:6379> dbsize
(integer) 0
Redis 127.0.0.1:6379>
In this example, we have cleared the key in database No. 0.
10, Flushall
Delete all the keys in all databases.
Redis 127.0.0.1:6379[1]> Dbsize
(integer) 1
Redis 127.0.0.1:6379[1]> select 0
OK
Redis 127.0.0.1:6379> flushall
OK
Redis 127.0.0.1:6379> select 1
OK
Redis 127.0.0.1:6379[1]>< Span class= "Apple-converted-space" > dbsize
(integer) 0
Redis&NBSP;127.0.0.1:6379[1]>
In this example we first looked at a key in database 1th, and then I switched to library No. 0 to execute the flushall command, and the key in library 1th was cleared, saying that the command worked properly.
Redis Common Command Manual: server-related commands