-
Notifications
You must be signed in to change notification settings - Fork 47
Setting client lib name properly by wrapping multiplxer creation #420
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
Open
atakavci
wants to merge
5
commits into
redis:master
Choose a base branch
from
atakavci:ali/set_lib_name
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using StackExchange.Redis; | ||
|
||
namespace NRedisStack; | ||
|
||
/// <summary> | ||
/// This class is EXPERIMENTAL!! and may change or removed in future releases. | ||
/// Interface that provides access to Redis commands | ||
/// including Search, JSON, TimeSeries, Bloom and more.. | ||
/// </summary> | ||
public interface IRedisDatabase : IDatabase | ||
{ | ||
/// <summary> | ||
/// Gets a command set for interacting with the RedisBloom Bloom Filter module. | ||
/// </summary> | ||
/// <returns>Command set for Bloom Filter operations.</returns> | ||
public BloomCommands BF(); | ||
|
||
/// <summary> | ||
/// Gets a command set for interacting with the RedisBloom Count-Min Sketch module. | ||
/// </summary> | ||
/// <returns>Command set for Count-Min Sketch operations.</returns> | ||
public CmsCommands CMS(); | ||
|
||
/// <summary> | ||
/// Gets a command set for interacting with the RedisBloom Cuckoo Filter module. | ||
/// </summary> | ||
/// <returns>Command set for Cuckoo Filter operations.</returns> | ||
public CuckooCommands CF(); | ||
|
||
/// <summary> | ||
/// Gets a command set for interacting with the RedisJSON module. | ||
/// </summary> | ||
/// <returns>Command set for JSON operations.</returns> | ||
public JsonCommands JSON(); | ||
|
||
/// <summary> | ||
/// Gets a command set for interacting with the RediSearch module. | ||
/// </summary> | ||
/// <param name="searchDialect">The search dialect version to use. Defaults to 2.</param> | ||
/// <returns>Command set for search operations.</returns> | ||
public SearchCommands FT(int? searchDialect = 2); | ||
|
||
/// <summary> | ||
/// Gets a command set for interacting with the Redis t-digest module. | ||
/// </summary> | ||
/// <returns>Command set for t-digest operations.</returns> | ||
public TdigestCommands TDIGEST(); | ||
|
||
/// <summary> | ||
/// Gets a command set for interacting with the RedisTimeSeries module. | ||
/// </summary> | ||
/// <returns>Command set for time series operations.</returns> | ||
public TimeSeriesCommands TS(); | ||
|
||
/// <summary> | ||
/// Gets a command set for interacting with the RedisBloom TopK module. | ||
/// </summary> | ||
/// <returns>Command set for TopK operations.</returns> | ||
public TopKCommands TOPK(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
using StackExchange.Redis; | ||
|
||
namespace NRedisStack; | ||
|
||
/// <summary> | ||
/// This class is EXPERIMENTAL!! and may change or removed in future releases. | ||
/// Represents a Redis client that can connect to a Redis server | ||
/// providing access to <see cref="IRedisDatabase"/> instances as well as the underlying multiplexer. | ||
/// </summary> | ||
public class RedisClient | ||
{ | ||
private ConnectionMultiplexer _multiplexer; | ||
|
||
private RedisClient(ConnectionMultiplexer multiplexer) | ||
{ | ||
_multiplexer = multiplexer; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new <see cref="RedisClient"/> instance. | ||
/// </summary> | ||
/// <param name="configuration">The string configuration to use for this client.</param> | ||
/// <param name="log">The <see cref="TextWriter"/> to log to.</param> | ||
public static async Task<RedisClient> ConnectAsync(string configuration, TextWriter? log = null) => | ||
await ConnectAsync(ConfigurationOptions.Parse(configuration), log); | ||
|
||
/// <summary> | ||
/// Creates a new <see cref="RedisClient"/> instance. | ||
/// </summary> | ||
/// <param name="configuration">The string configuration to use for this client.</param> | ||
/// <param name="configure">Action to further modify the parsed configuration options.</param> | ||
/// <param name="log">The <see cref="TextWriter"/> to log to.</param> | ||
public static async Task<RedisClient> ConnectAsync(string configuration, Action<ConfigurationOptions> configure, TextWriter? log = null) | ||
{ | ||
Action<ConfigurationOptions> config = (ConfigurationOptions config) => | ||
{ | ||
configure?.Invoke(config); | ||
SetNames(config); | ||
}; | ||
return new RedisClient(await ConnectionMultiplexer.ConnectAsync(configuration, configure, log)); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new <see cref="ConnectionMultiplexer"/> instance. | ||
/// </summary> | ||
/// <param name="configuration">The configuration options to use for this client.</param> | ||
/// <param name="log">The <see cref="TextWriter"/> to log to.</param> | ||
/// <remarks>Note: For Sentinel, do <b>not</b> specify a <see cref="ConfigurationOptions.CommandMap"/> - this is handled automatically.</remarks> | ||
public static async Task<RedisClient> ConnectAsync(ConfigurationOptions configuration, TextWriter? log = null) | ||
{ | ||
SetNames(configuration); | ||
return new RedisClient(await ConnectionMultiplexer.ConnectAsync(configuration, log)); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new <see cref="RedisClient"/> instance. | ||
/// </summary> | ||
/// <param name="configuration">The string configuration to use for this client.</param> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Link back to docs |
||
/// <param name="log">The <see cref="TextWriter"/> to log to.</param> | ||
public static RedisClient Connect(string configuration, TextWriter? log = null) => | ||
Connect(ConfigurationOptions.Parse(configuration), log); | ||
|
||
/// <summary> | ||
/// Creates a new <see cref="RedisClient"/> instance. | ||
/// </summary> | ||
/// <param name="configuration">The string configuration to use for this client.</param> | ||
/// <param name="configure">Action to further modify the parsed configuration options.</param> | ||
/// <param name="log">The <see cref="TextWriter"/> to log to.</param> | ||
public static RedisClient Connect(string configuration, Action<ConfigurationOptions> configure, TextWriter? log = null) | ||
{ | ||
Action<ConfigurationOptions> config = (ConfigurationOptions config) => | ||
{ | ||
configure?.Invoke(config); | ||
SetNames(config); | ||
}; | ||
return new RedisClient(ConnectionMultiplexer.Connect(configuration, configure, log)); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new <see cref="RedisClient"/> instance. | ||
/// </summary> | ||
/// <param name="configuration">The configuration options to use for this client.</param> | ||
/// <param name="log">The <see cref="TextWriter"/> to log to.</param> | ||
/// <remarks>Note: For Sentinel, do <b>not</b> specify a <see cref="ConfigurationOptions.CommandMap"/> - this is handled automatically.</remarks> | ||
public static RedisClient Connect(ConfigurationOptions configuration, TextWriter? log = null) | ||
{ | ||
SetNames(configuration); | ||
return new RedisClient(ConnectionMultiplexer.Connect(configuration, log)); | ||
} | ||
|
||
/// <summary> | ||
/// Gets a database instance. | ||
/// </summary> | ||
/// <param name="db">The ID to get a database for.</param> | ||
/// <param name="asyncState">The async state to pass into the resulting <see cref="RedisDatabase"/>.</param> | ||
/// <returns></returns> | ||
public IRedisDatabase GetDatabase(int db = -1, object? asyncState = null) | ||
{ | ||
var idatabase = _multiplexer.GetDatabase(db, asyncState); | ||
return new RedisDatabase(idatabase); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the underlying <see cref="ConnectionMultiplexer"/> instance. | ||
/// </summary> | ||
/// <returns></returns> | ||
public ConnectionMultiplexer GetMultiplexer() | ||
{ | ||
return _multiplexer; | ||
} | ||
|
||
private static void SetNames(ConfigurationOptions config) | ||
{ | ||
if (config.LibraryName == null) | ||
{ | ||
config.LibraryName = Auxiliary.GetNRedisStackLibName(); | ||
} | ||
|
||
if (config.ClientName == null) | ||
{ | ||
config.ClientName = (Environment.MachineName ?? Environment.GetEnvironmentVariable("ComputerName") ?? "Unknown") + $"-NRedisStack(.NET_v{Environment.Version})"; | ||
} | ||
} | ||
} | ||
|
||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using NRedisStack.RedisStackCommands; | ||
using StackExchange.Redis; | ||
|
||
namespace NRedisStack; | ||
|
||
internal class RedisDatabase : DatabaseWrapper, IRedisDatabase | ||
{ | ||
public RedisDatabase(IDatabase db) : base(db) { } | ||
|
||
public BloomCommands BF() => new BloomCommands(_db); | ||
|
||
public CuckooCommands CF() => new CuckooCommands(_db); | ||
|
||
public CmsCommands CMS() => new CmsCommands(_db); | ||
|
||
public TopKCommands TOPK() => new TopKCommands(_db); | ||
|
||
public TdigestCommands TDIGEST() => new TdigestCommands(_db); | ||
|
||
public SearchCommands FT(int? searchDialect = 2) => new SearchCommands(_db, searchDialect); | ||
|
||
public JsonCommands JSON() => new JsonCommands(_db); | ||
|
||
public TimeSeriesCommands TS() => new TimeSeriesCommands(_db); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This should be lifted out into an interface
IRedisClient
and should take anIConnectionMultiplexer
in all the places.