RedisService.cs 931 B

1234567891011121314151617181920212223242526272829303132
  1. namespace IMCS.CCS.Common.Redis
  2. {
  3. using StackExchange.Redis;
  4. /// <summary>
  5. /// Redis 服务类
  6. /// </summary>
  7. public class RedisService : IRedisService
  8. {
  9. /// <summary>
  10. /// get database
  11. /// </summary>
  12. public IDatabase Database { get; }
  13. public IConnectionMultiplexer Multiplexer { get; }
  14. private readonly ConnectionMultiplexer _connectionMultiplexer;
  15. public RedisService(string connectionString)
  16. {
  17. this._connectionMultiplexer = ConnectionMultiplexer.Connect(connectionString);
  18. this.Database = _connectionMultiplexer.GetDatabase();
  19. this.Multiplexer = this.Database.Multiplexer;
  20. }
  21. public void Dispose()
  22. {
  23. if (this._connectionMultiplexer == null) return;
  24. this._connectionMultiplexer.Close();
  25. this._connectionMultiplexer.Dispose();
  26. }
  27. }
  28. }