@Bean
 public JedisConnectionFactory connectionFactory() {
   JedisConnectionFactory factory = new JedisConnectionFactory();
   factory.setHostName("192.168.230.53");
   factory.setDatabase(159);
   return factory;
 }
Exemplo n.º 2
0
 @Bean
 public JedisConnectionFactory redisConnectionFactory() {
   JedisConnectionFactory factory = new JedisConnectionFactory();
   factory.setHostName(host);
   factory.setPort(port);
   factory.setTimeout(timeout);
   return factory;
 }
  @Bean
  public RedisTemplate<Object, Object> redisTemplate() {

    System.out.println("RedisConfiguation.redisTemplate()");
    JedisConnectionFactory factory = new JedisConnectionFactory();
    JedisShardInfo shardInfo = new JedisShardInfo("localhost", 6379);
    factory.setShardInfo(shardInfo);
    RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();
    redisTemplate.setConnectionFactory(factory);
    return redisTemplate;
  }
 protected final JedisConnectionFactory applyProperties(JedisConnectionFactory factory) {
   factory.setHostName(this.properties.getHost());
   factory.setPort(this.properties.getPort());
   if (this.properties.getPassword() != null) {
     factory.setPassword(this.properties.getPassword());
   }
   factory.setDatabase(this.properties.getDatabase());
   if (this.properties.getTimeout() > 0) {
     factory.setTimeout(this.properties.getTimeout());
   }
   return factory;
 }
 private String toString(RedisConnectionFactory redisConnectionFactory) {
   if (redisConnectionFactory == null) {
     return "<none>";
   } else {
     if (redisConnectionFactory instanceof JedisConnectionFactory) {
       JedisConnectionFactory jcf = (JedisConnectionFactory) redisConnectionFactory;
       return jcf.getHostName().toString() + ":" + jcf.getPort();
     } else if (redisConnectionFactory instanceof LettuceConnectionFactory) {
       LettuceConnectionFactory lcf = (LettuceConnectionFactory) redisConnectionFactory;
       return lcf.getHostName().toString() + ":" + lcf.getPort();
     }
     return "<unknown> " + redisConnectionFactory.getClass();
   }
 }
  @Before
  public void setUp() throws Exception {

    executorMock = mock(Executor.class);

    connectionFactory = new JedisConnectionFactory();
    connectionFactory.setPort(SettingsUtils.getPort());
    connectionFactory.setHostName(SettingsUtils.getHost());
    connectionFactory.setDatabase(2);

    connectionFactory.afterPropertiesSet();

    container = new RedisMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.setBeanName("container");
    container.setTaskExecutor(new SyncTaskExecutor());
    container.setSubscriptionExecutor(executorMock);
    container.afterPropertiesSet();
  }
  @After
  public void tearDown() throws Exception {

    container.destroy();
    connectionFactory.destroy();
  }
Exemplo n.º 8
0
 static {
   cf = new JedisConnectionFactory();
   cf.afterPropertiesSet();
   stringRedisTemplate = new StringRedisTemplate(cf);
 }
 static {
   CONNECTION_FACTORY.afterPropertiesSet();
 }
  @Parameters
  public static Collection<Object[]> testParams() {
    // XStream serializer
    XStreamMarshaller xstream = new XStreamMarshaller();
    try {
      xstream.afterPropertiesSet();
    } catch (Exception ex) {
      throw new RuntimeException("Cannot init XStream", ex);
    }
    OxmSerializer serializer = new OxmSerializer(xstream, xstream);
    JacksonJsonRedisSerializer<Person> jsonSerializer =
        new JacksonJsonRedisSerializer<Person>(Person.class);
    JacksonJsonRedisSerializer<String> jsonStringSerializer =
        new JacksonJsonRedisSerializer<String>(String.class);

    // create Jedis Factory
    ObjectFactory<String> stringFactory = new StringObjectFactory();

    JedisConnectionFactory jedisConnFactory = new JedisConnectionFactory();
    jedisConnFactory.setUsePool(true);

    jedisConnFactory.setPort(SettingsUtils.getPort());
    jedisConnFactory.setHostName(SettingsUtils.getHost());

    jedisConnFactory.afterPropertiesSet();

    RedisTemplate<String, String> genericTemplate = new StringRedisTemplate(jedisConnFactory);

    RedisTemplate<String, String> xstreamGenericTemplate = new RedisTemplate<String, String>();
    xstreamGenericTemplate.setConnectionFactory(jedisConnFactory);
    xstreamGenericTemplate.setDefaultSerializer(serializer);
    xstreamGenericTemplate.afterPropertiesSet();

    RedisTemplate<String, Person> jsonPersonTemplate = new RedisTemplate<String, Person>();
    jsonPersonTemplate.setConnectionFactory(jedisConnFactory);
    jsonPersonTemplate.setDefaultSerializer(jsonSerializer);
    jsonPersonTemplate.setHashKeySerializer(jsonSerializer);
    jsonPersonTemplate.setHashValueSerializer(jsonStringSerializer);
    jsonPersonTemplate.afterPropertiesSet();

    // JRedis
    JredisConnectionFactory jredisConnFactory = new JredisConnectionFactory();
    jredisConnFactory.setUsePool(true);
    jredisConnFactory.setPort(SettingsUtils.getPort());
    jredisConnFactory.setHostName(SettingsUtils.getHost());
    jredisConnFactory.afterPropertiesSet();

    RedisTemplate<String, String> genericTemplateJR = new StringRedisTemplate(jredisConnFactory);
    RedisTemplate<String, Person> xGenericTemplateJR = new RedisTemplate<String, Person>();
    xGenericTemplateJR.setConnectionFactory(jredisConnFactory);
    xGenericTemplateJR.setDefaultSerializer(serializer);
    xGenericTemplateJR.afterPropertiesSet();

    RedisTemplate<String, Person> jsonPersonTemplateJR = new RedisTemplate<String, Person>();
    jsonPersonTemplateJR.setConnectionFactory(jredisConnFactory);
    jsonPersonTemplateJR.setDefaultSerializer(jsonSerializer);
    jsonPersonTemplateJR.setHashKeySerializer(jsonSerializer);
    jsonPersonTemplateJR.setHashValueSerializer(jsonStringSerializer);
    jsonPersonTemplateJR.afterPropertiesSet();

    // RJC

    // rjc
    RjcConnectionFactory rjcConnFactory = new RjcConnectionFactory();
    rjcConnFactory.setUsePool(true);
    rjcConnFactory.setPort(SettingsUtils.getPort());
    rjcConnFactory.setHostName(SettingsUtils.getHost());
    rjcConnFactory.afterPropertiesSet();

    RedisTemplate<String, String> genericTemplateRJC = new StringRedisTemplate(jredisConnFactory);
    RedisTemplate<String, Person> xGenericTemplateRJC = new RedisTemplate<String, Person>();
    xGenericTemplateRJC.setConnectionFactory(rjcConnFactory);
    xGenericTemplateRJC.setDefaultSerializer(serializer);
    xGenericTemplateRJC.afterPropertiesSet();

    RedisTemplate<String, Person> jsonPersonTemplateRJC = new RedisTemplate<String, Person>();
    jsonPersonTemplateRJC.setConnectionFactory(rjcConnFactory);
    jsonPersonTemplateRJC.setDefaultSerializer(jsonSerializer);
    jsonPersonTemplateRJC.setHashKeySerializer(jsonSerializer);
    jsonPersonTemplateRJC.setHashValueSerializer(jsonStringSerializer);
    jsonPersonTemplateRJC.afterPropertiesSet();

    // Lettuce
    LettuceConnectionFactory lettuceConnFactory = new LettuceConnectionFactory();
    lettuceConnFactory.setPort(SettingsUtils.getPort());
    lettuceConnFactory.setHostName(SettingsUtils.getHost());
    lettuceConnFactory.afterPropertiesSet();

    RedisTemplate<String, String> genericTemplateLtc = new StringRedisTemplate(lettuceConnFactory);
    RedisTemplate<String, Person> xGenericTemplateLtc = new RedisTemplate<String, Person>();
    xGenericTemplateLtc.setConnectionFactory(lettuceConnFactory);
    xGenericTemplateLtc.setDefaultSerializer(serializer);
    xGenericTemplateLtc.afterPropertiesSet();

    RedisTemplate<String, Person> jsonPersonTemplateLtc = new RedisTemplate<String, Person>();
    jsonPersonTemplateLtc.setConnectionFactory(lettuceConnFactory);
    jsonPersonTemplateLtc.setDefaultSerializer(jsonSerializer);
    jsonPersonTemplateLtc.setHashKeySerializer(jsonSerializer);
    jsonPersonTemplateLtc.setHashValueSerializer(jsonStringSerializer);
    jsonPersonTemplateLtc.afterPropertiesSet();

    return Arrays.asList(
        new Object[][] {
          {stringFactory, stringFactory, genericTemplate},
          {stringFactory, stringFactory, genericTemplate},
          {stringFactory, stringFactory, genericTemplate},
          {stringFactory, stringFactory, genericTemplate},
          {stringFactory, stringFactory, xstreamGenericTemplate},
          {stringFactory, stringFactory, genericTemplateJR},
          {stringFactory, stringFactory, genericTemplateJR},
          {stringFactory, stringFactory, genericTemplateJR},
          {stringFactory, stringFactory, genericTemplateJR},
          {stringFactory, stringFactory, xGenericTemplateJR},
          {stringFactory, stringFactory, jsonPersonTemplate},
          {stringFactory, stringFactory, jsonPersonTemplateJR},
          {stringFactory, stringFactory, genericTemplateRJC},
          {stringFactory, stringFactory, genericTemplateRJC},
          {stringFactory, stringFactory, genericTemplateRJC},
          {stringFactory, stringFactory, genericTemplateRJC},
          {stringFactory, stringFactory, xGenericTemplateRJC},
          {stringFactory, stringFactory, jsonPersonTemplateRJC},
          {stringFactory, stringFactory, genericTemplateLtc},
          {stringFactory, stringFactory, genericTemplateLtc},
          {stringFactory, stringFactory, genericTemplateLtc},
          {stringFactory, stringFactory, genericTemplateLtc},
          {stringFactory, stringFactory, xGenericTemplateLtc},
          {stringFactory, stringFactory, jsonPersonTemplateLtc}
        });
  }