Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time to live not set when using save when using @PostConstruct #458

Open
GohKianSeng opened this issue Jun 8, 2024 · 8 comments
Open

Time to live not set when using save when using @PostConstruct #458

GohKianSeng opened this issue Jun 8, 2024 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@GohKianSeng
Copy link

hello this is my entity model.
set the time to live but in redis insight, show no limit.

image image

`@Document("TestResultRedis", timeToLive = 5 * 60)
data class TestResultRedisModel(
@id
val id: Long?,

@Searchable
val uuid: String?,

@Searchable
val uatId: String?,

@Searchable
val msgType: String?,

@Searchable
val filename: String?,

@Searchable
val status: String?,

@Searchable
val result: String?,

val overrideStatus: String?,

val remarksSnapshotId: Long?,

@Searchable
val actualCodes: List<String>,

val mappedActualCodes: List<String>,

@Searchable
val expectedCodes: List<String>,

val mappedExpectedCodes: List<String>,

@Searchable
val expectedUserCodes: List<String>,

val batchJobStatus: String?,

val expectedBatchJobStatus: String?,

val expectedUserBatchJobStatus: String?,

@Searchable
val remark: String?,

val remarkDate: String?,

val remarkUuid: String?,

@Searchable
val remarkHashTags: List<String>?,

@Searchable
val assignee: String?,

val user: String?,

@Searchable
var kivIndicator: Boolean?,

@Searchable
val manualIndicator: Boolean?,

val overwrite: Boolean?

)`

@GohKianSeng
Copy link
Author

just realised if i used saveAll. the Time to live is set.
is that a bug?

image

@bsbodden
Copy link
Contributor

bsbodden commented Jun 8, 2024

Sounds like a bug! Did you just used save?

@bsbodden bsbodden self-assigned this Jun 8, 2024
@bsbodden bsbodden added bug Something isn't working labels Jun 8, 2024
@bsbodden bsbodden changed the title Time to live not set. Time to live not set when using save Jun 8, 2024
@GohKianSeng
Copy link
Author

yes i used repository.save

@GohKianSeng
Copy link
Author

GohKianSeng commented Jun 10, 2024

hello @bsbodden for saveAll also has issue i guess.

the controller save() has TTL set.
image

but using PostConstruct doesn't work
image

Redis Insight
image

@bsbodden
Copy link
Contributor

@GohKianSeng I can't seem to be able to replicate the issue, could you create a simple reproducer app? Just models, repository and a CommandLineRunner to run your scenario?

@bsbodden bsbodden changed the title Time to live not set when using save Time to live not set when using save when using @PostConstruct Jun 11, 2024
@bsbodden
Copy link
Contributor

@GohKianSeng I don't think we have added support for @PostConstruct, that might be the root of the issue here

@nexlink-giangbui
Copy link

nexlink-giangbui commented Sep 17, 2024

Hi @bsbodden,

I discovered that in a Spring Boot project, when using spring-boot-devtools, the application runs with the org.springframework.boot.devtools.restart.classloader.RestartClassLoader class loader, instead of the jdk.internal.loader.ClassLoaders class loader (which is used by Spring OM). This difference causes an issue where Spring OM cannot load the KeyspaceConfiguration for an entity in the method:

com.redis.om.spring.RedisJSONKeyValueAdapter.getTTLForEntity(Object entity)

The problem arises because the line:

entityClassKey = ClassLoader.getSystemClassLoader().loadClass(entity.getClass().getTypeName())

returns an entityClassKey that is not present in the KeyspaceConfiguration.settingsMap

In the context of @SpringBootTest, the jdk.internal.loader.ClassLoaders class loader is used, which is why TTL works in the unit test environment, but fails in the application context when spring-boot-devtools is enabled.

A temporary fix for this issue is to disable spring-boot-devtools.

@bsbodden
Copy link
Contributor

@nexlink-giangbui thanks for the investigation! The RestartClassLoader getting in the way of low level stuff is a recurring theme, I'm looking into ways to get to the correct classloader in that scenario. Stay tuned!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants