Article Directory
Title 1: Introduction to redis
-
Redis is a kind of database. A software that can store data and manage data.
-
The development process of database applications:
stand-alone database era: one application, one database instance.
Era of caching and horizontal segmentation: Era of
separation of reads and writes : Era
of database and table (cluster):
Relational database:
Non-relational database (NoSql): Completely change the underlying storage mechanism and no longer adopt relational data model, but adopt aggregate data Structure storage data
3. Redis is a high-performance NoSQL database written in C language, open source, memory-based running and supporting persistence, and it is also one of the current popular NoSQL databases
. The data in Redis is available most of the time It is in the storage memory, suitable for storing frequently accessed and relatively small data.
Cache database -
Redis features:
1: Supports data persistence, can keep the data in the memory in the disk and can be loaded again for use when restarting
2: Supports multiple data structures, redis not only supports simple key-value type data, At the same time, it also provides storage of data structures such as list, set, zset, hash, etc.
3: Support data backup, redis supports data backup in master-slave mode
Title 2: Redis use
1: Start redis service:
1) Foreground startup: execute in any directory: redis-server (rarely used)
2) Background startup: execute in any directory: redis-service&
3) When starting redis service, specify the configuration file: redis-server redis.conf &
2: Turn off the service
1) Through the kill command: it is more violent and data is easy to lose.
kill -9 pid (pid is his process, the first number after root, and the second number is the secondary thread)
2) Shut down through the redis-cli command (recommended)
redis-cli shutdown
3: Redis client: used to connect to the redis service, send commands to the redis server, and display the processing results of the redis service.
redis-cli: It is the client that comes with redis. Use the command redis-cli to start the redis client program.
redis-cli: The default connection to the redis service on port 6379 of 127.0.0.1 (local)
redis-cli -p port number: the connection to the redis service on the designated port of 127.00.1 (local)
redis-cli -h ip address -p port: connect to the redis service of the specified port on the specified ip host
4: exit the client: execute the command on the client: exit or quit
Title 3: Basic knowledge of redis
1) Test redis-benchmark to see how fast your request is completed
2) Check whether the redis service is in normal use (check back to PONG means it runs successfully)
3) Check the statistics of the redis server: info
info [information section] specified by the redis server Statistical information such as: info Replication
4) Redis database instance: the role is similar to the mysql database instance. The redis database instance
can only be created and maintained by the redis service. Developers cannot modify and create the database instance by themselves. By default, redis will Automatically create 16 database instances, and number these database instances, starting from 0 to 15, using the database by numbering: you can specify the number of databases automatically created by redis through the configuration file; each database instance of redis occupies itself The storage space is very small, so it does not cause too much waste of storage space.
By default, the redis client connects to the database instance numbered 0.
5) View the number of all keys in the current database instance: dbsize
6) View All the keys in the current database example: keys *
7) Clear the database instance: flushdb
8) Clear all the database instances: flushall
9) View the configuration information in redis: config get *
View the configuration information specified in redis: config get parameter