单机&集群安装: 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();
}
}

Redis测试类的更多相关文章

  1. redis 工具类 单个redis、JedisPool 及多个redis、shardedJedisPool与spring的集成配置

    http://www.cnblogs.com/edisonfeng/p/3571870.html http://javacrazyer.iteye.com/blog/1840161 http://ww ...

  2. Java代码封装redis工具类

    maven依赖关系: <dependency> <groupId>redis.clients</groupId> <artifactId>jedis&l ...

  3. redistemplate优雅地操作redis redis 工具类

    参考:https://www.cnblogs.com/superfj/p/9232482.html redis 工具类 package com.service; import org.springfr ...

  4. php 基于redis计数器类

    本文引自网络 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API. 本文将使用其incr(自增),get(获取), ...

  5. Redis 工具类 java 实现的redis 工具类

    最近了解了一下非关系型数据库 redis 会使用简单的命令 在自己本地电脑 使用时必须先启动服务器端 在启动客户端 redis 简介 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内 ...

  6. Redis连接工具类

    Redis连接工具类 导包 测试一下(junit) package com.test; import org.junit.Test; import redis.clients.jedis.Jedis; ...

  7. php redis通用类

    <?php /** * redis操作类 * 说明,任何为false的串,存在redis中都是空串. * 只有在key不存在时,才会返回false. * 这点可用于防止缓存穿透 * */ cla ...

  8. 小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_40、Redis工具类封装讲解和实战

    笔记 4.Redis工具类封装讲解和实战     简介:高效开发方式 Redis工具类封装讲解和实战         1.常用客户端 https://redisdesktop.com/download ...

  9. SpringBoot整合Redis及Redis工具类

    前言 想做一个秒杀项目,问了几个大佬要了项目视频,结果,自己本地实践的时候,发现不太一样,所以写下这篇,为以后做准备. 环境配置 IDE:IDEA 环境:Windows 数据库:Redis Maven ...

随机推荐

  1. python学习第十四天字典的del(),pop().popitem(),clear()删除方法

    字典的每个键值 key=>value 数据类型,字典的key是唯一的,Value可以一样 names={'玖乐公司网址':‘www.96net.com.cn’,"电池网":' ...

  2. bzoj3097 Hash Killer I

    Hash Killer I Time Limit: 5 Sec Memory Limit: 128 MBSec Special Judge Description 这天天气不错,hzhwcmhf神犇给 ...

  3. centos6中安装RabbitMQ

    一.安装环境步骤需知 第一步 安装erlang环境 第二步 安装RabbitMQ 二.安装erlang环境 1)安装编译环境,和基础依赖包 yum -y install make gcc gcc-c+ ...

  4. Cheatsheet: 2019 03.01 ~ 04.30

    Golang How To Install Go and Set Up a Local Programming Environment on macOS Build A Go API 40+ prac ...

  5. 2019-9-2-win10-uwp-打电话

    title author date CreateTime categories win10 uwp 打电话 lindexi 2019-09-02 12:57:38 +0800 2018-2-13 17 ...

  6. 对于一般情况X1+X2+X3+……+Xn=m 的正整数解有 (m-1)C(n-1) 它的非负整数解有 (m+n-1)C(n-1)种

    对于一般情况X1+X2+X3+……+Xn=m 的正整数解有 (m-1)C(n-1) 它的非负整数解有 (m+n-1)C(n-1)种

  7. Linux中检查内存使用情况的命令

    Linux操作系统包含大量工具,所有这些工具都可以帮助您管理系统.从简单的文件和目录工具到非常复杂的安全命令,在Linux上没有太多不能做的事情.而且,虽然普通桌面用户可能不需要在命令行熟悉这些工具, ...

  8. python基础:2.二进制

    1.二进制:计算机存储0,1的一种方式,规则是逢2进1. 一个数字在计算机存储的是一个字节,即8个bit,每个bit要么存储0,要么存储1. 0000 0000 (二进制)表示 0(十进制), 000 ...

  9. 算法 识别有效ip地址和掩码并做统计

    题目描述 请解析IP地址和对应的掩码,进行分类识别.要求按照A/B/C/D/E类地址归类,不合法的地址和掩码单独归类. 所有的IP地址划分为 A,B,C,D,E五类 A类地址1.0.0.0~126.2 ...

  10. 1.xml简单介绍

    1.xml(eXtensible Markup Language)的简介 (1)xml: 可扩展标记型语言 - 标记型语言:例如html也是标记型语言,也是使用标签来操作的 - 可扩展:html里面的 ...