T[] SReadArray <T>(CommandPacket cb) => Call(cb.FlagReadbytes(true), rt => rt .ThrowOrValue((a, _) => a == null || a.Length == 0 ? new T[0] : a.Select(b => DeserializeRedisValue <T>(b.ConvertTo <byte[]>(), rt.Encoding)).ToArray()));
public abstract Task <TValue> AdapterCallAsync <TValue>(CommandPacket cmd, Func <RedisResult, TValue> parse);
public override IRedisSocket GetRedisSocket(CommandPacket cmd) { throw new RedisClientException($"RedisClient: Method cannot be used in {UseType} mode."); }
public override Task <TValue> AdapterCallAsync <TValue>(CommandPacket cmd, Func <RedisResult, TValue> parse) { //Single socket not support Async Multiplexing return(Task.FromResult(AdapterCall(cmd, parse))); }
public abstract IRedisSocket GetRedisSocket(CommandPacket cmd);
public override IRedisSocket GetRedisSocket(CommandPacket cmd) { return(DefaultRedisSocket.CreateTempProxy(_redisSocket, null)); }
public override TValue AdapterCall <TValue>(CommandPacket cmd, Func <RedisResult, TValue> parse) { return(TopOwner.LogCall(cmd, () => { RedisResult rt = null; RedisClientPool pool = null; using (var rds = GetRedisSocket(cmd)) { pool = (rds as DefaultRedisSocket.TempProxyRedisSocket)._pool; try { if (cmd._clusterMovedAsking) { cmd._clusterMovedAsking = false; rds.Write("ASKING"); rds.Read(false); } rds.Write(cmd); rt = rds.Read(cmd._flagReadbytes); } catch (Exception ex) { if (pool?.SetUnavailable(ex) == true) { } throw ex; } } if (rt.IsError && pool != null) { var moved = ClusterMoved.ParseSimpleError(rt.SimpleError); if (moved != null && cmd._clusterMovedTryCount < 3) { cmd._clusterMovedTryCount++; if (moved.endpoint.StartsWith("127.0.0.1")) { moved.endpoint = $"{DefaultRedisSocket.SplitHost(pool._policy._connectionStringBuilder.Host).Key}:{moved.endpoint.Substring(10)}"; } else if (moved.endpoint.StartsWith("localhost", StringComparison.CurrentCultureIgnoreCase)) { moved.endpoint = $"{DefaultRedisSocket.SplitHost(pool._policy._connectionStringBuilder.Host).Key}:{moved.endpoint.Substring(10)}"; } ConnectionStringBuilder connectionString = pool._policy._connectionStringBuilder.ToString(); connectionString.Host = moved.endpoint; RegisterClusterNode(connectionString); if (moved.ismoved) { _slotCache.AddOrUpdate(moved.slot, connectionString.Host, (k1, v1) => connectionString.Host); } if (moved.isask) { cmd._clusterMovedAsking = true; } TopOwner.OnNotice(new NoticeEventArgs(NoticeType.Info, null, $"{(cmd.WriteHost ?? "Not connected")} > {cmd}\r\n{rt.SimpleError} ", null)); return AdapterCall(cmd, parse); } } rt.IsErrorThrow = TopOwner._isThrowRedisSimpleError; return parse(rt); })); }
protected TValue Call <TValue>(CommandPacket cmd, Func <RedisResult, TValue> parse) => Adapter.AdapterCall(cmd, parse);
public object Call(CommandPacket cmd) => Adapter.AdapterCall(cmd, rt => rt.ThrowOrValue());
//public Task<object> CallAsync(CommandPacket cmd) => Adapter.AdapterCallAsync(cmd, rt => rt.ThrowOrValue()); protected Task <TValue> CallAsync <TValue>(CommandPacket cmd, Func <RedisResult, TValue> parse) => Adapter.AdapterCallAsync(cmd, parse);