Uploaded image for project: 'Spring Data Redis'
  1. Spring Data Redis
  2. DATAREDIS-877

Destroy LettuceConnectionFactory block too long

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Works as Designed
    • Affects Version/s: 2.1 GA (Lovelace)
    • Fix Version/s: None
    • Component/s: Lettuce Driver
    • Labels:
      None

      Description

      After switch redis driver from jedis to lettuce, closing ApplicationContext take more about 1.1s.

      import org.springframework.context.annotation.AnnotationConfigApplicationContext;
      import org.springframework.context.annotation.Bean;
      import org.springframework.context.annotation.Configuration;
      import org.springframework.data.redis.connection.RedisConnectionFactory;
      import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
      import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
      import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
      import org.springframework.data.redis.core.StringRedisTemplate;
      
      import io.lettuce.core.ClientOptions;
      
      public class Main {
      
      	public static void main(String[] args) {
      		test(false);
      		test(true);
      	}
      
      	private static void test(boolean interaction) {
      		AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
      		if (interaction) {
      			StringRedisTemplate srt = ctx.getBean(StringRedisTemplate.class);
      			srt.delete("anything"); // any operation
      		}
      		long time = System.currentTimeMillis();
      		ctx.close();
      		System.out.println(
      				(System.currentTimeMillis() - time) + " ms " + (interaction ? "with" : "without") + " interaction");
      	}
      
      	@Configuration
      	public static class Config {
      
      		@Bean
      		public RedisConnectionFactory redisConnectionFactory() {
      			LettuceClientConfiguration clientConfiguration = LettuceClientConfiguration.builder()
      					.clientOptions(ClientOptions.builder().build()).build();
      			RedisStandaloneConfiguration standaloneConfiguration = new RedisStandaloneConfiguration("localhost", 6379);
      			return new LettuceConnectionFactory(standaloneConfiguration, clientConfiguration);
      		}
      
      		@Bean
      		public StringRedisTemplate stringRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
      			return new StringRedisTemplate(redisConnectionFactory);
      		}
      
      	}
      
      }
      

      output result:
      113 ms without interaction
      1113 ms with interaction
       

       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mp911de Mark Paluch
              Reporter:
              quaff Yanming Zhou
              Last updater:
              Mark Paluch
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: