首页
  • Java
  • Linux
  • Deploy
  • Application

Xiao ku

板砖师傅
首页
  • Java
  • Linux
  • Deploy
  • Application
  • Springboot集成redis
    • pom文件
    • yml文件
    • 代码使用
      • String类型:
      • Object类型:
  • Springboot集成mongodb
  • Springboot集成FastDFS
  • Springboot集成WebSocket
  • Springboot集成kafka
  • Springboot集成Flyway
  • Springboot集成ScheduleTask
  • Validation数据校验规范使用
  • 常用代码
  • Java
xiaoku
2023-03-10
目录

Springboot集成redis

# pom文件

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
 </dependency>
1
2
3
4

# yml文件

spring:
  redis:
    database: 0
    port: 6379
    pool:
      max-idle: 8
      min-idle: 0
      max-active: 8
      max-wait: -1
    host: 192.168.213.213
    password: redismima123
    timeout: 100
1
2
3
4
5
6
7
8
9
10
11
12

# 代码使用

# String类型:

public class imclass {
  @Autowired
  private StringRedisTemplate Redis;
  public String test(String rawPass) {
    //存储
    Redis.opsForValue().set(key, value, 1800,TimeUnit.SECONDS);
    //取值
    String str = Redis.opsForValue().get(key);
  }
}
1
2
3
4
5
6
7
8
9
10

# Object类型:

public class imclass {
  @Autowired
  private RedisTemplate<String, Object> redisTemplate;
  public String test(String rawPass) {
    //存储
    Map<String,Object> params = new HashMap<>();
    params.put("accountId", "2");
    params.put("limit", 1);
    List<EvrAlarm> evrAlarms=evrAlarmDao.selectEvrAlarmByAccount(params);

    //redis缓存
    ListOperations<String, Object> lo =  redisTemplate.opsForList();
    lo.rightPush("EvrAlarm-2", evrAlarms);
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
上次更新: 2023/03/10, 09:02:56
Springboot集成mongodb

Springboot集成mongodb→

Copyright © 2019-2024 | 闽ICP备20012188号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式