Skip to content

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

Merged
merged 9 commits into from
May 4, 2021

Conversation

JunTaoLuo
Copy link
Contributor

Replaces #31879.

FYI @napalm684 I recreated the PR since I couldn't push to your fork. We'll continue the PR here.

@JunTaoLuo JunTaoLuo added area-runtime community-contribution Indicates that the PR has been added by a community member feature-caching Includes: StackExchangeRedis and SqlServer distributed caches labels Apr 29, 2021
@JunTaoLuo JunTaoLuo self-assigned this Apr 29, 2021
@JunTaoLuo JunTaoLuo requested review from pranavkm and Tratcher April 29, 2021 09:02
@@ -284,7 +299,7 @@ private byte[] GetAndRefresh(string key, bool getData)
return results[2];
}

return null;
return EmptyByteArray;
Copy link
Contributor Author

@JunTaoLuo JunTaoLuo Apr 29, 2021

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

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@NapalmCodes
Copy link
Contributor

NapalmCodes commented Apr 29, 2021

Replaces #31879.

FYI @napalm684 I recreated the PR since I couldn't push to your fork. We'll continue the PR here.

@JunTaoLuo what can I do to help out? I would really like to see this through.

Copy link
Contributor

@pranavkm pranavkm left a 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;
Copy link
Contributor

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 },
Copy link
Contributor

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

Copy link
Contributor Author

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.

@JunTaoLuo
Copy link
Contributor Author

@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?

@pranavkm
Copy link
Contributor

pranavkm commented May 3, 2021

Yup. Let's not block on nullability if the underlying libraries haven't been updated as yet.

@JunTaoLuo JunTaoLuo merged commit d2b772b into main May 4, 2021
@JunTaoLuo JunTaoLuo deleted the johluo/connectionmultiplexer branch May 4, 2021 19:38
@ghost ghost added this to the 6.0-preview5 milestone May 4, 2021
@NapalmCodes
Copy link
Contributor

Thx @JunTaoLuo this was an enjoyable experience and I look forward to contributing more in the future!

@ghost
Copy link

ghost commented May 4, 2021

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.

@amcasey amcasey added area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares and removed area-runtime labels Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlewares community-contribution Indicates that the PR has been added by a community member feature-caching Includes: StackExchangeRedis and SqlServer distributed caches
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants