spring-data-redis,jedis和redis主从集成和遇到的问题

Redis主从加哨兵的部署详见http://www.cnblogs.com/dupang/p/6414365.html

spring-data-redis和jedis集成代码总体结构

代码地址https://github.com/dupang/redistestwithspring

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>redistest</groupId>
  <artifactId>springredis</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>springredis Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <properties>
    <springframework.version>4.3.6.RELEASE</springframework.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>${springframework.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context-support</artifactId>
      <version>${springframework.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-tx</artifactId>
      <version>${springframework.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>${springframework.version}</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <version>${springframework.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.data</groupId>
      <artifactId>spring-data-redis</artifactId>
      <version>1.8.0.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>redis.clients</groupId>
      <artifactId>jedis</artifactId>
      <version>2.9.0</version>
    </dependency>
  </dependencies>
  <build>
    <finalName>springredis</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

RedisTest.java

package com.dupang.redis;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by Administrator on 2017/2/17.
 */
public class RedisTest {
    public static void main(String[] args) {
        ApplicationContext ac =  new ClassPathXmlApplicationContext("classpath:/spring-redisSentine.xml");
        RedisUtil redisUtil = (RedisUtil) ac.getBean("redisUtil");
        String ss = redisUtil.get("user.uid.1");
        System.out.printf(ss);
    }
}

RedisUtil.java

package com.dupang.redis;

import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.concurrent.TimeUnit;

public class RedisUtil {

    private StringRedisTemplate redisTemplate;

    public RedisUtil(StringRedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    public Boolean add(String key,String value){
        Boolean rt=Boolean.FALSE;
        rt=redisTemplate.boundValueOps(key).setIfAbsent(value);
        if(rt) {
           redisTemplate.expire(key, 30L, TimeUnit.MINUTES);
        }
        return rt;
    }

    public Boolean add(String key,String value,long expire,TimeUnit timeUnit){
        Boolean rt=Boolean.FALSE;
        rt=redisTemplate.boundValueOps(key).setIfAbsent(value);
        if(rt) {
            redisTemplate.expire(key, expire, timeUnit);
        }
        return rt;
    }

    public String get(String key){
        return redisTemplate.boundValueOps(key).get();
    }

    public void delete(String key){
        redisTemplate.delete(key);
    }

    public String getAndRemove(String key){
        String rt=redisTemplate.boundValueOps(key).get();
        redisTemplate.delete(key);
        return rt;
    }

    public Boolean hasKey(String key){
        return redisTemplate.hasKey(key);
    }

}

spring-redisSentine.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:cache="http://www.springframework.org/schema/cache"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:redis="http://www.springframework.org/schema/redis"
    xsi:schemaLocation="
     http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
     http://www.springframework.org/schema/context
     http://www.springframework.org/schema/context/spring-context-3.1.xsd
     http://www.springframework.org/schema/cache
     http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
     http://www.springframework.org/schema/redis
     http://www.springframework.org/schema/redis/spring-redis-1.0.xsd">
    <context:property-placeholder location="classpath:app.properties" />
    <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
        <!-- 最大空闲连接数 -->
        <property name="maxIdle" value="${redis.adapter.maxIdle}" />
        <!-- 最小空闲连接数 -->
        <property name="minIdle" value="${redis.adapter.minIdle}" />
        <!-- 在获取连接的时候检查有效性 -->
        <property name="testOnBorrow" value="${redis.adapter.testOnBorrow}" />
        <!-- return 一个jedis实例给pool时,是否检查连接可用性 (ping()) -->
        <property name="testOnReturn" value="${redis.adapter.testOnReturn}" />
        <!-- idle状态监测用异步线程evict进行检查, -->
        <property name="testWhileIdle" value="${redis.adapter.testWhileIdle}" />
        <!-- 一次最多evict的pool里的jedis实例个数 -->
        <property name="numTestsPerEvictionRun" value="${redis.adapter.numTestsPerEvictionRun}" />
        <!-- test idle 线程的时间间隔 -->
        <property name="timeBetweenEvictionRunsMillis" value="${redis.adapter.timeBetweenEvictionRunsMillis}" />
    </bean>

    <bean id="sentinelConfig"
        class="org.springframework.data.redis.connection.RedisSentinelConfiguration">
        <!-- master名称 sentinel.conf里面配置的主节点名称 -->
        <constructor-arg name="master" value="${redis.adapter.masterName}" />
        <!-- sentinel的ip和端口列表 -->
        <constructor-arg name="sentinelHostAndPorts">
            <set>
                <value>${redis.adapter.sentinel1}</value>
                <value>${redis.adapter.sentinel2}</value>
                <value>${redis.adapter.sentinel3}</value>
            </set>
        </constructor-arg>
    </bean>

    <bean id="jedisConnectionFactory"
        class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
        <constructor-arg ref="sentinelConfig" />
        <constructor-arg ref="jedisPoolConfig" />
    </bean>

    <bean id="stringRedisSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer"/>

    <bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
        <property name="connectionFactory" ref="jedisConnectionFactory" />
    </bean>

    <bean id="redisUtil" class="com.dupang.redis.RedisUtil">
        <constructor-arg name="redisTemplate" ref="redisTemplate"/>
    </bean>

</beans>

app.properties

#redis
redis.adapter.maxIdle=100
redis.adapter.minIdle=10
redis.adapter.testOnBorrow=true
redis.adapter.testOnReturn=true
redis.adapter.testWhileIdle=true
redis.adapter.numTestsPerEvictionRun=10
redis.adapter.timeBetweenEvictionRunsMillis=60000
redis.adapter.masterName=mymaster
redis.adapter.sentinel1=127.0.0.1:26379
redis.adapter.sentinel2=127.0.0.1:26389
redis.adapter.sentinel3=127.0.0.1:26399

遇到的问题

在运行测试类时报错,内容如下

/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/bin/java -Didea.launcher.port=7533 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/lib/tools.jar:/Users/duguanxin/IdeaProjects/redistestwithspring/target/classes:/Users/duguanxin/.m2/repository/org/springframework/spring-context/4.3.6.RELEASE/spring-context-4.3.6.RELEASE.jar:/Users/duguanxin/.m2/repository/org/springframework/spring-aop/4.3.6.RELEASE/spring-aop-4.3.6.RELEASE.jar:/Users/duguanxin/.m2/repository/org/springframework/spring-beans/4.3.6.RELEASE/spring-beans-4.3.6.RELEASE.jar:/Users/duguanxin/.m2/repository/org/springframework/spring-core/4.3.6.RELEASE/spring-core-4.3.6.RELEASE.jar:/Users/duguanxin/.m2/repository/commons-logging/commons-logging/1.2/commons-logging-1.2.jar:/Users/duguanxin/.m2/repository/org/springframework/spring-expression/4.3.6.RELEASE/spring-expression-4.3.6.RELEASE.jar:/Users/duguanxin/.m2/repository/org/springframework/spring-context-support/4.3.6.RELEASE/spring-context-support-4.3.6.RELEASE.jar:/Users/duguanxin/.m2/repository/org/springframework/spring-tx/4.3.6.RELEASE/spring-tx-4.3.6.RELEASE.jar:/Users/duguanxin/.m2/repository/org/springframework/spring-web/4.3.6.RELEASE/spring-web-4.3.6.RELEASE.jar:/Users/duguanxin/.m2/repository/junit/junit/4.12/junit-4.12.jar:/Users/duguanxin/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:/Users/duguanxin/.m2/repository/org/springframework/spring-test/4.3.6.RELEASE/spring-test-4.3.6.RELEASE.jar:/Users/duguanxin/.m2/repository/org/springframework/data/spring-data-redis/1.8.0.RELEASE/spring-data-redis-1.8.0.RELEASE.jar:/Users/duguanxin/.m2/repository/org/springframework/data/spring-data-keyvalue/1.2.0.RELEASE/spring-data-keyvalue-1.2.0.RELEASE.jar:/Users/duguanxin/.m2/repository/org/springframework/data/spring-data-commons/1.13.0.RELEASE/spring-data-commons-1.13.0.RELEASE.jar:/Users/duguanxin/.m2/repository/org/springframework/spring-oxm/4.3.6.RELEASE/spring-oxm-4.3.6.RELEASE.jar:/Users/duguanxin/.m2/repository/org/slf4j/slf4j-api/1.7.22/slf4j-api-1.7.22.jar:/Users/duguanxin/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.22/jcl-over-slf4j-1.7.22.jar:/Users/duguanxin/.m2/repository/redis/clients/jedis/2.9.0/jedis-2.9.0.jar:/Users/duguanxin/.m2/repository/org/apache/commons/commons-pool2/2.4.2/commons-pool2-2.4.2.jar:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar" com.intellij.rt.execution.application.AppMain com.dupang.redis.RedisTest
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
二月 19, 2017 10:34:30 上午 redis.clients.jedis.JedisSentinelPool initSentinels
信息: Trying to find master from available Sentinels...
二月 19, 2017 10:34:35 上午 redis.clients.jedis.JedisSentinelPool initSentinels
警告: Cannot get master address from sentinel running @ 192.168.2.101:26379. Reason: 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.. Trying next one.
二月 19, 2017 10:34:35 上午 redis.clients.jedis.JedisSentinelPool initSentinels
警告: Cannot get master address from sentinel running @ 192.168.2.101:26389. Reason: 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.. Trying next one.
二月 19, 2017 10:34:35 上午 redis.clients.jedis.JedisSentinelPool initSentinels
警告: Cannot get master address from sentinel running @ 192.168.2.101:26399. Reason: 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.. Trying next one.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘jedisConnectionFactory‘ defined in class path resource [spring-redisSentine.xml]: Invocation of init method failed; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: All sentinels down, cannot determine where is mymaster master is running...
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at com.dupang.redis.RedisTest.main(RedisTest.java:11)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: All sentinels down, cannot determine where is mymaster master is running...
    at redis.clients.jedis.JedisSentinelPool.initSentinels(JedisSentinelPool.java:180)
    at redis.clients.jedis.JedisSentinelPool.<init>(JedisSentinelPool.java:95)
    at redis.clients.jedis.JedisSentinelPool.<init>(JedisSentinelPool.java:76)
    at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.createRedisSentinelPool(JedisConnectionFactory.java:263)
    at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.createPool(JedisConnectionFactory.java:248)
    at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.afterPropertiesSet(JedisConnectionFactory.java:237)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624)
    ... 17 more

Process finished with exit code 1

居然报所有哨兵都down掉的错误,而我确认所有这些哨兵都正常着,百度看看,说是防火墙的问题。但是我的防火墙就没开,看来也不是这个问题。后来发现了上面打印的警告信息。

Cannot get master address from sentinel running @ 192.168.2.101:26399. Reason: 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.. Trying next one

这是因为哨兵的配置文件里的保护模式启动了。所以又因为没有绑定可以访问的ip和设置访问密码,就不允许从外部访问。

我们的哨兵明明是127的地址,应该访问127.0.0.1:26379才对啊,这是因为redis内部把127的地址转换成了192.168.2.101了,也就是你的本机的ip地址。所以访问192的地址就相当于从外部访问你的哨兵。

根据它的1,2,3,4的提示,你只要满足其中一个就行。于是我就把三个哨兵的sentinel.conf配置文件中的保护模式改为禁用就行了

# *** IMPORTANT ***
#
# By default Sentinel will not be reachable from interfaces different than
# localhost, either use the ‘bind‘ directive to bind to a list of network
# interfaces, or disable protected mode with "protected-mode no" by
# adding it to this configuration file.
#
# Before doing that MAKE SURE the instance is protected from the outside
# world via firewalling or other means.
#
# For example you may use one of the following:
#
# bind 127.0.0.1 192.168.1.1
#
protected-mode no

这样再访问就ok了。

时间: 2024-08-04 13:46:27

spring-data-redis,jedis和redis主从集成和遇到的问题的相关文章

征服 Redis + Jedis + Spring (三)—— 列表操作【转】

一开始以为Spring下操作哈希表,列表,真就是那么土.恍惚间发现“stringRedisTemplate.opsForList()”的强大,抓紧时间恶补下. 相关链接: 征服 Redis 征服 Redis + Jedis 征服 Redis + Jedis + Spring (一)—— 配置&常规操作(GET SET DEL) 征服 Redis + Jedis + Spring (二)—— 哈希表操作(HMGET HMSET) 征服 Redis + Jedis + Spring (三)—— 列表

征服 Redis + Jedis + Spring (一)—— 配置&amp;常规操作(GET SET DEL)

有日子没写博客了,真的是忙得要疯掉. 完成项目基础架构搭建工作,解决了核心技术问题,接着需要快速的调研下基于Spring框架下的Redis操作. 相关链接: 征服 Redis 征服 Redis + Jedis 征服 Redis + Jedis + Spring (一)—— 配置&常规操作(GET SET DEL) 征服 Redis + Jedis + Spring (二)—— 哈希表操作(HMGET HMSET) 征服 Redis + Jedis + Spring (三)—— 列表操作 前文有述

Spring boot 整合 Jedis

1 概述 1. Jedis是Redis的Java实现的客户端,其API提供了比较全面的Redis命令的支持. 2.Jedis中的方法调用是比较底层的暴露的Redis的API,也即Jedis中的Java方法基本和Redis的API保持着一致,了解Redis的API,也就能熟练的使用Jedis. 3.Jedis使用阻塞的I/O,且其方法调用都是同步的,程序流需要等到sockets处理完I/O才能执行,不支持异步.Jedis客户端实例不是线程安全的,所以需要通过连接池来使用Jedis. 4.Jedis

使用JAVA操作ElasticSearch(Java API 和Spring Data ElasticSearch)

Java API 我的ElasticSearch集群的版本是6.2.4,导入elasticsearch相关的maven依赖也是6.2.4,不同版本的api可能会有差异 一:maven依赖 <!--elasticsearch核心依赖--> <dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> <version

Spring Data Redis与Jedis的选择(转)

说明:内容可能有点旧,需要在业务上做权衡. Redis的客户端有两种实现方式,一是可以直接调用Jedis来实现,二是可以使用Spring Data Redis,通过Spring的封装来调用.应该使用哪一个呢?基于当前版本Spring Data Redis 1.0.1和Jedis 2.0.0,分析如下: Spring Data Redis 1.0.1 优点 1.对具体Redis客户端做了封装,客户端可在Jedis,Jredis,Rjc等Java客户端中做出选择和切换 . 2.用template对调

Spring Data Redis学习

本文是从为知笔记上复制过来的,懒得调整格式了,为知笔记版本是带格式的.点这里 为知笔记版本 Spring Data Redis 学习 Version 1.8.4.Release 前言 1.新功能 1.1.Spring Data Redis 1.8 新特性 1.2.Spring Data Redis 1.7 新特性 1.3.Spring Data Redis 1.6 新特性 1.4.Spring Data Redis 1.5 新特性 介绍 2.为什么选择Spring Data Redis? 3.要

使用Spring Data Redis操作Redis(一)

Spring-Data-Redis项目(简称SDR)对Redis的Key-Value数据存储操作提供了更高层次的抽象,类似于Spring Framework对JDBC支持一样. 项目主页:http://projects.spring.io/spring-data-redis/ 项目文档:http://docs.spring.io/spring-data/redis/docs/1.5.0.RELEASE/reference/html/ 本文主要介绍Spring Data Redis的实际使用. 1

Spring Data Redis简介以及项目Demo,RedisTemplate和 Serializer详解

一.概念简介: Redis: Redis是一款开源的Key-Value数据库,运行在内存中,由ANSI C编写,详细的信息在Redis官网上面有,因为我自己通过google等各种渠道去学习Redis,走了不少弯路,所以总结一条我认为不错的学习路径给大家: 1.<The Little Redis Book> 是一本开源PDF,只有29页的英文文档,看完后对Redis的基本概念应该差不多熟悉了,剩下的可以去Redis官网熟悉相关的命令. 2.<Redis设计与实现> 如果想继续深入,推

spring mvc Spring Data Redis RedisTemplate [转]

一.概念简介: Redis: Redis是一款开源的Key-Value数据库,运行在内存中,由ANSI C编写,详细的信息在Redis官网上面有,因为我自己通过google等各种渠道去学习Redis,走了不少弯路,所以总结一条我认为不错的学习路径给大家: 1.<The Little Redis Book> 是一本开源PDF,只有29页的英文文档,看完后对Redis的基本概念应该差不多熟悉了,剩下的可以去Redis官网熟悉相关的命令. 2.<Redis设计与实现> 如果想继续深入,推

使用Spring Data Redis操作Redis(集群版)

继上一篇文章http://www.cnblogs.com/EasonJim/p/7804545.html使用Spring Data Redis操作Redis用的是单机版,如果是集群版的集成其实差别不大.主要思路如下: 1.先建立连接工厂,这个连接工厂是用来设置IP,端口,账号密码等.(在这一步时,传递一个集群的地址列表,不再是单独一个去指定) 2.通过连接工厂建立Session. 3.然后在代码上注入Session进行使用. 简要实现步骤,操作的方法和单机版的类似: 一.使用spring-dat