about Redis
Redis serves as a cache server for hotspot data, as well as a variety of scenarios such as support queues and publish/subscribe, which are commonly used in many projects. The following descriptions can be found on the Redis official website Redis.io:
Redis is an open source (BSD licensed), IN-MEMORY data structure store, used as a database, cache and message broker. IT supports data structures such as strings,
Hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries. Redis has built-in replication, Lua scripting, LRU eviction,
Transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic Partitioning with Redis Cluster.
Redis is an open source, BSD licensed, Advanced Key-value storage System. can be used to store strings, hash structures, linked lists, and collections, so it is commonly used to provide data structure services.
Redis Installation
The latest stable version of the current Redis is redis-4.0.1, and can also be downloaded to the official website Redis.io.
1. Unzip and enter the directory redis-4.0.1
[Root@centos-server-yzr ~]# Tar-xvzf redis-4.0.1.tar.gz
2. Do not configure, compile make
[Root@centos-server-yzr redis-4.0.1]# make
3. Optional action make test
4. Install to the specified directory, such as/usr/local/redis
[Root@centos-server-yzr redis-4.0.1]# cd/usr/local
[Root@centos-server-yzr local]# mkdir Redis
Re-enter redis-4.0.1 for make install
[Root@centos-server-yzr redis-4.0.1]# make Prefix=/usr/local/redis Install
Error occurred during execution:/bin/sh:cc:command not found
Install CC command: [root@centos-server-yzr redis-4.0.1]# yum Install gcc
Make the Install again
You can see the following files at this point in the specified installation directory/usr/local/bin:
5. Replicating Redis configuration Files redis.conf
The downloaded source file contains a copy of the redis.conf, which copies this profile to the specified directory we just installed: CP Redis.conf/usr/local/redis
6. Start and test
You can now run the Redis service process:./bin/redis-server./redis.conf
Open another connection and use REDIS-CLI to connect to the service process:
If you want to close the Redis service process, you can simply press CTRL + C or close the terminal. The Redis client executes the QUIT command to exit.
7. The Redis service process is running as a terminal, which causes the Redis service process to shut down if the terminal is turned off, so we set up Redis to run as a background service process
Stop the Redis service process, modify the redis.conf configuration file, by default, the Daemonize property value is no, here to let Redis run as a background service process, change the Daemonize property to Yes:
Then reboot the boot.
Redis, which is run by the next service process, prints the following message:
The Redis service is in daemonize Yes, and if you want to turn it off, use the following command from the client: (the local Redis service process is turned off)
[Root@centos-server-yzr redis]#./bin/redis-cli-p 6379 shutdown
Redis Common common key usage
redis Command Description document Link: http://redisdoc.com/
1. View all keys under the current database
Command: Thekeys pattern has 3 wildcard characters *,? ,[]
*: Pass with any number of characters?: Wildcard single character []: 1 characters in parentheses
2. A key is randomly returned at the current database
Command:randomkey
3. Query the current database under key exists
Command:exists key exists return 1, otherwise returns 0
4. Query the type of value stored by the specified key
Command:type key has String,link,set,order set, hash, etc.
Returns none when key does not exist
5. Delete key multiple keys are separated by a space
Command:del key1 key2... Successful deletion of the existing key returns 1, otherwise returns 0
6. Rename Key
Command:rename key Newkey when the renamed Newkey name already exists, it will overwrite the previous key
If key does not exist, it will error (error) ERR no such key
7. Rename Key
Command:renamenx key Newkey
Rename successfully returns 1, otherwise returns 0
8. Replace Database
Command:Select database serial number
The Database property under the Redis.config configuration file has a value of 16, a redis process that opens more than one, opens 16 databases by default, numbers from 0 to 15, and selects to switch Redis's database.
9. Move the key to the specified database
Command:move key DB
10. Querying the life cycle of a key
Command:TTL key Returns a number of seconds
Returns 2 when key is not present, returns 1 when key is permanently active, otherwise returns the number of valid seconds remaining
11. Set the life cycle of the key
Command:expire key S s refers to the number of seconds
· 12. Queries in milliseconds and set lifecycle commands
Similarly:
pexpire key milliseconds, setting life cycle
Pttl Key, returns the life cycle in milliseconds
13. Set key to be permanently active
Command:persist key