单机&集群安装: https://blog.csdn.net/zxd1435513775/article/details/88901992

安装5.0.4版本OK,5.0.5版本make时报错。

redis.conf配置:

参考:

https://www.cnblogs.com/taiyonghai/p/5826134.html

https://www.cnblogs.com/taiyonghai/p/5826237.html

https://blog.csdn.net/tiantiandjava/article/details/72831529(重点参考)

bind 127.0.0.1(注释)

Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: Failed connecting to host 192.167.2.167:6379

Caused by: java.net.ConnectException: Connection refused: connect

该处英文说明bind的是interface,也就是说是网络接口。服务器可以有一个网络接口(通俗的说网卡,执行ifconfig查看),或者多个。打个比方说机器上有两个网卡,分别为192.168.205.5 和192.168.205.6,如果bind 192.168.205.5,那么只有该网卡地址接受外部请求,如果不绑定,则两个网卡口都接受请求。

执行ps -ef | grep redis-server,可以看到区别,# bind 127.0.0.1显示root 32012 1 0 14:00 ? 00:00:00 ./redis-server *:6379,bind 192.167.2.167显示root 2850 1 0 14:08 ? 00:00:00 ./redis-server 192.167.2.167:6379

bind 192.167.2.167,则本机的客户端连接必须是./redis-cli -h 192.167.2.167,否则可以直接./redis-cli连接

protected-mode no(改成yes)

Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

daemonize no(改成yes)

pidfile /var/run/redis_6379.pid

redis采用的是单进程多线程的模式。当redis.conf中选项daemonize设置成yes时,代表开启守护进程模式。在该模式下,redis会在后台运行,并将进程pid号写入至redis.conf选项pidfile设置的文件中,此时redis将一直运行,除非手动kill该进程。但当daemonize选项设置成no时,当前界面将进入redis的命令行界面,exit强制退出或者关闭连接工具(putty,xshell等)都会导致redis进程退出。

服务端开发的大部分应用都是采用后台运行的模式。

当redis在后台运行的时候,Redis默认会把pid文件放在/var/run/redis_6379.pid,可以配置到其他地址。当运行多个redis服务时,需要指定不同的pid文件和端口。

requirepass iMC123(放开注释)

参考 https://www.cnblogs.com/suanshun/p/7699084.html

说明:Warning: since Redis is pretty fast an outside user can try up to 150k passwords per second against a good box. This means that you should use a very strong password otherwise it will be very easy to break. redis的查询速度是非常快的,外部用户一秒内可以尝试多大150K个密码;所以密码要尽量长(对于DBA 没有必要必须记住密码);

客户端 ./redis-cli -p 6379 -a iMC123或./redis-cli -p 6379,在执行auth iMC123

Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: NOAUTH Authentication required.

依赖

<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.0.1</version>
</dependency>

代码

package com.example.demo_mg.test;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool; public class TestRedis {
public static void main( String[] args ) {
//方式一
// test1(); //方式二:线程池
test2();
} private static void test1() {
Jedis jedis = new Jedis("129.204.58.30",6379);
jedis.auth("test123"); //密码
System.out.println(jedis.ping()); //PONG
jedis.set("hello","world");
String value = jedis.get("hello");
System.out.println(value);
jedis.close();
} private static void test2() {
JedisPool pool = new JedisPool("129.204.58.30",6379);
Jedis jedis = pool.getResource();
String value = jedis.get("hello");
System.out.println(value);
jedis.close();
}
}

最新文章

  1. 利用box-shadow实现伪边框透明到图片
  2. 关于java对Excel的读取
  3. 条件变量pthread_cond_t怎么用
  4. (转) CCTextFieldTTF输入框
  5. php抽象类的简单应用
  6. PDA移动开单系统-PDA开单,手机开单,开单APP,移动开单,移动POS开单
  7. localStorage变更事件当前页响应新解
  8. iOS 非ARC基本内存管理系列 5-autorelease方法使用总结
  9. Linux的压缩解压命令快速上手——解压篇
  10. RVDS 3.1 下载地址及破解方法
  11. SQLite数据库操作 (原始操作)
  12. jquery.range.js左右滑动选取数值插件,动态改变进度。
  13. Openjudge-计算概论(A)-找和为K的两个元素
  14. iOS - CALayer 绘图层
  15. LeetCode之“字符串”:Valid Number(由此引发的对正则表达式的学习)
  16. Xapian索引-文档检索过程分析之匹配百分比
  17. php中include和require的区别(整理)
  18. Linux .vimrc 设置项
  19. 【Linux】使用w命令和uptime命令查看系统负载
  20. gensim与numpy array 互转

热门文章

  1. JavaScript中函数带与不带括号的区别
  2. 攻防世界--dmd-50
  3. Crash的数字表格(莫比乌斯反演)
  4. JS高级 — 函数中的this指向问题
  5. Ubuntu14.04(nginx+php+mysql+vsftp)配置安装流程
  6. 对象名 XXX 无效。
  7. 安装electron-react-boilerplate遇到的问题
  8. mysql Got a packet bigger than &#39;max_allowed_packet&#39; bytes
  9. mobx学习笔记02——mobx基础语法(class)
  10. createElement 函数