Redis is a high-performance key-value database. Its key has a wide range of data structures: string, hash, list set, and sorted set. Compared with memcache, NOSQL not only has a rich key data structure, but also has persistence functions. It also supports master-slave replication, making it easy to build clusters.
Redis's high performance is largely derived from its memory-type database, which features a set operation of 11 w/s and a get operation of 8.1 w/s. to further deepen the understanding of redis, I plan to write an article in The redis series. Here we will talk about the installation, deployment, and O & M of redis.
1. Download and install
[Root @ www.bkjia.com] # wget-c http://redis.googlecode.com/files/redis-2.4.17.tar.gz # download
[Root @ www.bkjia.com] # tar-zxvf redis-2.4.17.tar.gz # unzip
[Root @ www.bkjia.com] # cd redis-2.4.17
[Root @ www.bkjia.com redis-2.4.17] # make # compile
[Root @ www.bkjia.com redis-2.4.17] # make install # install
After installation, common tools are automatically copied to the/user/loca/bin directory. As a server, we often need to set redis to start automatically when it is turned on. The source code package contains a very useful script, which can be entered as prompted.
[Root @ www.bkjia.com redis-2.4.17] # cd utils/
[Root @ www.bkjia.com utils] #./install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379. conf]
Selected default-/etc/redis/6379. conf
Please select the redis log file name [/var/log/redis_62.16.log]
Selected default-/var/log/redis_62.16.log
Please select the data directory for this instance [/var/lib/apsaradb for redis/6379]
Selected default-/var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
Copied/tmp/6379. conf =>/etc/init. d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully addedto runlevels 345!
Starting Redis server...
Installation successful!
Note: To Run install_server.sh, you must first enter the utils directory. Otherwise, the script reports an error and the corresponding file cannot be found. After the service is installed, redis starts automatically. You can use the ps command to view the relevant information:
[Root @ www.bkjia.com utils] # ps-ef | grep redis
Root 4554 1 0 :55? 00:00:02/usr/local/bin/redis-server/etc/redis/6379. conf
Root 4564 2808 0 00:00:00 pts/0 grep redis
2. manually start and close the service
[Root @ www.bkjia.com utils] #/etc/init. d/redis_6379 stop # Close
[Root @ www.bkjia.com utils] #/etc/init. d/redis_6379 start # start
3. Use the client command line tool to connect to the redis service to view redis Information
A) Connection
[Root @ www.bkjia.com utils] # redis-cli
Redis 127.0.0.1: 6379>
B) Other commands
Redis 127.0.0.1: 6379> info # view server version memory usage connections and other information
Redis 127.0.0.1: 6379> client list # obtain the client connection list
Redis 127.0.0.1: 6379> client kill 127.0.0.1: 33441 # terminate a client connection
Redis 127.0.0.1: 6379> dbsize # number of keys currently saved
Redis 127.0.0.1: 6379> save # save data to the hard disk immediately
Redis 127.0.0.1: 6379> bgsave # asynchronously save data to the hard disk
Redis 127.0.0.1: 6379> flushdb # Remove all keys from the current database
Redis 127.0.0.1: 6379> flushall # Remove all keys from all databases
Redis 127.0.0.1: 6379> lastsave # obtain the unix timestamp successfully saved to the hard disk
Redis 127.0.0.1: 6379> monitor # requests received by the Real-time Monitoring Server
Redis 127.0.0.1: 6379> slowlog len # query the number of slow query logs
(Integer) 3
Redis 127.0.0.1: 6379> slowlog get # returns all slow query logs. The maximum value depends on the slowlog-max-len configuration.
Redis 127.0.0.1: 6379> slowlog get 2 # print two slow query logs
Redis 127.0.0.1: 6379> slowlog reset # Clear slow query log information
Through the above operations, a single server is basically running, but the subsequent path is still very long.