当前位置:网站首页>Redis quick start
Redis quick start
2022-07-06 17:20:00 【bestkasscn】
Redis
Concept
redis It is a high-performance non relational database . The storage form is key-value.
Characteristics of non relational database
- There is no correlation between the data
- Data stored in memory
Download and install
- Official website :https://redis.io
- Chinese net :http://www.redis.net.cn
- Decompression can be used directly
- redis.windows.conf: The configuration file
- redis-cli.exe:redis The client of
- redis-server.exe:redis Server side of
The command operation
redis Data structure of
- redis What's stored is :key-value Formatted data , among key All strings ,value Yes 5 Different data structures
- value Data structure of
- String type :string
- Hash type :hash:map Format
- List the type :list:linkedlist Format
- Collection types :set;
- Ordered set type :sortedset
- value Data structure of
- redis What's stored is :key-value Formatted data , among key All strings ,value Yes 5 Different data structures
String type string
- Storage :set key value
- obtain :get key
- Delete :del key
Hash type hash
Storage :hset key field value
obtain :hget key field
hgetall key( Get all field Of value)
Delete :hdel key field
List the type list Head and tail interpolation can be used
Storage :lpush key value( The first interpolation )
rpush key value( The tail interpolation )
obtain :lrange key start end : Scope acquisition
Delete :lpop key Delete the leftmost element , And return the element to
rpop key Delete the rightmost element , And return the element to
Collection types set
- Storage :sadd key value
- obtain :smembers key
- Delete :srem key value
General Command
- keys *: Query all the keys
- type key: Get the key corresponding to value type
- del key: Delete key
Persistence
redis It's a memory database , When redis Server restart , Or restart the computer , Data will be lost , We can redis The data in memory is persisted and saved to the file on the hard disk
redis Persistence mechanism :
RDB: Default mode , There is no need to configure , This mechanism is used by default
At certain intervals , testing key The change of , Then persist the data
AOF: How to log , The operation of each command can be recorded . You can persist data after every operation
Jedis
Introduce dependencies
<dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.7.0</version> </dependency>
test
public class JedisTest { private Jedis jedis; @BeforeEach void setup(){ // Establishing a connection jedis = new Jedis("127.0.0.1",6379); // Select database jedis.select(0); } @Test void testString(){ // In the data String result = jedis.set("name","zhangsan"); System.out.println("result=" + result); // get data String name = jedis.get("name"); System.out.println("name=" + name); } @AfterEach void tearDown(){ if (jedis != null){ jedis.close(); } } }
SpringDataRedis
Spring-data-redis yes spring Part of a large family , Provided in srping Access through simple configuration in the application redis service , Yes reids Underlying development package (Jedis, JRedis, and RJC) It's highly encapsulated ,RedisTemplate Provides redis Various operations 、 Exception handling and serialization , Support publish subscription , Also on spring 3.1 cache Implemented .
spring-data-redis in the light of jedis The following functions are provided :
Connection pool automatic management , Provides a highly encapsulated “RedisTemplate” class
in the light of jedis There are a lot of api It is classified and packaged , Encapsulate the same type of operation as operation Interface
ValueOperations: Simple K-V operation
SetOperations:set Type data operation
ZSetOperations:zset Type data operation
HashOperations: in the light of map Type of data operation
ListOperations: in the light of list Type of data operation
边栏推荐
- 控制转移指令
- High performance mysql (Third Edition) notes
- The "advertising maniacs" in this group of programmers turned Tiktok advertisements into ar games
- Control transfer instruction
- 汇编语言寻址方式
- Flink 解析(二):反压机制解析
- 华为认证云计算HICA
- JVM garbage collection overview
- Ruoyi-Cloud 踩坑的BUG
- Programmer orientation problem solving methodology
猜你喜欢
华为认证云计算HICA
MySQL字符串函数
【逆向】脱壳后修复IAT并关闭ASLR
February database ranking: how long can Oracle remain the first?
EasyRE WriteUp
Resume of a microservice architecture teacher with 10 years of work experience
JVM之垃圾回收器上篇
1. JVM入门介绍
Interpretation of Flink source code (III): Interpretation of executiongraph source code
TCP's three handshakes and four waves
随机推荐
Activit fragmented deadly pit
Resume of a microservice architecture teacher with 10 years of work experience
MySQL optimization notes
Flink源码解读(一):StreamGraph源码解读
Data transfer instruction
SQL tuning notes
Some feelings of brushing leetcode 300+ questions
吴军三部曲见识(七) 商业的本质
Activiti目录(五)驳回、重新发起、取消流程
vscode
yum install xxx报错
mysql的列的数据类型详解
服务器端渲染(SSR)和客户端渲染(CSR)的区别
Akamai浅谈风控原理与解决方案
Brush questions during summer vacation, ouch ouch
程序员定位解决问题方法论
控制转移指令
[VNCTF 2022]ezmath wp
Alibaba cloud server builds SVN version Library
JVM garbage collector part 2