当前位置:网站首页>Preliminary understanding of redis
Preliminary understanding of redis
2022-07-24 17:27:00 【Hanshhh】
A preliminary understanding Redis
Redis It's completely open source , comply with BSD agreement , Is a high-performance key-value database .
Redis Characteristics
- Redis Support data persistence , The data in memory can be saved on disk , When you restart, you can load it again for use .
- Redis It's not just about supporting simple key-value Data of type , It also provides list,set,zset,hash Such as data structure storage .
- Redis Support data backup , namely master-slave Mode data backup .
- atom – Redis All operations of are atomic , It means either successful execution or failure and no execution at all . Individual operations are atomic . Multiple operations also support transactions , Atomicity , adopt MULTI and EXEC Package the instructions .
function Reids after , Open another one cmd window , Switch to redis Operating under the directory
Enter the command :redis-cli.exe -h 127.0.0.1 -p 6379
Set key value pairs :set myKey abc
Take out the key value pair :get myKey
Redis To configure
Redis The configuration file is located in Redis Installation directory , The file named redis.conf(Windows be known as redis.windows.conf).
View the configuration file , The grammar is :config get + Profile name // View all profiles CONFIG GET *
It can be modified by redis.conf Document or use config set Command to modify the configuration .
Example :
redis 127.0.0.1:6379> CONFIG SET loglevel "notice"
OK
redis 127.0.0.1:6379> CONFIG GET loglevel
1) "loglevel"
2) "notice"
Redis Please check the configuration details Novice tutorial Redis To configure
Reids data type
Redis Five data types are supported :string( character string ),hash( Hash ),list( list ),set( aggregate ) And zset(sorted set: Ordered set ).
String type :
string The type is Redis Basic data types , One key Corresponding to one value.
string Type is binary safe . intend redis Of string Can contain any data . such as jpg Picture or serialized object .
string The maximum value of type can store 512MB.
Hash( Hash ) type :
Redis hash It's a key value (key=>value) The collection .
Redis hash It's a string Type of field and value Mapping table ,hash Ideal for storing objects .
redis 127.0.0.1:6379> DEL runoob
redis 127.0.0.1:6379> HMSET runoob field1 "Hello" field2 "World"
"OK"
redis 127.0.0.1:6379> HGET runoob field1
"Hello"
redis 127.0.0.1:6379> HGET runoob field2
"World"
In the example, we use Redis HMSET, HGET command ,HMSET Set up two field=>value Yes , HGET Get corresponding field Corresponding value.
Every hash Can be stored 232 -1 Key value pair (40 More than ).
List( list ) type :
Redis List is a simple list of strings , Sort by insertion order . You can add an element to the head of the list ( On the left ) Or tail ( On the right ).
redis 127.0.0.1:6379> DEL runoob
redis 127.0.0.1:6379> lpush runoob redis
(integer) 1
redis 127.0.0.1:6379> lpush runoob mongodb
(integer) 2
redis 127.0.0.1:6379> lpush runoob rabbitmq
(integer) 3
redis 127.0.0.1:6379> lrange runoob 0 10
1) "rabbitmq"
2) "mongodb"
3) "redis"
redis 127.0.0.1:6379>
set( aggregate ) type :
Redis Of Set yes string Unordered collection of type .
Collections are implemented through hash tables , So add the , Delete , The complexity of searching is O(1).
sadd Command to add a string Element to key Corresponding set Collection , Successfully returns 1, If the element has already returned in the collection 0.
redis 127.0.0.1:6379> DEL runoob
redis 127.0.0.1:6379> sadd runoob redis
(integer) 1
redis 127.0.0.1:6379> sadd runoob mongodb
(integer) 1
redis 127.0.0.1:6379> sadd runoob rabbitmq
(integer) 1
redis 127.0.0.1:6379> sadd runoob rabbitmq //rabbitmq Has been added , Elements added again will be ignored
(integer) 0
redis 127.0.0.1:6379> smembers runoob
1) "redis"
2) "rabbitmq"
3) "mongodb"
zset(sorted set: Ordered set ) type :
Redis zset and set The same is true. string Collection of type elements , And duplicate members are not allowed .
The difference is that each element is associated with a double Score of type .redis It's the scores that sort the members of a collection from small to large .
zset Members of are unique , But fractions (score) But it can be repeated .
redis 127.0.0.1:6379> DEL runoob
redis 127.0.0.1:6379> zadd runoob 0 redis
(integer) 1
redis 127.0.0.1:6379> zadd runoob 0 mongodb
(integer) 1
redis 127.0.0.1:6379> zadd runoob 0 rabbitmq
(integer) 1
redis 127.0.0.1:6379> zadd runoob 0 rabbitmq
(integer) 0
redis 127.0.0.1:6379> ZRANGEBYSCORE runoob 0 1000
1) "mongodb"
2) "rabbitmq"
3) "redis"
边栏推荐
- Yolopose practice: one-stage human posture estimation with hands + code interpretation
- Digital transformation must have digital thinking
- Open source Invoicing system, 10 minutes to complete, it is recommended to collect!
- Mobile robot (IV) four axis aircraft
- The orders in the same city are delivered in the same city, and the order explosion is still handy!
- Stop littering configuration files everywhere! Try our 7-year-old solution, which is stable
- hcip第三天
- Scept: consistent and strategy based trajectory prediction for planned scenarios
- Kernel development
- Kyligence attended the Huawei global smart finance summit to accelerate the expansion of the global market
猜你喜欢

Yolopose practice: one-stage human posture estimation with hands + code interpretation

Cann training camp learns the animation stylization and AOE ATC tuning of the second season of 2022 model series

Programming language exercises (I)

Transformer structure analysis -- learning notes

Kernel development

Keyboard input operation

Atcoder beginer 202 e - count descendants (heuristic merge on heavy chain split tree for offline query)

Getaverse,走向Web3的远方桥梁

opencv自带颜色操作

快速入门
随机推荐
地表最强程序员装备“三件套”,你知道是什么吗?
Today, I met a 38K from Tencent, which let me see the ceiling of the foundation
Still shocked by the explosion in the movie? Then you must not miss this explosive plug-in of unity
socat 端口转发
通道的分离与合并
2022 ranking list of database audit products - must see!
Pat class A - check in and check out
Portfwd port forwarding
QT embed Notepad under win10
Three.js (7): local texture refresh
TCP协议调试工具TcpEngine V1.3.0使用教程
HCNP Routing&Switching之DHCP中继
Use 4D nerf to display occlusion (cvpr2022)
Pat a - correct spelling
Logisim group experiment 10 single cycle MIPS CPU
How the computer accesses the Internet (IV) LAN and server response
Wallys/3 × 3/2 × 2 MIMO 802.11ac Mini PCIe Wi-Fi Module, Dual Band, 2,4GHz / 5GHz/QCN9074
UFW port forwarding
Demonstration experiment of scrollbar for adjusting image brightness
Socat port forwarding