Skip to content

Commit

Permalink
Merge d08a840 into f4f0cfb
Browse files Browse the repository at this point in the history
  • Loading branch information
junmipan committed Aug 17, 2017
2 parents f4f0cfb + d08a840 commit e3c5c21
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 9 additions & 3 deletions db/keyval/redis/bytes_broker_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,16 @@ func (db *BytesConnectionRedis) GetValue(key string) (data []byte, found bool, r
}

// ListKeys returns an iterator used to traverse keys that start with the given match string.
// When done traversing, you must close the iterator by calling its Close() method.
func (db *BytesConnectionRedis) ListKeys(match string) (keyval.BytesKeyIterator, error) {
if db.closed {
return nil, fmt.Errorf("ListKeys(%s) called on a closed connection", match)
}
return listKeys(db, match, nil, nil)
}

// ListValues lists values for all the keys that start with the given match string.
// ListValues returns an iterator used to traverse key value pairs for all the keys that start with the given match string.
// When done traversing, you must close the iterator by calling its Close() method.
func (db *BytesConnectionRedis) ListValues(match string) (keyval.BytesKeyValIterator, error) {
if db.closed {
return nil, fmt.Errorf("ListValues(%s) called on a closed connection", match)
Expand Down Expand Up @@ -193,12 +195,13 @@ func (db *BytesConnectionRedis) Delete(key string, opts ...keyval.DelOption) (fo
return (intCmd.Val() != 0), nil
}

// Close closes the iterator. Returns error, if any. Otherwise, nil.
func (it *bytesKeyIterator) Close() error {
return it.err
}

// GetNext returns the next item from the iterator.
// If the iterator has reached the last item previously, lastReceived is set to true.
// If the iterator encounters error or has reached the last item previously, lastReceived is set to true.
func (it *bytesKeyIterator) GetNext() (key string, rev int64, lastReceived bool) {
if it.err != nil {
return "", 0, true
Expand Down Expand Up @@ -229,12 +232,13 @@ func (it *bytesKeyIterator) GetNext() (key string, rev int64, lastReceived bool)
return key, 0, false
}

// Close closes the iterator. Returns error, if any. Otherwise, nil.
func (it *bytesKeyValIterator) Close() error {
return it.err
}

// GetNext returns the next item from the iterator.
// If the iterator has reached the last item previously, lastReceived set to true.
// If the iterator encounters error or has reached the last item previously, lastReceived is set to true.
func (it *bytesKeyValIterator) GetNext() (kv keyval.BytesKeyVal, lastReceived bool) {
if it.err != nil {
return nil, true
Expand Down Expand Up @@ -466,6 +470,7 @@ func (pdb *BytesBrokerWatcherRedis) GetValue(key string) (data []byte, found boo
// ListKeys calls ListKeys function of BytesConnectionRedis.
// Prefix will be prepended to key argument when searching.
// The returned keys, however, will have the prefix trimmed.
// When done traversing, you must close the iterator by calling its Close() method.
func (pdb *BytesBrokerWatcherRedis) ListKeys(match string) (keyval.BytesKeyIterator, error) {
if pdb.delegate.closed {
return nil, fmt.Errorf("ListKeys(%s) called on a closed connection", match)
Expand All @@ -476,6 +481,7 @@ func (pdb *BytesBrokerWatcherRedis) ListKeys(match string) (keyval.BytesKeyItera
// ListValues calls ListValues function of BytesConnectionRedis.
// Prefix will be prepended to key argument when searching.
// The returned keys, however, will have the prefix trimmed.
// When done traversing, you must close the iterator by calling its Close() method.
func (pdb *BytesBrokerWatcherRedis) ListValues(match string) (keyval.BytesKeyValIterator, error) {
if pdb.delegate.closed {
return nil, fmt.Errorf("ListValues(%s) called on a closed connection", match)
Expand Down
2 changes: 2 additions & 0 deletions db/keyval/redis/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
//
// // delete
// found, err := db.Delete("some-key")
// // or, delete all keys matching the prefix "some-key".
// found, err := db.Delete("some-key", keyval.WithPrefix())
//
// // transaction
// var txn keyval.BytesTxn = db.NewTxn()
Expand Down

0 comments on commit e3c5c21

Please sign in to comment.