From 0933c541f4aec20d09c0d7a874dce56b77b3a35b Mon Sep 17 00:00:00 2001 From: Alex Roitman Date: Wed, 31 Oct 2018 22:00:09 -0700 Subject: [PATCH] Refactor cursor/paging. --- internal/collection/collection.go | 47 ++++++++++ internal/server/crud.go | 4 +- internal/server/fence.go | 6 +- internal/server/scan.go | 4 +- internal/server/scanner.go | 8 +- internal/server/search.go | 10 +- tests/keys_search_test.go | 148 ++++++++++++++++++++++++++++++ 7 files changed, 214 insertions(+), 13 deletions(-) diff --git a/internal/collection/collection.go b/internal/collection/collection.go index b9120cf7..78fe6236 100644 --- a/internal/collection/collection.go +++ b/internal/collection/collection.go @@ -309,10 +309,19 @@ func (c *Collection) FieldArr() []string { // Scan iterates though the collection ids. func (c *Collection) Scan(desc bool, + offset uint64, + inc func(n uint64), iterator func(id string, obj geojson.Object, fields []float64) bool, ) bool { var keepon = true + var count uint64 + inc(offset) iter := func(key string, value interface{}) bool { + count++ + if count <= offset { + return true + } + inc(1) iitm := value.(*itemT) keepon = iterator(iitm.id, iitm.obj, c.getFieldValues(iitm.id)) return keepon @@ -327,10 +336,19 @@ func (c *Collection) Scan(desc bool, // ScanRange iterates though the collection starting with specified id. func (c *Collection) ScanRange(start, end string, desc bool, + offset uint64, + inc func(n uint64), iterator func(id string, obj geojson.Object, fields []float64) bool, ) bool { var keepon = true + var count uint64 + inc(offset) iter := func(key string, value interface{}) bool { + count++ + if count <= offset { + return true + } + inc(1) if !desc { if key >= end { return false @@ -355,10 +373,19 @@ func (c *Collection) ScanRange(start, end string, desc bool, // SearchValues iterates though the collection values. func (c *Collection) SearchValues(desc bool, + offset uint64, + inc func(n uint64), iterator func(id string, obj geojson.Object, fields []float64) bool, ) bool { var keepon = true + var count uint64 + inc(offset) iter := func(item btree.Item) bool { + count++ + if count <= offset { + return true + } + inc(1) iitm := item.(*itemT) keepon = iterator(iitm.id, iitm.obj, c.getFieldValues(iitm.id)) return keepon @@ -373,10 +400,19 @@ func (c *Collection) SearchValues(desc bool, // SearchValuesRange iterates though the collection values. func (c *Collection) SearchValuesRange(start, end string, desc bool, + offset uint64, + inc func(n uint64), iterator func(id string, obj geojson.Object, fields []float64) bool, ) bool { var keepon = true + var count uint64 + inc(offset) iter := func(item btree.Item) bool { + count++ + if count <= offset { + return true + } + inc(1) iitm := item.(*itemT) keepon = iterator(iitm.id, iitm.obj, c.getFieldValues(iitm.id)) return keepon @@ -500,9 +536,11 @@ func (c *Collection) Within( obj geojson.Object, offset uint64, sparse uint8, + inc func(n uint64), iter func(id string, obj geojson.Object, fields []float64) bool, ) bool { var count uint64 + inc(offset) if sparse > 0 { return c.geoSparse(obj, sparse, func(id string, o geojson.Object, fields []float64) ( @@ -512,6 +550,7 @@ func (c *Collection) Within( if count <= offset { return false, true } + inc(1) if match = o.Within(obj); match { ok = iter(id, o, fields) } @@ -525,6 +564,7 @@ func (c *Collection) Within( if count <= offset { return true } + inc(1) if o.Within(obj) { return iter(id, o, fields) } @@ -539,9 +579,11 @@ func (c *Collection) Intersects( obj geojson.Object, offset uint64, sparse uint8, + inc func(n uint64), iter func(id string, obj geojson.Object, fields []float64) bool, ) bool { var count uint64 + inc(offset) if sparse > 0 { return c.geoSparse(obj, sparse, func(id string, o geojson.Object, fields []float64) ( @@ -551,6 +593,7 @@ func (c *Collection) Intersects( if count <= offset { return false, true } + inc(1) if match = o.Intersects(obj); match { ok = iter(id, o, fields) } @@ -564,6 +607,7 @@ func (c *Collection) Intersects( if count <= offset { return true } + inc(1) if o.Intersects(obj) { return iter(id, o, fields) } @@ -576,11 +620,13 @@ func (c *Collection) Intersects( func (c *Collection) Nearby( target geojson.Object, offset uint64, + inc func(n uint64), iter func(id string, obj geojson.Object, fields []float64) bool, ) bool { alive := true center := target.Center() var count uint64 + inc(offset) c.index.Nearby( []float64{center.X, center.Y}, []float64{center.X, center.Y}, @@ -589,6 +635,7 @@ func (c *Collection) Nearby( if count <= offset { return true } + inc(1) item := itemv.(*itemT) alive = iter(item.id, item.obj, c.getFieldValues(item.id)) return alive diff --git a/internal/server/crud.go b/internal/server/crud.go index 8ab3e237..12648aea 100644 --- a/internal/server/crud.go +++ b/internal/server/crud.go @@ -372,9 +372,9 @@ func (server *Server) cmdPdel(msg *Message) (res resp.Value, d commandDetailsT, if col != nil { g := glob.Parse(d.pattern, false) if g.Limits[0] == "" && g.Limits[1] == "" { - col.Scan(false, iter) + col.Scan(false, 0, func(n uint64) {}, iter) } else { - col.ScanRange(g.Limits[0], g.Limits[1], false, iter) + col.ScanRange(g.Limits[0], g.Limits[1], false, 0, func(n uint64) {}, iter) } var atLeastOneNotDeleted bool for i, dc := range d.children { diff --git a/internal/server/fence.go b/internal/server/fence.go index aedeaf12..6a45c700 100644 --- a/internal/server/fence.go +++ b/internal/server/fence.go @@ -299,10 +299,10 @@ func extendRoamMessage( } g := glob.Parse(pattern, false) if g.Limits[0] == "" && g.Limits[1] == "" { - col.Scan(false, iterator) + col.Scan(false, 0, func(n uint64) {}, iterator) } else { col.ScanRange(g.Limits[0], g.Limits[1], - false, iterator) + false, 0, func(n uint64) {}, iterator) } } nmsg = append(nmsg, ']') @@ -364,7 +364,7 @@ func fenceMatchRoam( prevNearbys := fence.roam.nearbys[tid] var newNearbys map[string]bool - col.Intersects(obj, 0, 0, func( + col.Intersects(obj, 0, 0, func(n uint64) {}, func( id string, obj2 geojson.Object, fields []float64, ) bool { if c.hasExpired(fence.roam.key, id) { diff --git a/internal/server/scan.go b/internal/server/scan.go index 1d685b81..1f36185c 100644 --- a/internal/server/scan.go +++ b/internal/server/scan.go @@ -66,7 +66,7 @@ func (c *Server) cmdScan(msg *Message) (res resp.Value, err error) { } else { g := glob.Parse(sw.globPattern, s.desc) if g.Limits[0] == "" && g.Limits[1] == "" { - sw.col.Scan(s.desc, + sw.col.Scan(s.desc, s.cursor, sw.IncCursor, func(id string, o geojson.Object, fields []float64) bool { return sw.writeObject(ScanWriterParams{ id: id, @@ -76,7 +76,7 @@ func (c *Server) cmdScan(msg *Message) (res resp.Value, err error) { }, ) } else { - sw.col.ScanRange(g.Limits[0], g.Limits[1], s.desc, + sw.col.ScanRange(g.Limits[0], g.Limits[1], s.desc, s.cursor, sw.IncCursor, func(id string, o geojson.Object, fields []float64) bool { return sw.writeObject(ScanWriterParams{ id: id, diff --git a/internal/server/scanner.go b/internal/server/scanner.go index 3215f123..d612058a 100644 --- a/internal/server/scanner.go +++ b/internal/server/scanner.go @@ -42,6 +42,7 @@ type scanWriter struct { wheres []whereT whereins []whereinT whereevals []whereevalT + numberIters uint64 numberItems uint64 nofields bool cursor uint64 @@ -166,7 +167,7 @@ func (sw *scanWriter) writeHead() { func (sw *scanWriter) writeFoot() { sw.mu.Lock() defer sw.mu.Unlock() - cursor := sw.cursor + sw.numberItems + cursor := sw.numberIters if !sw.hitLimit { cursor = 0 } @@ -325,6 +326,11 @@ func (sw *scanWriter) globMatch(id string, o geojson.Object) (ok, keepGoing bool return true, true } +// Increment cursor +func (sw *scanWriter) IncCursor(n uint64) { + sw.numberIters += n +} + // ok is whether the object passes the test and should be written // keepGoing is whether there could be more objects to test func (sw *scanWriter) testObject(id string, o geojson.Object, fields []float64, ignoreGlobMatch bool) ( diff --git a/internal/server/search.go b/internal/server/search.go index 1a099b58..9e8e2687 100644 --- a/internal/server/search.go +++ b/internal/server/search.go @@ -410,7 +410,7 @@ func (server *Server) nearestNeighbors( maxDist := target.Haversine() limit := int(sw.limit) var items []iterItem - sw.col.Nearby(target, sw.cursor, func(id string, o geojson.Object, fields []float64) bool { + sw.col.Nearby(target, sw.cursor, sw.IncCursor, func(id string, o geojson.Object, fields []float64) bool { if server.hasExpired(s.key, id) { return true } @@ -481,7 +481,7 @@ func (server *Server) cmdWithinOrIntersects(cmd string, msg *Message) (res resp. sw.writeHead() if sw.col != nil { if cmd == "within" { - sw.col.Within(s.obj, s.cursor, s.sparse, func( + sw.col.Within(s.obj, s.cursor, s.sparse, sw.IncCursor, func( id string, o geojson.Object, fields []float64, ) bool { if server.hasExpired(s.key, id) { @@ -495,7 +495,7 @@ func (server *Server) cmdWithinOrIntersects(cmd string, msg *Message) (res resp. }) }) } else if cmd == "intersects" { - sw.col.Intersects(s.obj, s.cursor, s.sparse, func( + sw.col.Intersects(s.obj, s.cursor, s.sparse, sw.IncCursor, func( id string, o geojson.Object, fields []float64, @@ -579,7 +579,7 @@ func (server *Server) cmdSearch(msg *Message) (res resp.Value, err error) { } else { g := glob.Parse(sw.globPattern, s.desc) if g.Limits[0] == "" && g.Limits[1] == "" { - sw.col.SearchValues(s.desc, + sw.col.SearchValues(s.desc, s.cursor, sw.IncCursor, func(id string, o geojson.Object, fields []float64) bool { return sw.writeObject(ScanWriterParams{ id: id, @@ -593,7 +593,7 @@ func (server *Server) cmdSearch(msg *Message) (res resp.Value, err error) { // must disable globSingle for string value type matching because // globSingle is only for ID matches, not values. sw.globSingle = false - sw.col.SearchValuesRange(g.Limits[0], g.Limits[1], s.desc, + sw.col.SearchValuesRange(g.Limits[0], g.Limits[1], s.desc, s.cursor, sw.IncCursor, func(id string, o geojson.Object, fields []float64) bool { return sw.writeObject(ScanWriterParams{ id: id, diff --git a/tests/keys_search_test.go b/tests/keys_search_test.go index ba532adb..f0767656 100644 --- a/tests/keys_search_test.go +++ b/tests/keys_search_test.go @@ -6,10 +6,15 @@ import ( func subTestSearch(t *testing.T, mc *mockServer) { runStep(t, mc, "KNN", keys_KNN_test) + runStep(t, mc, "KNN_CURSOR", keys_KNN_cursor_test) runStep(t, mc, "WITHIN_CIRCLE", keys_WITHIN_CIRCLE_test) runStep(t, mc, "INTERSECTS_CIRCLE", keys_INTERSECTS_CIRCLE_test) runStep(t, mc, "WITHIN", keys_WITHIN_test) + runStep(t, mc, "WITHIN_CURSOR", keys_WITHIN_CURSOR_test) runStep(t, mc, "INTERSECTS", keys_INTERSECTS_test) + runStep(t, mc, "INTERSECTS_CURSOR", keys_INTERSECTS_CURSOR_test) + runStep(t, mc, "SCAN_CURSOR", keys_SCAN_CURSOR_test) + runStep(t, mc, "SEARCH_CURSOR", keys_SEARCH_CURSOR_test) } func keys_KNN_test(mc *mockServer) error { @@ -26,6 +31,28 @@ func keys_KNN_test(mc *mockServer) error { }) } +func keys_KNN_cursor_test(mc *mockServer) error { + return mc.DoBatch([][]interface{}{ + {"SET", "mykey", "1", "FIELD", "foo", 5.5, "POINT", 5, 5}, {"OK"}, + {"SET", "mykey", "2", "FIELD", "foo", 19.19, "POINT",19, 19}, {"OK"}, + {"SET", "mykey", "3", "FIELD", "foo", 12.19, "POINT", 12, 19}, {"OK"}, + {"SET", "mykey", "4", "FIELD", "foo", -5.5, "POINT", -5, 5}, {"OK"}, + {"SET", "mykey", "5", "FIELD", "foo", 13.21, "POINT", 33, 21}, {"OK"}, + {"NEARBY", "mykey", "LIMIT", 2, "POINTS", "POINT", 20, 20}, { + "[2 [[2 [19 19] [foo 19.19]] [3 [12 19] [foo 12.19]]]]"}, + {"NEARBY", "mykey", "CURSOR", 2, "LIMIT", 1, "POINTS", "POINT", 20, 20}, { + "[3 [[5 [33 21] [foo 13.21]]]]"}, + {"NEARBY", "mykey", "LIMIT", 2, "WHERE", "foo", -10, 15, "POINTS", "POINT", 20, 20}, { + "[3 [[3 [12 19] [foo 12.19]] [5 [33 21] [foo 13.21]]]]"}, + {"NEARBY", "mykey", "CURSOR", 3, "LIMIT", 1, "WHERE", "foo", -10, 15, "POINTS", "POINT", 20, 20}, { + "[4 [[1 [5 5] [foo 5.5]]]]"}, + {"NEARBY", "mykey", "CURSOR", 4, "LIMIT", 1, "WHERE", "foo", -10, 15, "POINTS", "POINT", 20, 20}, { + "[5 [[4 [-5 5] [foo -5.5]]]]"}, + {"NEARBY", "mykey", "CURSOR", 4, "LIMIT", 10, "WHERE", "foo", -10, 15, "POINTS", "POINT", 20, 20}, { + "[0 [[4 [-5 5] [foo -5.5]]]]"}, + }) +} + func keys_WITHIN_test(mc *mockServer) error { return mc.DoBatch([][]interface{}{ {"SET", "mykey", "point1", "POINT", 37.7335, -122.4412}, {"OK"}, @@ -73,6 +100,44 @@ func keys_WITHIN_test(mc *mockServer) error { }) } +func keys_WITHIN_CURSOR_test(mc *mockServer) error { + testArea := `{ + "type": "Polygon", + "coordinates": [ + [ + [-122.44126439094543,37.72906137107], + [-122.43980526924135,37.72906137107], + [-122.43980526924135,37.73421283683962], + [-122.44126439094543,37.73421283683962], + [-122.44126439094543,37.72906137107] + ] + ] + }` + return mc.DoBatch([][]interface{}{ + {"SET", "mykey", "point1", "FIELD", "foo", 1, "POINT", 37.7335, -122.4412}, {"OK"}, + {"SET", "mykey", "point2", "FIELD", "foo", 2, "POINT", 37.7335, -122.44121}, {"OK"}, + {"SET", "mykey", "line3", "FIELD", "foo", 3, "OBJECT", `{"type":"LineString","coordinates":[[-122.4408378,37.7341129],[-122.4408378,37.733]]}`}, {"OK"}, + {"SET", "mykey", "poly4", "FIELD", "foo", 4, "OBJECT", `{"type":"Polygon","coordinates":[[[-122.4408378,37.7341129],[-122.4408378,37.733],[-122.44,37.733],[-122.44,37.7341129],[-122.4408378,37.7341129]]]}`}, {"OK"}, + {"SET", "mykey", "multipoly5","FIELD", "foo", 5, "OBJECT", `{"type":"MultiPolygon","coordinates":[[[[-122.4408378,37.7341129],[-122.4408378,37.733],[-122.44,37.733],[-122.44,37.7341129],[-122.4408378,37.7341129]]],[[[-122.44091033935547,37.731981251280985],[-122.43994474411011,37.731981251280985],[-122.43994474411011,37.73254976045042],[-122.44091033935547,37.73254976045042],[-122.44091033935547,37.731981251280985]]]]}`}, {"OK"}, + {"SET", "mykey", "point6", "FIELD", "foo", 6, "POINT", -5, 5}, {"OK"}, + {"SET", "mykey", "point7", "FIELD", "foo", 7, "POINT", 33, 21}, {"OK"}, + {"SET", "mykey", "poly8", "FIELD", "foo", 8, "OBJECT", `{"type":"Polygon","coordinates":[[[-122.4408378,37.7341129],[-122.4408378,37.733],[-122.44,37.733],[-122.44,37.7341129],[-122.4408378,37.7341129]],[[-122.44060993194579,37.73345766902749],[-122.44044363498686,37.73345766902749],[-122.44044363498686,37.73355524732416],[-122.44060993194579,37.73355524732416],[-122.44060993194579,37.73345766902749]],[[-122.44060724973677,37.7336888869566],[-122.4402102828026,37.7336888869566],[-122.4402102828026,37.7339752567853],[-122.44060724973677,37.7339752567853],[-122.44060724973677,37.7336888869566]]]}`}, {"OK"}, + {"SET", "mykey", "point9", "FIELD", "foo", 9, "POINT", 37.7335, -122.4412}, {"OK"}, + {"WITHIN", "mykey", "LIMIT", 3, "IDS", "OBJECT", testArea}, { + "[3 [point1 point2 line3]]"}, + {"WITHIN", "mykey", "CURSOR", 3, "LIMIT", 3, "IDS", "OBJECT", testArea}, { + "[6 [poly4 multipoly5 poly8]]"}, + {"WITHIN", "mykey", "WHERE", "foo", 3, 5, "IDS", "OBJECT", testArea}, { + "[0 [line3 poly4 multipoly5]]"}, + {"WITHIN", "mykey", "LIMIT", 1, "WHERE", "foo", 3, 5, "IDS", "OBJECT", testArea}, { + "[3 [line3]]"}, + {"WITHIN", "mykey", "CURSOR", 3, "LIMIT", 1, "WHERE", "foo", 8, 9, "IDS", "OBJECT", testArea}, { + "[6 [poly8]]"}, + {"WITHIN", "mykey", "CURSOR", 6, "LIMIT", 1, "WHERE", "foo", 8, 9, "IDS", "OBJECT", testArea}, { + "[7 [point9]]"}, + }) +} + func keys_INTERSECTS_test(mc *mockServer) error { return mc.DoBatch([][]interface{}{ {"SET", "mykey", "point1", "POINT", 37.7335, -122.4412}, {"OK"}, @@ -123,6 +188,44 @@ func keys_INTERSECTS_test(mc *mockServer) error { }) } +func keys_INTERSECTS_CURSOR_test(mc *mockServer) error { + testArea := `{ + "type": "Polygon", + "coordinates": [ + [ + [-122.44126439094543,37.732906137107], + [-122.43980526924135,37.732906137107], + [-122.43980526924135,37.73421283683962], + [-122.44126439094543,37.73421283683962], + [-122.44126439094543,37.732906137107] + ] + ] + }` + return mc.DoBatch([][]interface{}{ + {"SET", "mykey", "point1", "FIELD", "foo", 1, "POINT", 37.7335, -122.4412}, {"OK"}, + {"SET", "mykey", "point2", "FIELD", "foo", 2, "POINT", 37.7335, -122.44121}, {"OK"}, + {"SET", "mykey", "line3", "FIELD", "foo", 3, "OBJECT", `{"type":"LineString","coordinates":[[-122.4408378,37.7341129],[-122.4408378,37.733]]}`}, {"OK"}, + {"SET", "mykey", "poly4", "FIELD", "foo", 4, "OBJECT", `{"type":"Polygon","coordinates":[[[-122.4408378,37.7341129],[-122.4408378,37.733],[-122.44,37.733],[-122.44,37.7341129],[-122.4408378,37.7341129]]]}`}, {"OK"}, + {"SET", "mykey", "multipoly5", "FIELD", "foo", 5, "OBJECT", `{"type":"MultiPolygon","coordinates":[[[[-122.4408378,37.7341129],[-122.4408378,37.733],[-122.44,37.733],[-122.44,37.7341129],[-122.4408378,37.7341129]]],[[[-122.44091033935547,37.731981251280985],[-122.43994474411011,37.731981251280985],[-122.43994474411011,37.73254976045042],[-122.44091033935547,37.73254976045042],[-122.44091033935547,37.731981251280985]]]]}`}, {"OK"}, + {"SET", "mykey", "point6", "FIELD", "foo", 6, "POINT", -5, 5}, {"OK"}, + {"SET", "mykey", "point7", "FIELD", "foo", 7, "POINT", 33, 21}, {"OK"}, + {"SET", "mykey", "poly8", "FIELD", "foo", 8, "OBJECT", `{"type":"Polygon","coordinates":[[[-122.4408378,37.7341129],[-122.4408378,37.733],[-122.44,37.733],[-122.44,37.7341129],[-122.4408378,37.7341129]],[[-122.44060993194579,37.73345766902749],[-122.44044363498686,37.73345766902749],[-122.44044363498686,37.73355524732416],[-122.44060993194579,37.73355524732416],[-122.44060993194579,37.73345766902749]],[[-122.44060724973677,37.7336888869566],[-122.4402102828026,37.7336888869566],[-122.4402102828026,37.7339752567853],[-122.44060724973677,37.7339752567853],[-122.44060724973677,37.7336888869566]]]}`}, {"OK"}, + {"SET", "mykey", "point9", "FIELD", "foo", 9, "POINT", 37.7335, -122.4412}, {"OK"}, + {"INTERSECTS", "mykey", "LIMIT", 3, "IDS", "OBJECT", testArea}, { + "[3 [point1 point2 line3]]"}, + {"INTERSECTS", "mykey", "CURSOR", 3, "LIMIT", 3, "IDS", "OBJECT", testArea}, { + "[6 [poly4 multipoly5 poly8]]"}, + {"INTERSECTS", "mykey", "WHERE", "foo", 3, 5, "IDS", "OBJECT", testArea}, { + "[0 [line3 poly4 multipoly5]]"}, + {"INTERSECTS", "mykey", "LIMIT", 1, "WHERE", "foo", 3, 5, "IDS", "OBJECT", testArea}, { + "[3 [line3]]"}, + {"INTERSECTS", "mykey", "CURSOR", 3, "LIMIT", 1, "WHERE", "foo", 8, 9, "IDS", "OBJECT", testArea}, { + "[6 [poly8]]"}, + {"INTERSECTS", "mykey", "CURSOR", 6, "LIMIT", 1, "WHERE", "foo", 8, 9, "IDS", "OBJECT", testArea}, { + "[7 [point9]]"}, + }) +} + func keys_WITHIN_CIRCLE_test(mc *mockServer) error { return mc.DoBatch([][]interface{}{ {"SET", "mykey", "1", "POINT", 37.7335, -122.4412}, {"OK"}, @@ -154,3 +257,48 @@ func keys_INTERSECTS_CIRCLE_test(mc *mockServer) error { "[0 [1 2]]"}, }) } + +func keys_SCAN_CURSOR_test(mc *mockServer) error { + return mc.DoBatch([][]interface{}{ + {"SET", "mykey", "id1", "FIELD", "foo", 1, "STRING", "bar1"}, {"OK"}, + {"SET", "mykey", "id2", "FIELD", "foo", 2, "STRING", "bar2"}, {"OK"}, + {"SET", "mykey", "id3", "FIELD", "foo", 3, "STRING", "bar3"}, {"OK"}, + {"SET", "mykey", "id4", "FIELD", "foo", 4, "STRING", "bar4"}, {"OK"}, + {"SET", "mykey", "id5", "FIELD", "foo", 5, "STRING", "bar5"}, {"OK"}, + {"SET", "mykey", "id6", "FIELD", "foo", 6, "STRING", "bar6"}, {"OK"}, + {"SET", "mykey", "id7", "FIELD", "foo", 7, "STRING", "bar7"}, {"OK"}, + {"SET", "mykey", "id8", "FIELD", "foo", 8, "STRING", "bar8"}, {"OK"}, + {"SET", "mykey", "id9", "FIELD", "foo", 9, "STRING", "bar9"}, {"OK"}, + {"SCAN", "mykey", "LIMIT", 3, "IDS"}, {"[3 [id1 id2 id3]]"}, + {"SCAN", "mykey", "CURSOR", 3, "LIMIT", 3, "IDS"}, {"[6 [id4 id5 id6]]"}, + {"SCAN", "mykey", "WHERE", "foo", 3, 5, "IDS"}, {"[0 [id3 id4 id5]]"}, + {"SCAN", "mykey", "LIMIT", 1, "WHERE", "foo", 3, 5, "IDS"}, {"[3 [id3]]"}, + {"SCAN", "mykey", "CURSOR", 3, "LIMIT", 1, "WHERE", "foo", 8, 9, "IDS"}, { + "[8 [id8]]"}, + {"SCAN", "mykey", "CURSOR", 6, "LIMIT", 1, "WHERE", "foo", 8, 9, "IDS"}, { + "[8 [id8]]"}, + }) +} + +func keys_SEARCH_CURSOR_test(mc *mockServer) error { + return mc.DoBatch([][]interface{}{ + {"SET", "mykey", "id1", "FIELD", "foo", 1, "STRING", "bar1"}, {"OK"}, + {"SET", "mykey", "id2", "FIELD", "foo", 2, "STRING", "bar2"}, {"OK"}, + {"SET", "mykey", "id3", "FIELD", "foo", 3, "STRING", "bar3"}, {"OK"}, + {"SET", "mykey", "id4", "FIELD", "foo", 4, "STRING", "bar4"}, {"OK"}, + {"SET", "mykey", "id5", "FIELD", "foo", 5, "STRING", "bar5"}, {"OK"}, + {"SET", "mykey", "id6", "FIELD", "foo", 6, "STRING", "bar6"}, {"OK"}, + {"SET", "mykey", "id7", "FIELD", "foo", 7, "STRING", "bar7"}, {"OK"}, + {"SET", "mykey", "id8", "FIELD", "foo", 8, "STRING", "bar8"}, {"OK"}, + {"SET", "mykey", "id9", "FIELD", "foo", 9, "STRING", "bar9"}, {"OK"}, + {"SEARCH", "mykey", "LIMIT", 3, "IDS"}, {"[3 [id1 id2 id3]]"}, + {"SEARCH", "mykey", "CURSOR", 3, "LIMIT", 3, "IDS"}, {"[6 [id4 id5 id6]]"}, + {"SEARCH", "mykey", "WHERE", "foo", 3, 5, "IDS"}, {"[0 [id3 id4 id5]]"}, + {"SEARCH", "mykey", "LIMIT", 1, "WHERE", "foo", 3, 5, "IDS"}, {"[3 [id3]]"}, + {"SEARCH", "mykey", "CURSOR", 3, "LIMIT", 1, "WHERE", "foo", 8, 9, "IDS"}, { + "[8 [id8]]"}, + {"SEARCH", "mykey", "CURSOR", 6, "LIMIT", 1, "WHERE", "foo", 8, 9, "IDS"}, { + "[8 [id8]]"}, + {"SEARCH", "mykey", "LIMIT", 3, "DESC", "IDS"}, {"[3 [id9 id8 id7]]"}, + }) +}