Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@viztea
Copy link

@viztea viztea commented May 22, 2021

  • Adds a property for configuring the TTL of a value
  • Adds a property for the command to use, hset or set

@viztea viztea changed the title Config improvements Redis config improvements May 22, 2021
Copy link
Contributor

@BartArys BartArys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR! Since I've got little experience with Redis I'd like to ask some clarifying questions though.

Comment on lines 48 to 51
val mono = when (command) {
RedisCommand.HashSet -> info.commands.hset(info.entryName, key, value)
RedisCommand.Set -> info.commands.set(key, value)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the impression that hashing was always advised over non-hashing. What would be some situations where not using a hash is beneficial?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afaik you can't set a TTL for individual hash values but you can with a set

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reading up on it seems like trying to expire a hset would result in the entire has being expired, so you're right there.

If that's the only practical difference though, we shouldn't allow choosing both a command and a TTL, the two decisions depend on eachother.

Copy link
Author

@viztea viztea May 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe something like this?

sealed class RedisCommand {
  object HashSet : RedisCommand()
  data class Set(val ttl: Long? = null) : RedisCommand()
}

Comment on lines 58 to 60
fun <T> Mono<T>.cache(ttl: Duration?): Mono<T> {
return if (ttl != null) cache(ttl.toJavaDuration()) else this
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this just cache the mono? I was under the impression you need to call something like RedisKeyReactiveCommands#expire to inform redis of a key's TTL.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. I'm not very familiar with lettuce or rxjava to begin with, I'll switch it over.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants