Skip to content

RedisCacheOptions to Manually Set ConnectionMultiplexer #31879

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

Closed
wants to merge 6 commits into from
Closed

RedisCacheOptions to Manually Set ConnectionMultiplexer #31879

wants to merge 6 commits into from

Conversation

NapalmCodes
Copy link
Contributor

@NapalmCodes NapalmCodes commented Apr 16, 2021

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

PR Title
RedisCacheOptions to Manually Set ConnectionMultiplexer

PR Description
Adding a Factory Func to allow manual setting of the ConnectionMultiplexer for Redis.
Implemented for both Async and Sync method paths.

Addresses #28379

@NapalmCodes NapalmCodes requested review from JunTaoLuo and a team as code owners April 16, 2021 18:38
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Apr 16, 2021
@dnfadmin
Copy link

dnfadmin commented Apr 16, 2021

CLA assistant check
All CLA requirements met.

@Pilchie Pilchie added area-runtime feature-caching Includes: StackExchangeRedis and SqlServer distributed caches labels Apr 19, 2021
/// <summary>
/// Gets or sets a delegate to create the ConnectionMultiplexer instance.
/// </summary>
public Func<IConnectionMultiplexer> ConnectionMultiplexerFactory { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be nullable?

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public Func<IConnectionMultiplexer> ConnectionMultiplexerFactory { get; set; }
[DisallowNull]
public Func<Task<IConnectionMultiplexer>>? ConnectionMultiplexerFactory { get; set; }

Copy link
Contributor Author

@NapalmCodes NapalmCodes Apr 26, 2021

Choose a reason for hiding this comment

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

What is making this a Task return type buying us exactly?

Copy link
Contributor

Choose a reason for hiding this comment

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

@davidfowl mentioned creating the connection involved I/O. This was meant to reflect that.

Copy link
Contributor

Choose a reason for hiding this comment

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

The Func will likely include an async call e.g. ConnectionMultiplexer.ConnectAsync and this way, the Func can be awaited in other components to get the same connection.

Copy link
Contributor Author

@NapalmCodes NapalmCodes Apr 27, 2021

Choose a reason for hiding this comment

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

@JunTaoLuo and @pranavkm I am having some issues with this. Nullable annotations does not appear to be enabled in this class yet:

/Users/dev-spv/aspnetcore/src/Caching/StackExchangeRedis/src/RedisCacheOptions.cs(32,65): error CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. [/Users/dev-spv/aspnetcore/src/Caching/StackExchangeRedis/src/Microsoft.Extensions.Caching.StackExchangeRedis.csproj]

I am willing to add these annotations if desired, but I had a ton of issues trying to satisfy the Roslyn Unshipped API file changes with VSCode. Specifically it would not recognize the get as public even though it recognized it was part of the API. Below is what I could not get working in the unshipped text file even when I did have #nullable enabled at the top of the class:

Microsoft.Extensions.Caching.StackExchangeRedis.RedisCacheOptions.ConnectionMultiplexerFactory.get -> System.Func<System.Threading.Tasks.Task<StackExchange.Redis.IConnectionMultiplexer>>? Microsoft.Extensions.Caching.StackExchangeRedis.RedisCacheOptions.ConnectionMultiplexerFactory.set -> void

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll take a look.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's continue the conversation at #32266

@JunTaoLuo JunTaoLuo closed this Apr 29, 2021
@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.

6 participants