Skip to content

Commit

Permalink
Add test for reading many keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Mar 21, 2013
1 parent ef0cc25 commit f14cf36
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
12 changes: 6 additions & 6 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ func readLine(rd reader) ([]byte, error) {
}

func readN(rd reader, n int) ([]byte, error) {
buf, err := rd.ReadN(n)
b, err := rd.ReadN(n)
if err == bufio.ErrBufferFull {
newBuf := make([]byte, n)
r := copy(newBuf, buf)
buf = newBuf
newB := make([]byte, n)
r := copy(newB, b)
b = newB

for {
nn, err := rd.Read(buf[r:])
nn, err := rd.Read(b[r:])
r += nn
if r >= n {
// Ignore error if we read enough.
Expand All @@ -94,7 +94,7 @@ func readN(rd reader, n int) ([]byte, error) {
} else if err != nil {
return nil, err
}
return buf, nil
return b, nil
}

//------------------------------------------------------------------------------
Expand Down
9 changes: 9 additions & 0 deletions redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,15 @@ func (t *RedisTest) TestGetBigVal(c *C) {
c.Assert(get.Val(), Equals, val)
}

func (t *RedisTest) TestManyKeys(c *C) {
for i := 0; i < 100000; i++ {
t.client.Set("keys.key"+strconv.Itoa(i), "hello")
}
keys := t.client.Keys("keys.*")
c.Assert(keys.Err(), IsNil)
c.Assert(len(keys.Val()), Equals, 100000)
}

//------------------------------------------------------------------------------

func (t *RedisTest) TestConnPoolRemovesBrokenConn(c *C) {
Expand Down

0 comments on commit f14cf36

Please sign in to comment.