SpringBoot集成Redis及使用总结

java哥 阅读:1104 2020-03-25 18:21:07 评论:0

一、Centos下安装Redis
1、下载安装包到/usr/local
wget http://download.redis.io/releases/redis-4.0.2.tar.gz
2、解压及安装
tar xzf redis-4.0.2.tar.gz
cd redis-4.0.2
make
make install
二、Redis常用指令
redis-server 启动redis服务器
redis-server redis.conf 启动服务器并加载配置文件redis.conf
redis-cli 启动redis客户端
flushdb //删除当前库中的数据
flushall //删除所有库中的数据
expire key seconds //设置key的过期时间
dbsize //所有key的数量
set key value
get key
del key
config set requirepass root 设置密码
auth root 登录
config rewrite 对redis配置文件进行改写,前提是服务端指定配置文件打开
三、Redis使用中常见的问题
1、Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool或connect refuse
可能原因:

  • redis服务器设置了密码,而连接redis的客户端没有setPassword
  • 远程访问权限 修改redis.conf中的配置:注释掉 bind 127.0.0.1 即 #bind 127.0.0.1

待续

标签:Spring Boot
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号