Redis learning-redis introduction overview and introduction

What is it

Redis: REmote DIctionary Server (remote dictionary server) is completely open source and free. It is written in C language and complies with the BSD protocol. It is a high-performance (key/value) distributed memory database that runs on memory and supports persistent NoSQL. The database is currently one of the most popular NoSql databases, and is also called a data structure server.

Redis and other key-value caching products have the following three characteristics:
  Persistence: Redis supports data persistence, which can keep the data in the memory in the disk, and can be loaded again when restarting (it will be gone after shutdown)
  KV: Redis not only supports simple key-value data, but also provides storage
  Cache for list, set, zset, hash and other data structures : Redis supports data backup, that is, data backup in master-slave mode

KV+Cache+Persistence

What can you do

Memory storage and persistence: Redis supports asynchronously writing data in memory to the hard disk without affecting the continued service
. The operation of fetching the latest N data, such as: the ID of the latest 10 comments can be placed in the Redis List collection
Simulation is similar to the function of HttpSession, which needs to set the expiration time.
Publish and subscribe message system.
Timer, counter

Where to go

Redis official website
Redis Chinese website

How to play

Data type, basic operation and configuration
Persistence and replication, RDB/AOF
transaction control
replication (master-slave relationship)

HelloWorld

Remarks: /usr/ This is a very important directory. Many user applications are placed in this directory, similar to the programfiles directory under windows

Enter the home directory of redis.
Enter redis-server to start the redis server.
Enter redis-cli to start the redis client.
Determine whether redis has started successfully, enter ping, and reply pong.
Enter set k1 hello to
Insert picture description here
close the redis process. Use shutdown to
kill it. Use sudo /etc/init .d/redis-server stop

Miscellaneous basic knowledge after startup

Redis is a distributed memory database, very fast.
According to the requirements of the official website, write 80,000 and read 110,000 times.
Redis is a single process to handle client requests. The response to events such as reading and writing is done by wrapping my Epoll function. The actual processing speed of redis depends entirely on the execution efficiency of the main process.
Epoll is an improved version of the Linux kernel to handle large quantities of file descriptors. It is an enhanced version of the multiplexed IO interface select/poll under Linux. It can significantly improve the program when there are only a few active connections in a large number of concurrent connections. CPU utilization.
There are 16 databases by default. Similar to the array index starting from 0, the initial default value uses the zero number
Insert picture description here
database. There is a key-value pair of k1 in the 0th database, and after the 7th database is selected, k1 cannot be found.
The select command switches the database
dbsize to view the number of keys in the current database

(hashset and hashmap are actually the same thing, the bottom layer of hashset is hashmap)
which is important, key
Insert picture description here
flushdb clears the current database,
flushes clears all databases

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_39736597/article/details/110959433