First acquaintance and basic operation of Reids

Preface

   REmote DIctionary Server (Redis) is a key-value storage system written by Salvatore Sanfilippo.

  Redis is an open source log-type, Key-Value database that is written in ANSI C language, complies with the BSD protocol, supports the network, can be memory-based or persistent, and provides APIs in multiple languages. It is usually called a data structure server because the value can be of string (String), hash (Hash), list, set, and sorted sets.

Three major roles

  1. database
  2. Cache
  3. Message middleware MQ

Extension:
Redis bottleneck:
Redis is single-threaded, based on memory operations, CPU is not a performance bottleneck, the bottleneck is memory and network bandwidth

Why is redis fast?
Redis puts all the data in the memory, so single thread is the highest, because multi-threaded cpu takes more time to switch between the door and the door. For the memory system, if there is no context switch, single thread is The best. The cpu switch is between 1000-1500 nanoseconds.

Five types

Strings

Hashes (hash)

Lists

Sets

Sorted Sets (Ordered Sets)
Insert picture description here

Three special data types

Bitmap
Geo
GEOADD

Basic Redis operation

Redis has 16a database by default

vim  /redis.conf   # 查看配置文件

Insert picture description here
The number of the library is 0-15. The
default entry is library 0

select 2 Switch to the second database

set name jack Create a key with name value jack

Insert picture description here

type name View the value type of the name key
Insert picture description here

MSET age1 10 age2 20 Create multiple values ​​at the same time
Insert picture description here

DBSIZEView the capacity of the database

Insert picture description here
keys * View all keys of the current database*
Insert picture description here

get name View the value of the name key
Insert picture description here

flushdb Clear the current library

Insert picture description here

flushallClear all libraries (open RDB persistence, the data is saved on the disk) to
Insert picture description here
exists namedetermine whether the name key exists. If it returns 1, it exists, 0 does not exist.
Insert picture description here
move name 2Move the name key to the second library.
Insert picture description here
del nameDelete the name key

Insert picture description here

EXPIRE name 30 Set the value of the name key to be valid for 30 seconds, and clear the value after expiration (1. For example, store a cookie and expire after half a month 2. Single sign-on, set the expiration time 3. Verification code)
Insert picture description here

TTL name View remaining time
Insert picture description here

Value is empty after expiration
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_26129413/article/details/112335539