In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains the concept and building method of Redis. The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn the concept and building method of Redis.
Introduction to Redis
What is Redis?
Redis, whose full name is Remote Dictionary Server, is an open source, high-performance NoSQL database that can be used as a database, cache, and message queue.
What is NoSQL?
The most common explanation of NoSQL is naon-relational, non-relational database, and another saying is Not Only SQL. SQL,NoSQL is not only a concept, but also refers to non-relational database, which is different from relational database. They do not guarantee the ACID characteristics of relational data. ACID is
A (Atomicity) atomicity
C (Consistency) consistency
I (Isolation) independence
D (Durability) persistence
Redis adapts to storage requirements in different scenarios by providing data types of multiple key-value pairs.
The representative of NoSQL
As the representative of NoSQL, there are
MongoDB
Redis
Memcached
Advantages of NoSQL
Compared with relational database model, Redis still has many advantages.
Easy to expand
There are many kinds of NoSQL databases, but a common feature is to remove the relational characteristics of relational databases, and there is no relationship between the data, so it is very easy to expand.
Large amount of data, high performance
NoSQL databases have very high read and write performance, especially in the case of a large amount of data.
Flexible data model
NoSQL does not need to establish fields in advance, which eliminates the disadvantage that once fields are established in a relational database, the scalability is very poor. NoSQL can store custom data formats at any time.
High availability
NoSQL can easily implement a highly available architecture with little impact on performance. For example, Cassandra and HBase models can also achieve high availability by copying models.
Redis data type
There are five main data types supported by Redis, which are
String-strings
String string is the simplest data type in Redis. It is the same type as Memcached. One key corresponds to one value. This way of key/value is called key-value pair. Strings are useful for many examples, such as caching HTML fragments and web pages.
Collection-set
Set is a set, which is similar to the concept of set in our mathematics, such as adding and deleting elements, intersection and difference of multiple sets and so on. The key in the operation is understood as the name of the collection.
Hash-hash
Hash is a collection of key-value pairs (key= > value); it is a mapping table of field and value of type string, and hash is particularly suitable for storing objects.
List-list
The Redis list is a simple list of strings sorted in the order in which they are inserted. You can add an element to the head (left) or tail (right) of the list. The list type is often used for message queuing services to complete message exchange between multiple programs.
Ordered set-zset
Redis zset, like set, is a collection of elements of type string, and duplicate members are not allowed. When you need an ordered and non-repeating list of collections, you can choose sorted set data structures.
Redis installation
Redis supports installation in Linux, OS X, BSD and other POSIX systems, as well as in Windows. For installation under Windows and Linux, please refer to https://www.runoob.com/redis/redis-install.html
My own computer is mac system, and the installation process of mac system is https://www.jianshu.com/p/bb7c19c5fc47.
If you are using Homebrew, its installation process is https://www.jianshu.com/p/e1e5717049e8
Redis start
After installing Redis, we need to start Redis, but before we start Redis, we need to know the executable file of Redis. If you are downloading the tar.gz installation package, you can use make install to compile. After compilation, the following executable files will be generated in the / usr/local/bin directory
Let's take a look at the role of these executable files.
Redis-benchmark is a Redis performance testing tool. You can use redis-benchmark for benchmarking, such as redis-benchmark-Q-n 100000. This tool is very easy to use, and you can use your own benchmarking tool.
Redis-check-rdb RDB file checking tool, rdb is a persistence method of Redis
Redis-check-aof AOF file checking tool, aof is also a persistence method of Redis, which we will talk about later.
Redis-sentinel redis-sentinel is an independent process that monitors multiple master-slave clusters, automatically discovers master outages, and automatically switches slave > master.
Redis-cli,redis-cli and the following redis-server are common and important commands, which are instructions for you to log in to redis.
Redis-server,redis-server is the backend server for redis
Redis startup is divided into two types, one is to run redis-server directly, the other is to start through redis script, the former is generally used in the development environment, script startup is generally used in the production environment, here we directly use the direct startup method.
Run redis-server directly to start redis
You can also run Redis by specifying the port of Redis
Redis-server-port 6380
We won't post the picture here.
Redis stop
Given that Redis may be synchronizing data in memory to the hard disk, forcing the stop command of Redis may result in data loss. The correct way to stop Redis should be to send a SHUTDOWN command to Redis, as follows
Redis-cli SHUTDOWN
You may not know what the redis-cli command is here, which we'll talk about next.
When Redis receives the SHUTDOWN instruction, it first disconnects all client connections, then persists according to the configuration, and finally completes the exit.
You can also use the kill Redis port to end the Redis normally, which is the same as the SHUTDOWN command.
Redis command line client
Let's talk about redis-cli instructions. Redis-cli and redis-server are both very important tools in Redis. You must know that redis-cli, whose full name is Redis Command Line Interface, is a command-line tool that comes with Redis. It has the following main uses
Send a command
There are two ways to send a command to Redis through redis-cli. One is to execute the command as a parameter of redis-cli. For example, in the above redis-cli SHUTDOWN command, redis-cli will connect according to the default host and port number, which is 127.0.0.1 and 6379 to connect to Redis, respectively.
You can also customize the address and port number through the-h and-p parameters
Redis-cli-h 127.0.0.1-p 6379
Redis provides a PING command to test whether the client's connection to Redis is normal, and if so, it will reply to the PONG response, as follows
Redis-cli PING
Command return value
In most cases, we want to get the return value of a command after executing a command. In Redis, there are mainly five types of command return values of Redis. The display results of each type of redis-cli are different, which are described below.
Status reply
A status reply (status reply) is the simplest reply. For example, when you send a SET command to Redis to set the value of a key, Redis will reply to OK to indicate that the setting is successful. The PING and PONG we mentioned above are also a status reply. The status reply displays the status information directly.
Error reply
Error reply (error reply) means that when a command does not exist or there is an error in the command, an error reply occurs, followed by an error message. Like executing an instruction that doesn't exist.
Integer reply
Although Redis does not have an integer type, it does provide some instructions for integer operations, such as the INCR command that increments the key value to return the incremented key value as an integer. In addition, some other commands also return integers. Integer replies (integer reply) start with integer and then follow the integer data
String reply
String reply (bulk reply) is the most common type of reply, and you get a string reply when you request the key value of a key of a string type or an element in a key of another type. String reply wrapped in double quotation marks
In another case, nli is returned when the key value of the request does not exist, indicating that an empty result is returned.
Multiline string reply
Multiline string replies (multi-bulk reply) are also common, such as receiving multiline string replies when you request a list of elements of a key that is not a string type.
Redis configuration
Redis can support custom configuration, such as whether to enable persistence, configure log level, and so on. Because there are so many options that can be configured, it is not reasonable to configure them through startup, so they can be configured manually by the programmer. The way to enable the configuration file is to pass the path of the configuration file to redis-server as a startup parameter at startup, as follows
Redis-server / path / redis.conf
Passing the configuration option with the same name through the parameter overrides the corresponding parameter in the configuration file, as follows
Redis-server / path / redis.conf-- loglevel warning
Redis provides a template of configuration files, redis.conf,Redis, and supports dynamic configuration modification. You can use the CONFIG SET command to dynamically modify Redis without re-Redis.
CONFIG SET loglevel warning
Redis multi-database switching
Redis is a dictionary-structured storage server. In fact, a Redis instance provides multiple dictionaries for storing data, and the client can specify which dictionary to store the data in.
Each database is externally named with an incremental number starting at 0, and Redis supports 16 databases by default, which can be modified by configuring databases. Database 0 is selected by default after the client establishes a connection with Redis, but the database can be switched using the select command.
Select 1
This instruction will select database 1.
Thank you for your reading, the above is the content of "the concept and building method of Redis". After the study of this article, I believe you have a deeper understanding of the concept and building method of Redis, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.