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

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

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

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

                //Console.WriteLine("--------------Call " + command.ToString());
                _io.Write(_io.Writer.Prepare(command));
                return(command.Parse(_io.Reader));
            }
            catch (IOException)
            {
                if (ReconnectAttempts == 0)
                {
                    throw;
                }
                Reconnect();
                return(Call(command));
            }
            catch (RedisException ex)
            {
                throw new RedisException($"{ex.Message}\r\nCommand: {command}", ex);
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        public T Call <T>(RedisCommand <T> command)
        {
            ConnectIfNotConnected();

            try
            {
                _io.Write(_io.Writer.Prepare(command));
                return(command.Parse(_io.Reader));
            }
            catch (IOException)
            {
                if (ReconnectAttempts == 0)
                {
                    throw;
                }
                Reconnect();
                return(Call(command));
            }
            catch (RedisException ex)
            {
                throw new RedisException($"{ex.Message}\r\nCommand: {command}", ex);
            }
        }
Exemplo n.º 4
0
        public object[] Flush()
        {
            try
            {
                object[] results = new object[0];
                if (_parsers.IsEmpty == false)
                {
                    lock (_bufferLock)
                    {
                        if (_parsers.IsEmpty == false)
                        {
                            _buffer.Position = 0;
                            //Console.WriteLine(Encoding.UTF8.GetString(_buffer.ToArray()));
                            _io.Write(_buffer);

                            _buffer.SetLength(0);

                            results = new object[_parsers.Count];
                        }
                    }
                }

                for (int i = 0; i < results.Length; i++)
                {
                    if (_parsers.TryDequeue(out var func))
                    {
                        try
                        {
                            results[i] = func();
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                }

                return(results);
            }
            finally
            {
                Active = false;
            }
        }