コード例 #1
0
            // Authentication settings for thread-wise pool, unused elsewhere.
            // TODO: Probably better to move this to the pool itself.
            public Builder Auth(string password)
            {
                SAssert.ArgumentSatisfy(() => password, v => !string.IsNullOrEmpty(v),
                                        "Password cannot be null or empty.");

                _settings.Password = password;
                return(this);
            }
コード例 #2
0
            public Builder Host(string host)
            {
                SAssert.ArgumentSatisfy(() => host, v => !string.IsNullOrEmpty(v),
                                        "Host cannot be null or empty.");

                _settings.Host = host;
                return(this);
            }
コード例 #3
0
        public RedisReader(Stream stream, RedisSettings settings)
        {
            SAssert.ArgumentNotNull(() => stream);
            SAssert.ArgumentSatisfy(() => stream, s => s.CanRead, "Stream must be readable.");
            SAssert.ArgumentNotNull(() => settings);

            _settings = settings;
            _stream   = new BufferedStream(stream, _settings.ReadBufferSize);
        }
コード例 #4
0
ファイル: RedisWriter.cs プロジェクト: git-thinh/cache_redis
        public void WriteTypeChar(ResponseType type)
        {
            SAssert.ArgumentSatisfy(() => type,
                                    v => Enum.IsDefined(typeof(ResponseType), v), "Invalid type char.");

            // assuming writebuffersize >= 1 so fitInBuffer(1) == true
            // the else case is for testing purpose
            _stream.WriteByte((byte)type);
            flushIfAuto();
        }
コード例 #5
0
        public LimitingStream(Stream inner, int bytesLimit)
        {
            SAssert.ArgumentNotNull(() => inner);
            SAssert.ArgumentNonNegative(() => bytesLimit);
            SAssert.ArgumentSatisfy(() => inner, s => s.CanRead,
                                    "Stream must be readable.");

            _inner     = inner;
            _bytesLeft = bytesLimit;
        }
コード例 #6
0
ファイル: RedisWriter.cs プロジェクト: git-thinh/cache_redis
        public RedisWriter(Stream stream, RedisSettings settings)
        {
            SAssert.ArgumentNotNull(() => stream);
            SAssert.ArgumentSatisfy(() => stream, s => s.CanWrite, "Stream must be writable.");
            SAssert.ArgumentNotNull(() => settings);

            _settings  = settings;
            _stream    = new BufferedStream(stream, _settings.WriteBufferSize);
            _strBuffer = new byte[_settings.EncodingBufferSize];

            AutoFlush = false;
        }
コード例 #7
0
ファイル: RedisWriter.cs プロジェクト: git-thinh/cache_redis
        public void WriteBulk(byte[] buffer, int offset, int count)
        {
            SAssert.ArgumentNotNull(() => buffer);

            if (!(offset == 0 && count == 0))
            {
                SAssert.ArgumentBetween(() => offset, 0, buffer.Length);
                SAssert.ArgumentBetween(() => count, 0, buffer.Length + 1);
            }

            SAssert.ArgumentSatisfy(() => offset, o => o + count <= buffer.Length,
                                    "Offset plus count is larger than the buffer.");

            _stream.Write(buffer, offset, count);
            writeCrLf();
        }
コード例 #8
0
        public void ReadBulk(byte[] buffer, int offset, int bulkLength)
        {
            SAssert.ArgumentNotNull(() => buffer);
            SAssert.ArgumentNonNegative(() => bulkLength);

            // special case for empty reads
            if (offset == 0 && bulkLength == 0)
            {
                return;
            }

            SAssert.ArgumentBetween(() => offset, 0, buffer.Length);
            SAssert.ArgumentSatisfy(() => offset, o => o + bulkLength <= buffer.Length,
                                    "Offset plus bulkLength is larger than the supplied buffer.");

            // read data from the stream, expect as much data as there's bulkLength
            var bytesRead = _stream.Read(buffer, 0, bulkLength);

            SAssert.IsTrue(bytesRead == bulkLength,
                           () => new ResponseException("Expected " + bulkLength.ToString() +
                                                       " bytes of bulk data, but only " + bytesRead.ToString() + " bytes are read."));

            readCrLf();
        }