using StackExchange.Redis; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace OASystem.RedisRepository.Config { public class RedisConnection { private static ConnectionMultiplexer _connection; private static readonly object SyncObject = new object(); /// /// redis连接对象,单例加锁不影响性能 /// public static ConnectionMultiplexer GenerateConnection { get { if (_connection == null || !_connection.IsConnected) { lock (SyncObject) { var configurationOptions = new ConfigurationOptions() { Password = RedisClientConfig.RedisAuth, EndPoints = { {RedisClientConfig.Server, RedisClientConfig.Port} //,{RedisClientConfig.SlaveServer, RedisClientConfig.SlavePort} } }; _connection = ConnectionMultiplexer.Connect(configurationOptions); } } return _connection; } } } }