Common Command Description
Redis server: redis-server
Redis client: redis-cli
Redis performance testing tool: redis-benchmark
AOF File Repair Tool: redis-check-aof
RDB File Repair Tool: redis-check-rd
redis sets temporary password: config set requirepass password
redis gets the temporary password: config get requirepass
start and stopping
Server Start
-
Default startup
As mentioned above, the redis server is started at the command redis-server. And accept client connection - Start according to settings
- Create bin, etc, db directories under / usr/local/redis
- Copy mkreleasehdr.sh, redis-benchmark, redis-check-rdb, redis-cli, redis-server in the / usr/local/redis/src directory to the bin directory
- Under etc, a new configuration redis.conf is created, which reads as follows.
- / New log file log-redis.log under usr/local/redis and modify current user permissions. Sudo chown-R shoren/usr/local/redis/
-
Start the server: redis-server/usr/local/redis/etc/redis.conf
#Modified to daemon mode daemonize yes #Setting Process Lock File pidfile /usr/local/redis/redis.pid #port port 6379 #Client timeout timeout 300 #log level loglevel debug #Location of log files logfile /usr/local/redis/log-redis.log #Set the number of databases, default database is 16, you can use the SELECT command to specify the database id on the connection databases 16 ##Specifies how many update operations there are in the long run, synchronizing the data to the data file. #save #The Redis default configuration file provides three conditions: save 900 1 save 300 10 save 60 10000 #Specifies whether to compress data when stored in a local database, by default yes, Redis uses LZF compression, if in order to save CPU time, #This can be turned off#Options, but can cause database files to become huge rdbcompression yes #Specify the local database file name dbfilename dump.rdb #Specify the local database path dir /usr/local/redis/db/ #Specifies whether to log after each update operation. Redis, by default, writes data asynchronously to disk. If not turned on, it may #It can cause data loss for a period of time when the power is off. Because redis itself synchronizes data files according to the save condition above, there are #Data will only exist in memory for a period of time. appendonly no #There are three optional values for specifying update log conditions: #no: indicates that the operating system will synchronize data cache to disk (fast). #always: Represents a manual call to fsync() after each update operation to write data to disk (slow, secure) #everysec: Represents synchronization once a second (compromise, default) appendfsync everysec
Next, you can view the log as follows to indicate that the startup was successful:
_._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 3.2.5 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 14447 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 14447:M 24 Apr 17:57:33.215 # Server started, Redis version 3.2.5 14447:M 24 Apr 17:57:33.215 * The server is now ready to accept connections on port 6379 14447:M 24 Apr 17:57:33.215 - 0 clients connected (0 slaves), 956832 bytes in use 14447:M 24 Apr 17:57:38.257 - 0 clients connected (0 slaves), 956832 bytes in use
Close the server
- force close
Forced termination of redis process may result in data loss, because redis may be synchronizing memory data to hard disk.
ps axu|grep redis ## Find the PID of redis-server kill -9 PID
- Command close
Send SHUTDOWN command to redis, namely redis-cli SHUTDOWN. When Redis receives the command, the server disconnects all clients, persists according to configuration, and finally exits.
## Start redis-server, background thread AT8775:redis shoren$ redis-server /usr/local/redis/etc/redis.conf ## Startup success AT8775:redis shoren$ ps axu|grep redis shoren 14948 0.0 0.0 2434840 760 s000 S+ 10:18 0 a.m.:00.00 grep redis shoren 14946 0.0 0.0 2452968 1492 ?? Ss 10:18 0 a.m.:00.01 redis-server *:6379 ## Close the server AT8775:redis shoren$ redis-cli shutdown ##Shut down successfully AT8775:redis shoren$ ps axu|grep redis shoren 14952 0.0 0.0 2435864 772 s000 S+ 10:19 0 a.m.:00.01 grep redis
Start the client
-
Default startup
Start the client with the command redis-cli and connect Redis (127.0.0.1:6379) according to the default configuration. -
Specify address and port number
Use the command redis-cli-h 127.0.0.1-p 6379
Close the client
Interactive mode uses quit
AT8775:redis shoren$ redis-cli -h 127.0.0.1 -p 6379 ## Simple use of set and get commands 127.0.0.1:6379> set key value12 OK 127.0.0.1:6379> get key "value12" ## Sign out 127.0.0.1:6379> quit AT8775:redis shoren$