Java Code Examples for org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory#afterPropertiesSet()

The following examples show how to use org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory#afterPropertiesSet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RateLimiterPluginDataHandler.java    From soul with Apache License 2.0 6 votes vote down vote up
@Override
public void handlerPlugin(final PluginData pluginData) {
    if (Objects.nonNull(pluginData) && pluginData.getEnabled()) {
        //init redis
        RateLimiterConfig rateLimiterConfig = GsonUtils.getInstance().fromJson(pluginData.getConfig(), RateLimiterConfig.class);
        //spring data redisTemplate
        if (Objects.isNull(Singleton.INST.get(ReactiveRedisTemplate.class))
                || Objects.isNull(Singleton.INST.get(RateLimiterConfig.class))
                || !rateLimiterConfig.equals(Singleton.INST.get(RateLimiterConfig.class))) {
            LettuceConnectionFactory lettuceConnectionFactory = createLettuceConnectionFactory(rateLimiterConfig);
            lettuceConnectionFactory.afterPropertiesSet();
            RedisSerializer<String> serializer = new StringRedisSerializer();
            RedisSerializationContext<String, String> serializationContext =
                    RedisSerializationContext.<String, String>newSerializationContext().key(serializer).value(serializer).hashKey(serializer).hashValue(serializer).build();
            ReactiveRedisTemplate<String, String> reactiveRedisTemplate = new ReactiveRedisTemplate<>(lettuceConnectionFactory, serializationContext);
            Singleton.INST.single(ReactiveRedisTemplate.class, reactiveRedisTemplate);
            Singleton.INST.single(RateLimiterConfig.class, rateLimiterConfig);
        }
    }
}
 
Example 2
Source File: RedisChannel.java    From syncer with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public RedisChannel(Redis redis, SyncerOutputMeta outputMeta, Ack ack) {
  this.batch = redis.getBatch();
  id = redis.connectionIdentifier();
  this.batchBuffer = new BatchBuffer<>(batch);
  this.ack = ack;
  FailureLogConfig failureLog = redis.getFailureLog();
  Path path = Paths.get(outputMeta.getFailureLogDir(), id);
  request = FailureLog.getLogger(path, failureLog, new TypeToken<FailureEntry<SyncWrapper<String>>>() {
  });
  template = new RedisTemplate<>();
  LettuceConnectionFactory factory = redis.getConnectionFactory();
  factory.afterPropertiesSet();
  template.setConnectionFactory(factory);
  template.afterPropertiesSet();

  operationMapper = new OperationMapper(redis.getMapping());
  SpelExpressionParser parser = new SpelExpressionParser();
  if (!StringUtils.isEmpty(redis.conditionExpr())) {
    try {
      expression = parser.parseExpression(redis.conditionExpr());
    } catch (ParseException e) {
      throw new InvalidConfigException("Fail to parse [condition] for [redis] output channel", e);
    }
  }
}
 
Example 3
Source File: LettuceConnFactoryProvider.java    From sofa-dashboard-client with Apache License 2.0 5 votes vote down vote up
public LettuceConnectionFactory createFactory(ClientResources clientResources) {
    LettuceClientConfiguration clientConfig = getLettuceClientConfiguration(clientResources,
        this.properties.getLettuce().getPool());
    LettuceConnectionFactory factory = createLettuceConnectionFactory(clientConfig);
    factory.afterPropertiesSet();
    return factory;
}
 
Example 4
Source File: L3RedisCacheConfig.java    From x7 with Apache License 2.0 5 votes vote down vote up
@Bean
public L3CacheStorageCustomizer l3CacheStorageCustomizer(){

    RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(hostName, port);
    config.setPassword(password);
    config.setDatabase(database);

    LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(config);
    connectionFactory.afterPropertiesSet();


    Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<Object>(
            Object.class);
    ObjectMapper om = new ObjectMapper();
    om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
    om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    jackson2JsonRedisSerializer.setObjectMapper(om);

    StringRedisTemplate stringRedisTemplate = new StringRedisTemplate();
    stringRedisTemplate.setConnectionFactory(connectionFactory);
    stringRedisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
    stringRedisTemplate.setKeySerializer(new StringRedisSerializer());
    stringRedisTemplate.setHashKeySerializer(new StringRedisSerializer());

    stringRedisTemplate.afterPropertiesSet();

    return () -> {

        L3CacheStorage l3CacheStorage = new DefaultL3CacheStorage();
        ((DefaultL3CacheStorage) l3CacheStorage).setStringRedisTemplate(stringRedisTemplate);

        return l3CacheStorage;
    };
}
 
Example 5
Source File: RedisCacheConfig.java    From x7 with Apache License 2.0 5 votes vote down vote up
@Bean
public LettuceConnectionFactory redisConnectionFactory() {
    RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(hostName, port);
    LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(config);
    connectionFactory.afterPropertiesSet();
    return connectionFactory;
}
 
Example 6
Source File: RedisSpringDataCacheTest.java    From jetcache with Apache License 2.0 5 votes vote down vote up
@Test
public void lettuceTest() throws Exception {
    LettuceConnectionFactory connectionFactory =  new LettuceConnectionFactory(
            new RedisStandaloneConfiguration("127.0.0.1", 6379));
    connectionFactory.afterPropertiesSet();
    doTest(connectionFactory);
}
 
Example 7
Source File: SpringDataRedisTestConfiguration.java    From java-redis-client with Apache License 2.0 5 votes vote down vote up
@Bean
public RedisConnectionFactory redisConnectionFactory() {
  LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory();
  lettuceConnectionFactory.afterPropertiesSet();
  return new TracingRedisConnectionFactory(lettuceConnectionFactory,
      new TracingConfiguration.Builder(tracer()).build());
}
 
Example 8
Source File: InstallRemote.java    From jeesupport with MIT License 5 votes vote down vote up
@RemoteMethod
public void redis( String _host, int _port, String _password, int _db ) throws Exception{
    try{
        RedisConfig rc = new RedisConfig();

        RedisStandaloneConfiguration rsc = rc.redisStandaloneConfiguration();
        rsc.setHostName( _host );
        rsc.setPort( _port );
        rsc.setPassword( _password );
        rsc.setDatabase( _db );

        LettuceConnectionFactory lcf = ( LettuceConnectionFactory )
                rc.connectionFactory( rsc, rc.lettucePoolConfig( rc.clientOptions(), rc.clientResources() ) );
        lcf.setDatabase( _db );
        lcf.afterPropertiesSet();

        sDB.changeDatabase( lcf );

        Test t = new Test( RandomUtil.s_random_integer( 100 ) );
        sDB.insert( t );
        sDB.delete( t );

        installConfig.installRedis( _host, _port,_password, _db );
    }catch ( Exception e ){
        installConfig.installFailure( InstallConfig.InstallRedisSucc );
        throw new Exception( "连接失败" );
    }
}
 
Example 9
Source File: LetucceLockProviderIntegrationTest.java    From ShedLock with Apache License 2.0 4 votes vote down vote up
private static RedisConnectionFactory createLettuceConnectionFactory() {
    LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(HOST, PORT);
    lettuceConnectionFactory.afterPropertiesSet();
    return lettuceConnectionFactory;
}
 
Example 10
Source File: LetucceLockProviderIntegrationTest.java    From ShedLock with Apache License 2.0 4 votes vote down vote up
private static RedisConnectionFactory createLettuceConnectionFactory() {
    LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(HOST, PORT);
    lettuceConnectionFactory.afterPropertiesSet();
    return lettuceConnectionFactory;
}