diff --git a/src/EasyCaching.Redis/Configurations/RedisDatabaseProvider.cs b/src/EasyCaching.Redis/Configurations/RedisDatabaseProvider.cs index d5a8dcfb..28271019 100644 --- a/src/EasyCaching.Redis/Configurations/RedisDatabaseProvider.cs +++ b/src/EasyCaching.Redis/Configurations/RedisDatabaseProvider.cs @@ -1,4 +1,6 @@ -namespace EasyCaching.Redis +using Elastic.Apm.StackExchange.Redis; + +namespace EasyCaching.Redis { using StackExchange.Redis; using StackExchange.Redis.KeyspaceIsolation; @@ -17,6 +19,8 @@ public class RedisDatabaseProvider : IRedisDatabaseProvider /// private readonly RedisDBOptions _options; + private readonly bool _useApm; + /// /// The connection multiplexer. /// @@ -25,6 +29,7 @@ public class RedisDatabaseProvider : IRedisDatabaseProvider public RedisDatabaseProvider(string name, RedisOptions options) { _options = options.DBConfig; + _useApm = options.UseApm; _connectionMultiplexer = new Lazy(CreateConnectionMultiplexer); _name = name; } @@ -40,10 +45,14 @@ public IDatabase GetDatabase() { try { - var database = _connectionMultiplexer.Value.GetDatabase(); + if (!string.IsNullOrEmpty(_options.KeyPrefix)) database = database.WithKeyPrefix(_options.KeyPrefix); + + if (_useApm) + _connectionMultiplexer.Value.UseElasticApm(); + return database; } catch (Exception) @@ -131,4 +140,4 @@ private List GetMastersServersEndpoints() return masters; } } -} \ No newline at end of file +} diff --git a/src/EasyCaching.Redis/Configurations/RedisOptions.cs b/src/EasyCaching.Redis/Configurations/RedisOptions.cs index 278db56e..47490bd4 100644 --- a/src/EasyCaching.Redis/Configurations/RedisOptions.cs +++ b/src/EasyCaching.Redis/Configurations/RedisOptions.cs @@ -11,5 +11,10 @@ public RedisOptions() } public RedisDBOptions DBConfig { get; set; } = new RedisDBOptions(); + + /// + /// Whether or not to use Elastic APM, defaults to false + /// + public bool UseApm { get; set; } = false; } } diff --git a/src/EasyCaching.Redis/EasyCaching.Redis.csproj b/src/EasyCaching.Redis/EasyCaching.Redis.csproj index 3c526a83..707368b5 100644 --- a/src/EasyCaching.Redis/EasyCaching.Redis.csproj +++ b/src/EasyCaching.Redis/EasyCaching.Redis.csproj @@ -33,6 +33,7 @@ +