Redis entry commands

Redis entry commands

Redis basics

It can be seen from the configuration file:
There Redis 16databases, used by default is the first 0one

Switch database

select x   # 切换数据库 0-15

View database capacity

DBSIZE 
1
Data accessed between databases is generally disconnected
If you have information in the 3rd data inventory, it will not affect other databases DBSIZE

Access data

ser key value   # 存入 k:v

get key         # 得到 对应k的v

View all keys

keys *          
2

Clear the current database

flushdb
3

Clear all databases

FLUSHALL
  1. In the 0stored data number in the database, check capacity
  2. In the 3stored data number in the database, check capacity
  3. Use the statement
  4. View the capacity in the two databases, both are 0
4
Redis is single threaded

Officially, Redis is based on 内存operations

CPU is not the performance bottleneck of Redis. The bottleneck of Redis is based on the 内存sum of the machines 网络带宽. Since it can be realized by single thread, single thread is used

Why is Redis so fast in single thread?

Misunderstanding 1: High-performance servers are not necessarily multi-threaded.
Misunderstanding 2: CPU context switching in multi-threading is not necessarily more efficient than single-threading.
Go to CPU>Memory>Hard disk speed to understand!

core

Redis puts all the data in 内存it, so using a single thread to operate is the most efficient

In multi-threading, the CPU context will switch, which is a time-consuming operation. For the memory system, if there is no context switch, the efficiency is the highest. Multiple reads and writes are performed on one CPU. In the case of memory, This is the best solution

Redis basic commands

You can view the commands on the official website: http://www.redis.cn/commands.html

9

Determine if it exists

Return 1 if it exists, 0 if it doesn't exist
EXISTS XXX

I'm ahead of the deposit K:VandK1:V1

5

Mobile data

move xxx 数据库号

Examples are: The above K1:V1move to the 1number of the database

6

Set expiration time

EXPIRE XXX 时间(s)

View expiration time

ttl xxx
7

View corresponding type

type xxx
8
Personal blog is:
MoYu's HomePage
MoYu’s Gitee Blog