generated from pagopa/template-java-spring-microservice
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [PagoPa-1797] paging and caching (#70)
* [PAGOPA-1797] paging and caching: first DRAFT impl * [PAGOPA-1797] paging and caching: REDIS impl --------- Co-authored-by: aacitelli <aacitelli@PDD-NB-0205.dgsgroup.it>
- Loading branch information
1 parent
1c8a927
commit c6aeaf1
Showing
25 changed files
with
505 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/it/gov/pagopa/bizeventsservice/config/RedisConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package it.gov.pagopa.bizeventsservice.config; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAutoDetect; | ||
import com.fasterxml.jackson.annotation.PropertyAccessor; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
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.RedisTemplate; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
@Configuration | ||
public class RedisConfig { | ||
|
||
@Value("${spring.redis.host}") | ||
private String redisHost; | ||
|
||
@Value("${spring.redis.port}") | ||
private int redisPort; | ||
|
||
@Value("${spring.redis.pwd}") | ||
private String redisPwd; | ||
|
||
@Bean | ||
public ObjectMapper objectMapper() { | ||
final var objectMapper = new ObjectMapper().findAndRegisterModules(); | ||
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); | ||
return objectMapper; | ||
} | ||
|
||
@Bean | ||
public LettuceConnectionFactory redisConnectionFactory() { | ||
RedisStandaloneConfiguration redisConfiguration = | ||
new RedisStandaloneConfiguration(redisHost, redisPort); | ||
redisConfiguration.setPassword(redisPwd); | ||
LettuceClientConfiguration lettuceConfig = | ||
LettuceClientConfiguration.builder().useSsl().build(); | ||
return new LettuceConnectionFactory(redisConfiguration, lettuceConfig); | ||
} | ||
|
||
@Bean | ||
@Qualifier("object") | ||
public RedisTemplate<String, byte[]> redisObjectTemplate( | ||
final LettuceConnectionFactory connectionFactory, ObjectMapper objectMapper) { | ||
RedisTemplate<String, byte[]> template = new RedisTemplate<>(); | ||
template.setKeySerializer(new StringRedisSerializer()); | ||
template.setConnectionFactory(connectionFactory); | ||
return template; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/it/gov/pagopa/bizeventsservice/model/PageInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package it.gov.pagopa.bizeventsservice.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
import javax.validation.constraints.Positive; | ||
import javax.validation.constraints.PositiveOrZero; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@ToString | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class PageInfo { | ||
|
||
@JsonProperty("page") | ||
@Schema(description = "Page number", required = true) | ||
@PositiveOrZero | ||
Integer page; | ||
|
||
@JsonProperty("limit") | ||
@Schema(description = "Required number of items per page", required = true) | ||
@Positive | ||
Integer limit; | ||
|
||
@JsonProperty("items_found") | ||
@Schema(description = "Number of items found. (The last page may have fewer elements than required)", required = true) | ||
@PositiveOrZero | ||
Integer itemsFound; | ||
|
||
@JsonProperty("total_pages") | ||
@Schema(description = "Total number of pages", required = true) | ||
@PositiveOrZero | ||
Integer totalPages; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/it/gov/pagopa/bizeventsservice/repository/redis/RedisRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package it.gov.pagopa.bizeventsservice.repository.redis; | ||
|
||
import java.time.Duration; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.stereotype.Component; | ||
|
||
|
||
@Component | ||
public class RedisRepository { | ||
|
||
@Autowired | ||
@Qualifier("object") | ||
private RedisTemplate<String, byte[]> redisTemplateObj; | ||
|
||
public void save(String key, byte[] value, long ttl) { | ||
redisTemplateObj.opsForValue().set(key, value, Duration.ofMinutes(ttl)); | ||
} | ||
|
||
public byte[] get(String key) { | ||
return redisTemplateObj.opsForValue().get(key); | ||
} | ||
|
||
public void remove(String key) { | ||
redisTemplateObj.delete(key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.