Spring Boot整合Redis详解

Redis的Java客户端有很多,例如Jedis、JRedis、Spring Data Redis等,Spring Boot借助于Spring Data Redis为Redis提供了开箱即用的自动化配置,开发者只需要添加相关依赖并配置Redis连接信息即可,具体步骤如下:

创建Spring Boot项目:

首先创建Spring Boot项目,添加如下依赖:


    org.springframework.boot
    spring-boot-starter-data-redis


    org.springframework.boot
    spring-boot-starter-web

默认情况下,spring-boot-starter-data-redis使用的Redis工具是Lettuce。

配置Redis:

在application.properties中配置redis的连接信息:

#配置redis连接信息
spring.redis.database=0
spring.redis.host=127.0.0.1
spring.redis.port

你可能感兴趣的:(redis,redis)