-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Add option to RedisCacheOptions to allow custom creation of IConnectionMultiplexer #32266
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
Conversation
Co-authored-by: Pranav K <[email protected]>
@@ -284,7 +299,7 @@ private byte[] GetAndRefresh(string key, bool getData) | |||
return results[2]; | |||
} | |||
|
|||
return null; | |||
return EmptyByteArray; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Tratcher this seems like the only option without external changes but it's a breaking change? We don't really want to do this though since it's breaking the API contract and is a breaking change.
Alternatively, should we ask to change dotnet/runtime's definition to byte[]? The benefit there is that the interface definition would actually match the description. https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.Caching.Abstractions/src/IDistributedCache.cs#L14-L19
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The API docs are clear that it returns null if the entry is not found. That's an important distinction because an empty entry and a missing entry can be semantically different.
Let's get the nullability fixed on IDistributedCache.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is anything I can do to assist here I am game/able.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I filed: dotnet/runtime#52148, we'll need that before we can enable nullability properly on this PR.
@JunTaoLuo what can I do to help out? I would really like to see this through. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Please get @Tratcher to sign off on the breaking changes
|
||
private volatile ConnectionMultiplexer _connection; | ||
private IDatabase _cache; | ||
private volatile IConnectionMultiplexer? _connection; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea why this is volatile?
@@ -107,7 +108,7 @@ public void Set(string key, byte[] value, DistributedCacheEntryOptions options) | |||
|
|||
var absoluteExpiration = GetAbsoluteExpiration(creationTime, options); | |||
|
|||
var result = _cache.ScriptEvaluate(SetScript, new RedisKey[] { _instance + key }, | |||
var result = _cache!.ScriptEvaluate(SetScript, new RedisKey[] { _instance + key }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can annotate Connect
and ConnectAsync
with [MemberNotNull(nameof(_cache))]
to avoid the null forgiveness
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had trouble applying MemberNotNull on ConnectAsync, we can chat about it when you are back.
@pranavkm It's unclear to me when dotnet/runtime will address dotnet/runtime#52148. Should we undo our nullability changes here and update the nullability of the APIs when we are unblocked? |
Yup. Let's not block on nullability if the underlying libraries haven't been updated as yet. |
Thx @JunTaoLuo this was an enjoyable experience and I look forward to contributing more in the future! |
Hi @napalm684. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context. |
Replaces #31879.
FYI @napalm684 I recreated the PR since I couldn't push to your fork. We'll continue the PR here.