24 Şubat 2023 Cuma

SpringData Redis Redission Sınıfı

Giriş
Redisson için açıklama şöyle
Redisson adopts the nety framework based on NIO, which can not only be used as the underlying driver client of Redis, but also can send redis commands in synchronous, asynchronous, asynchronous stream or pipeline forms, execute and process Lua scripts, and process the returned results.
Maven
Şu satırı dahil ederiz
<dependency>
   <groupId>org.redisson</groupId>
   <artifactId>redisson</artifactId>
   <version>3.17.6</version>
</dependency>
Örnek
Şöyle yaparız
@RequiredArgsConstructor
@Configuration
public class RedissonConfig {

  @Bean
  public RedissonClient redissionClient() {
    Config config = new Config();
    config.useSingleServer().setAddress("redis://127.0.0.1:6379");
    return Redisson.create(config);
 }

@Bean
public RedisTemplate<String, Object> redisTemplate( RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory);
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
redisTemplate.setHashKeySerializer(new JdkSerializationRedisSerializer());
redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
redisTemplate.setEnableTransactionSupport(true);
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
}

Hiç yorum yok:

Yorum Gönder