时间:2022-10-02来源:www.pcxitongcheng.com作者:电脑系统城
修改redis.conf配置文件
1、protected-mode yes(默认的) 修改成 protected-mode no,解除保护模式

2、注释掉绑定ip ,绑定ip的话,使得除了本机(服务器)以外的主机无法访问redis数据库

3、将守护进程模式关闭 daemonize yes 改成 daemonize no

4、最后,一定记住要redis-server redis.conf重启redis的配置文件,否则修改不生效!!!
1、导入依赖
| 1 2 3 4 5 |
<!--redis--><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId></dependency> |
2、配置yml配置文件
| 1 2 3 4 5 |
spring: redis: host: 你的云服务器的ip port: 6379 # Redis的端口 password: redis密码 # Redis服务器连接密码 |
3、注入RedisTemplate
| 1 2 |
@Autowiredprivate RedisTemplate redisTemplate; |
使用例子
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
@Autowiredprivate RedisTemplate redisTemplate;@Testpublic void redisTestSet( ) { ValueOperations ops = redisTemplate.opsForValue(); ops.set( "username", 41); System.out.println( );}@Testpublic void redisTestGet( ) { ValueOperations ops = redisTemplate.opsForValue(); Object name = ops.get( "username"); System.out.println( name );} |
报错1:

解决方式1:在redis.conf配置文件中requirepass后空一一格,然后加上密码

解决方式2:命令模式
1)登录redis
| 1 | redis-cli |
2)设置密码 (比如我设置密码为12345678)
| 1 | set requirepass 12345678 |
3)验证 :输入默认用户名 auth 和 密码
| 1 | auth 12345678 |

错误2:
启动项目时报错:java.net.ConnectException: Connection refused: no further information
原因:开头的前提条件2可能没有弄好,或是弄了但没有和重新启动redis
2023-10-27
windows11安装SQL server数据库报错等待数据库引擎恢复句柄失败解决办法2023-10-27
SQL Server截取字符串函数操作常见方法2023-10-27
浅谈SELECT *会导致查询效率低的原因收缩数据文件通过将数据页从文件末尾移动到更靠近文件开头的未占用的空间来恢复空间,在文件末尾创建足够的空间后,可取消对文件末尾的数据页的分配并将它们返回给文件系统,本文给大家介绍SQL Server 数据库中的收缩数据...
2023-10-27