コード例 #1
0
            public Builder Port(int port)
            {
                SAssert.ArgumentBetween(() => port, 1, 65535);

                _settings.Port = port;
                return(this);
            }
コード例 #2
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();
        }
コード例 #3
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();
        }