Exemplo n.º 1
0
        //public IAutoPipelineOption AutoPipeline => _autoPipeline;
        //AutoPipelineOption _autoPipeline;

        public T Call <T>(RedisCommand <T> command)
        {
            ConnectIfNotConnected();

#if !net40
            var operationId = Guid.Empty;
            var key         = command.Arguments.Length > 0 ? command.Arguments[0].ToString() : "";
#endif

            try
            {
                if (IsPipelined)
                {
                    return(_io.Pipeline.Write(command));
                }

                //if (_autoPipeline.IsEnabled)
                //	return _autoPipeline.EnqueueSync(command);

                //Console.WriteLine("--------------Call " + command.ToString());
#if !net40
                operationId = _diagnosticListener.WriteCallBefore(new CallEventData(command.Command, key));
#endif
                _io.Write(_io.Writer.Prepare(command));
                var res = command.Parse(_io.Reader);
#if !net40
                _diagnosticListener.WriteCallAfter(operationId, new CallEventData(command.Command, key));
#endif
                return(res);
            }
            catch (IOException)
            {
                if (ReconnectAttempts == 0)
                {
                    throw;
                }
                Reconnect();
                return(Call(command));
            }
            catch (RedisException ex)
            {
#if !net40
                _diagnosticListener.WriteCallError(operationId, new CallEventData(command.Command, key), ex);
#endif
                throw new RedisException($"{ex.Message}\r\nCommand: {command}", ex);
            }
        }