Пример #1
0
        protected internal virtual RedisString ExpectSimpleString(RedisCommand command, bool throwException = true)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            ValidateNotDisposed();

            using (var connection = Connect(command.DbIndex, command.Role))
            {
                return(command.ExpectSimpleString(connection, throwException));
            }
        }
Пример #2
0
        protected internal override RedisString ExpectSimpleString(RedisCommand command, bool throwException = true)
        {
            using (var result = TryToExecuteAsync <RedisString>(command, RedisCommandExpect.SimpleString, (string)null))
            {
                if (result.Handled)
                {
                    return(result.Result);
                }

                using (var connection = (result.UsingConnection() ?? Connect(command.DbIndex, command.Role)))
                {
                    return(command.ExpectSimpleString(connection, throwException));
                }
            }
        }
Пример #3
0
            public RedisHeartBeatPulseResult Pulse()
            {
                if (Interlocked.CompareExchange(ref m_PulseState, RedisConstants.One, RedisConstants.Zero) ==
                    RedisConstants.Zero)
                {
                    try
                    {
                        if (!Disposed)
                        {
                            lock (m_SyncRoot)
                            {
                                var socket = m_Socket;
                                if (socket.IsConnected(10))
                                {
                                    var settings = m_Settings;
                                    if (settings != null)
                                    {
                                        using (var cmd = new RedisCommand(-1, RedisCommandList.Ping))
                                        {
                                            cmd.ExpectSimpleString(new RedisSocketContext(socket, settings), RedisConstants.PONG);
                                        }
                                    }
                                }
                            }

                            Interlocked.Add(ref m_PulseFailCount, RedisConstants.Zero);
                            return(RedisHeartBeatPulseResult.Success);
                        }
                    }
                    catch (Exception)
                    {
                        if (Interlocked.Read(ref m_PulseFailCount) < long.MaxValue)
                        {
                            Interlocked.Add(ref m_PulseFailCount, RedisConstants.One);
                        }
                        return(RedisHeartBeatPulseResult.Failed);
                    }
                    finally
                    {
                        Interlocked.Exchange(ref m_PulseState, RedisConstants.Zero);
                    }
                }
                return(RedisHeartBeatPulseResult.Unknown);
            }
Пример #4
0
 protected internal virtual bool Ping(bool forceNewConnection = false)
 {
     if (!Disposed)
     {
         try
         {
             var result = false;
             using (var connection = NewConnection(Settings))
             {
                 using (var cmd = new RedisCommand(-1, RedisCommandList.Ping))
                 {
                     var pong = cmd.ExpectSimpleString(connection);
                     result = (pong == RedisConstants.PONG);
                 }
             }
             return(result);
         }
         catch (Exception)
         { }
     }
     return(false);
 }
Пример #5
0
        protected internal override T Expect <T>(RedisCommand command, RedisCommandExpect expectation, string okIf = null)
        {
            using (var connection = Connect())
            {
                switch (expectation)
                {
                case RedisCommandExpect.Response:
                    return((T)(object)command.Execute(connection, ThrowOnError));

                case RedisCommandExpect.Array:
                    return((T)(object)command.ExpectArray(connection, ThrowOnError));

                case RedisCommandExpect.BulkString:
                    return((T)(object)command.ExpectBulkString(connection, ThrowOnError));

                case RedisCommandExpect.BulkStringBytes:
                    return((T)(object)command.ExpectBulkStringBytes(connection, ThrowOnError));

                case RedisCommandExpect.Double:
                    return((T)(object)command.ExpectDouble(connection, ThrowOnError));

                case RedisCommandExpect.GreaterThanZero:
                    return((T)(object)command.ExpectInteger(connection, ThrowOnError));

                case RedisCommandExpect.Integer:
                    return((T)(object)command.ExpectInteger(connection, ThrowOnError));

                case RedisCommandExpect.MultiDataBytes:
                    return((T)(object)command.ExpectMultiDataBytes(connection, ThrowOnError));

                case RedisCommandExpect.MultiDataStrings:
                    return((T)(object)command.ExpectMultiDataStrings(connection, ThrowOnError));

                case RedisCommandExpect.Nothing:
                    return((T)(object)command.ExpectNothing(connection, ThrowOnError));

                case RedisCommandExpect.NullableDouble:
                    return((T)(object)command.ExpectNullableDouble(connection, ThrowOnError));

                case RedisCommandExpect.NullableInteger:
                    return((T)(object)command.ExpectNullableInteger(connection, ThrowOnError));

                case RedisCommandExpect.OK:
                    return((T)(object)command.ExpectOK(connection, ThrowOnError));

                case RedisCommandExpect.One:
                    return((T)(object)command.ExpectOne(connection, ThrowOnError));

                case RedisCommandExpect.SimpleString:
                    if (!okIf.IsEmpty())
                    {
                        return((T)(object)command.ExpectSimpleString(connection, okIf, ThrowOnError));
                    }
                    return((T)(object)command.ExpectSimpleString(connection, ThrowOnError));

                case RedisCommandExpect.SimpleStringBytes:
                    if (!okIf.IsEmpty())
                    {
                        return((T)(object)command.ExpectSimpleStringBytes(connection, okIf.ToBytes(), ThrowOnError));
                    }
                    return((T)(object)command.ExpectSimpleStringBytes(connection, ThrowOnError));

                default:
                    throw new RedisException(String.Format("Undefined expectation type, {0}", expectation.ToString("F")), RedisErrorCode.NotSupported);
                }
            }
        }