123456789101112131415161718192021222324252627282930313233343536373839404142 |
- 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();
- /// <summary>
- /// redis连接对象,单例加锁不影响性能
- /// </summary>
- 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;
- }
- }
- }
- }
|