springboot整合redis

一、POM文件

<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-redis</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-pool2</artifactId>
		</dependency>
	</dependencies>

二、application.yml

server:
  port: 8080
spring:
  redis:
    # Redis服务器地址
    host: 127.0.0.1
    #集群配置 127.0.0.1:6379,127.0.0.1:6378,127.0.0.1:6377
#    cluster:
#      nodes:
    # Redis服务器端口
    port: 6379
    #密码
    password:
    # Redis默认情况下有16个分片,值是0
    database: 0
    timeout: 36000ms

    lettuce:
     pool:
       #连接池最大连接数(使用负值表示没有限制) 默认 8
       max-active: 200
       # 连接池最大阻塞等待时间(使用负值表示没有限制) 默认 -1ms
       max-wait: -1ms
       #连接池中的最大空闲连接 默认 8
       max-idle: 8
       #连接池中的最小空闲连接 默认 0
       min-idle: 0

当前是单机版

三、操作redis

redis提供了两个模板 RedisTemplate 和 StringRedisTemplate

操作方法相同

    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    @Resource
    private StringRedisTemplate stringRedisTemplate;
* opsForValue :对应 String(字符串)
* opsForZSet:对应 ZSet(有序集合)
* opsForHash:对应 Hash(哈希)
* opsForList:对应 List(列表)
* opsForSet:对应 Set(集合)
* opsForGeo:对应 GEO(地理位置)

具体代码参照:

https://gitee.com/third_code/springboot-family 

下的 spring-boot-redis 模块

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值