public bool Connect(string connectionString) { options = RedisConnectionOptions.Parse(connectionString); redisClient = new RedisClient(options.Host, options.Port); redisClient.Connect(options); redisClient.Connected += (sender, args) => { EventNotify($"CsRedis Connected,Host:{options.Host}|Port:{options.Port}"); }; return(redisClient.IsConnected); }
private void InitConnections(RedisConnectionOptions options) { if (this.totalConnections < 1) { throw new ArgumentException("total connections must be greater than 0", nameof(this.totalConnections)); } this.connections = new IConnectionMultiplexer[this.totalConnections]; for (int i = 0; i < totalConnections; i++) { this.connections[i] = ConnectionMultiplexer.Connect(options.RedisConfigurationOptions); this.connections[i].PreserveAsyncOrder = false; } }
internal static RedisClient GetDatabaseRedisClient(ClientType clientType, RedisConnectionOptions options, string channelName = "", int dbIndex = -1, Action <string, Exception> eventNotify = null) { string clientName; if (clientType.Equals(ClientType.Sub)) { clientName = ClientType.Sub + "_" + channelName; } else { clientName = ClientType.Common + "_" + dbIndex; } RedisClient client = null; if (RedisPool.TryGetValue(clientName, out client)) { return(client); } lock (SynObject) { client = new RedisClient(options.Host, options.Port); client.Connect(options); if (clientType.Equals(ClientType.Common)) { client.Select(dbIndex); } if (eventNotify != null) { client.Connected += (sender, args) => { eventNotify($"CsRedis Connected,Host:{options.Host}|Port:{options.Port}", null); }; } RedisPool.TryAdd(clientName, client); return(client); } }
public RedisConnection(Action <RedisConnectionOptions> optionsBuilder) { Options = new RedisConnectionOptions(); optionsBuilder(Options); multiplexer_ = new Lazy <ConnectionMultiplexer>(() => ConnectionMultiplexer.Connect(Options.ConnectionString)); }