Redis basics

Redis basics

Insert picture description here

Redis has 16 databases by default

You can use the command vim to edit redis.config.

Insert picture description here

By default, the 0th database is used.

You can use select to switch databases

 [[email protected] bin]# redis-cli> select 0 //切换数据库
OK> DBSIZE  //查看DB大小
(integer) 4
Insert picture description here>kes *//查看所有的Key
Insert picture description here>flushdb//清空当前数据库
Insert picture description here>flushall//清空全部数据库的内容
Insert picture description here
Redis is single threaded

To understand that Redis is fast, the official said that Redis is based on memory operations, CPU is not the performance bottleneck of Redis, the bottleneck of Redis is based on the memory and network bandwidth of the machine, since it can be implemented with single thread, use single thread! All Just use single thread!
Redis is written in C language, the official data is 100000+ QPS, which is not worse than Memecache which also uses key-vale!
Why is Redis single thread so fast?
1. Misunderstanding 1: High The performance server must be multi-threaded?

Answer: High-performance servers are not necessarily multi-threaded.

2. Misunderstanding 2: Multi-threading (CPU context will switch!) must be more efficient than single-threading!

First go to CPU>Memory>hard disk speed to know something!

Core: Redis puts all the data in memory, so using a single thread to operate is the most efficient, more

Thread (CPU context switching: a time-consuming operation!!! ), for the memory system, if there is no context switching efficiency

It is the highest! Multiple reads and writes are performed on one CPU. In the case of memory, this is the best solution!