/// <summary> /// General purpose pipeline /// </summary> /// <param name="redisClient"></param> public RedisAllPurposePipeline(RedisClient redisClient) : base(redisClient) { Init(); }
protected void ClosePipeline() { RedisClient.EndPipeline(); }
/// <summary> /// Issue exec command (not queued) /// </summary> private void Exec() { RedisClient.Exec(); RedisClient.FlushAndResetSendBuffer(); }
public RedisClientHash(RedisClient client, string hashId) { this.client = client; this.hashId = hashId; }
public RedisTransaction(RedisClient redisClient) : base(redisClient) { }
public RedisCommandQueue(RedisClient redisClient) { this.RedisClient = redisClient; }
public RedisClientSet(RedisClient client, string setId) { this.client = client; this.setId = setId; }
public virtual RedisClient CreateRedisClient(RedisEndpoint config, bool master) { var client = ClientFactory(config); if (master) { var role = RedisServerRole.Unknown; try { role = client.GetServerRole(); if (role == RedisServerRole.Master) { lastValidMasterFromSentinelAt = DateTime.UtcNow; return(client); } } catch (Exception ex) { Interlocked.Increment(ref RedisState.TotalInvalidMasters); if (client.GetHostString() == lastInvalidMasterHost) { lock (oLock) { if (DateTime.UtcNow - lastValidMasterFromSentinelAt > sentinel.WaitBeforeForcingMasterFailover) { lastInvalidMasterHost = null; lastValidMasterFromSentinelAt = DateTime.UtcNow; log.Error("Valid master was not found at '{0}' within '{1}'. Sending SENTINEL failover...".Fmt( client.GetHostString(), sentinel.WaitBeforeForcingMasterFailover), ex); Interlocked.Increment(ref RedisState.TotalForcedMasterFailovers); sentinel.ForceMasterFailover(); Thread.Sleep(sentinel.WaitBetweenFailedHosts); role = client.GetServerRole(); } } } else { lastInvalidMasterHost = client.GetHostString(); } } if (role != RedisServerRole.Master && RedisConfig.VerifyMasterConnections) { try { var stopwatch = Stopwatch.StartNew(); while (true) { try { var masterConfig = sentinel.GetMaster(); var masterClient = ClientFactory(masterConfig); masterClient.ConnectTimeout = sentinel.SentinelWorkerConnectTimeoutMs; var masterRole = masterClient.GetServerRole(); if (masterRole == RedisServerRole.Master) { lastValidMasterFromSentinelAt = DateTime.UtcNow; return(masterClient); } else { Interlocked.Increment(ref RedisState.TotalInvalidMasters); } } catch { /* Ignore errors until MaxWait */ } if (stopwatch.Elapsed > sentinel.MaxWaitBetweenFailedHosts) { throw new TimeoutException("Max Wait Between Sentinel Lookups Elapsed: {0}" .Fmt(sentinel.MaxWaitBetweenFailedHosts.ToString())); } Thread.Sleep(sentinel.WaitBetweenFailedHosts); } } catch (Exception ex) { log.Error("Redis Master Host '{0}' is {1}. Resetting allHosts...".Fmt(config.GetHostString(), role), ex); var newMasters = new List <RedisEndpoint>(); var newSlaves = new List <RedisEndpoint>(); RedisClient masterClient = null; foreach (var hostConfig in allHosts) { try { var testClient = ClientFactory(hostConfig); testClient.ConnectTimeout = RedisConfig.HostLookupTimeoutMs; var testRole = testClient.GetServerRole(); switch (testRole) { case RedisServerRole.Master: newMasters.Add(hostConfig); if (masterClient == null) { masterClient = testClient; } break; case RedisServerRole.Slave: newSlaves.Add(hostConfig); break; } } catch { /* skip past invalid master connections */ } } if (masterClient == null) { Interlocked.Increment(ref RedisState.TotalNoMastersFound); var errorMsg = "No master found in: " + string.Join(", ", allHosts.Map(x => x.GetHostString())); log.Error(errorMsg); throw new Exception(errorMsg); } ResetMasters(newMasters); ResetSlaves(newSlaves); return(masterClient); } } } return(client); }
public RedisClientLists(RedisClient client) { this.client = client; }