Spring Boot Redis添加密码

两种方式

第一种

1.直接在config文件中找到 requirepass foobared 去掉注释 默认密码为foobared 

2.直接在命令行启动redis即可  redis-server redis.config

第二种

1.先启动Redis服务

2.在命令行输入 redis-cli  进入redis 命令

3. 

设置密码命令

config set requirepass 密码

查询密码

config get requirepass

 

 auth 密码

红色箭头方向的内容为设置的密码

 

项目配置

application.yml 配置

spring:       
    redis:
      host: 127.0.0.1
      #redis密码,没有密码的可以用~表示
      password: 密码
      port: 6379
      database: 0
      timeout: 60s
      lettuce:
        pool:
          # 最大空闲连接数
          max-idle: 500
          # 最小空闲连接数
          min-idle: 50
          # 等待可用连接的最大时间,负数为不限制
          max-wait:  -1s
          # 最大活跃连接数,负数为不限制
          max-active: -1

Pom 配置

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

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章