Introduction to redis
Redis is completely open source and free, complies with the BSD protocol, and is a high-performance key-value database.
Redis and other key-value caching products have the following three characteristics:
- Redis supports data persistence, which can save the data in memory to disk, and can be loaded again for use when restarting.
- Redis not only supports simple key-value type data, but also provides storage of data structures such as list, set, zset, and hash.
- Redis supports data backup, that is, data backup in master-slave mode.
redis installation
The source code installation is more troublesome, so a simple method is used. Under centos, the yum method is directly used to install, and the execution command is as follows:
yum install redis
Start the redis service after success:
service redis start
Check the redis version:
redis-cli --version
Close the redis database command:
service redis stop
Uninstall redis:
yum remove redis
Under Ubuntu, use the apt-get
command to install and uninstall:
Install: apt-get install redis-server
Uninstall:apt-get remove redis-server
All other commands are the same.
Common operations of redis
After the startup is successful, connect to the local redis command line to operate:
redis-cli
The above are the three functions of adding, deleting and checking redis, using the SET, GET and DEL commands of Redis. The data type of the operation is string:
- Set the value of the string object whose key is "name" to "perfect-ssm"
- Get value of string object with key "name"
- set value of string object with key "author" to "13"
- get value of string object with key "author"
- delete string object with key "author"
Redis supports five data types: string string, hash hash, list list, set set and zset (ordered set). If you want to know more about it, you can check the relevant information. The relevant knowledge about redis will not be written too much. Many, after all, it is not a tutorial article of redis, and in the usual project development, basically more string types are needed in the initial stage.
Among the above three commands, GET is to obtain the value of the specified key, which cannot meet the requirements of the search function. The search is usually implemented by using another keyword. KEYS
The command is used to search for keys with matching patterns. The command syntax is:
KEYS PATTERN
Create a few more key-value pairs for testing KEYS:
KEYS *
It is to get a list of all available keys in Redis, and o
the query to get the letters in the keys is keys *o*
, a simple example is as follows:
redis opens remote login
Redis can only be accessed by localhost by default, so you need to enable remote login. The solution is as follows:
- First, check the redis configuration file address:
rpm -ql redis
The configuration file is , you can change /etc/redis.conf
the in this file to. The security method is to bind only a few specific server IPs. - Secondly, the firewall settings, the default port of redis is 6379, so you need to set the permissions on the 6379 port of the server.bind 127.0.0.1
bind 0.0.0.0
After the server completes the above operations, it can be verified, and the rdm client is used to connect and operate locally:
the connection is successful!
View the key in the redis database:
Summarize
The introduction of redis comes to an end here. I hope to give you some help when reading this article. The integration of redis in the project will be sorted out as soon as possible.
First published on my personal blog , the new project demo address: perfect-ssm , login account: admin, password: 123456
If you have any questions or have some good ideas, please leave me a message, and thank you for pointing out that there are problems in the project friend.
If you want to continue to learn about the project, you can view the entire series of articles on Spring+SpringMVC+MyBatis+easyUI integration series , or you can go to my GitHub repository or open source Chinese code repository to view the source code and project documentation.