From 8038a54cdb055f60fdf6730df97cd970e3943ee2 Mon Sep 17 00:00:00 2001 From: siddontang Date: Fri, 23 May 2014 13:06:44 +0800 Subject: [PATCH] add inclusive flag for scan --- ledis/t_kv.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ledis/t_kv.go b/ledis/t_kv.go index 16a92c5..a4cd1f9 100644 --- a/ledis/t_kv.go +++ b/ledis/t_kv.go @@ -289,7 +289,8 @@ func (db *DB) KvFlush() (drop int64, err error) { return } -func (db *DB) Scan(key []byte, count int) ([]KVPair, error) { +//if inclusive is true, scan range [key, inf) else (key, inf) +func (db *DB) Scan(key []byte, count int, inclusive bool) ([]KVPair, error) { var minKey []byte if key != nil { if err := checkKeySize(key); err != nil { @@ -308,7 +309,12 @@ func (db *DB) Scan(key []byte, count int) ([]KVPair, error) { v := make([]KVPair, 0, 2*count) - it := db.db.Iterator(minKey, maxKey, leveldb.RangeROpen, 0, count) + rangeType := leveldb.RangeROpen + if !inclusive { + rangeType = leveldb.RangeOpen + } + + it := db.db.Iterator(minKey, maxKey, rangeType, 0, count) for ; it.Valid(); it.Next() { if key, err := db.decodeKVKey(it.Key()); err != nil { continue