当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
MySQL数字函数
Serial serialold parnew of JVM garbage collector
February database ranking: how long can Oracle remain the first?
List set data removal (list.sublist.clear)
肖申克的救赎有感
Introduction to spring trick of ByteDance: senior students, senior students, senior students, and the author "brocade bag"
控制转移指令
Logical operation instruction
Description of project structure configuration of idea
Brush questions during summer vacation, ouch ouch
Take you hand-in-hand to do intensive learning experiments -- knock the level in detail
汇编语言基础知识
8086 分段技术
汇编课后作业
Ce n'est qu'en apprenant que c est à la hauteur des attentes Top5 s1e8 | s1e9: caractères et chaînes & opérateurs arithmétiques
吴军三部曲见识(七) 商业的本质
Ruoyi-Cloud 踩坑的BUG
【逆向】脱壳后修复IAT并关闭ASLR
Yao BanZhi and his team came together, and the competition experts gathered together. What fairy programming competition is this?
Activiti directory (V) reject, restart and cancel process









