Skip to content

Commit 0c13e4f

Browse files
committed
Get scan working on the same as redis-cli 6.2.1
1 parent 03a066f commit 0c13e4f

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

Sources/RediStack/Commands/RedisCommand.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ extension RedisCommand {
9696
var args: [RESPValue] = [.init(bulk: pos)]
9797

9898
if let k = key { args.insert(.init(from: k), at: 0) }
99-
if let m = match { args.append(.init(bulk: "match \(m)")) }
100-
if let c = count { args.append(.init(bulk: "count \(c)")) }
99+
if let m = match { args.append(contentsOf: [.init(bulk: "match"), .init(bulk: "\(m)")]) }
100+
if let c = count { args.append(contentsOf: [.init(bulk: "count"), .init(bulk: "\(c)")]) }
101101

102102
return .init(keyword: keyword, arguments: args) {
103103
let response = try $0.map(to: [RESPValue].self)

Tests/RediStackIntegrationTests/Commands/KeyCommandsTests.swift

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -125,29 +125,29 @@ final class KeyCommandsTests: RediStackIntegrationTestCase {
125125

126126
// TODO: #23 -- Rework Scan Unit Test
127127
// This is extremely flakey, and causes non-deterministic failures because of the assert on key counts
128-
// func test_scan() throws {
129-
// var dataset: [RedisKey] = .init(repeating: "", count: 10)
130-
// for index in 1...15 {
131-
// let key = RedisKey("key\(index)\(index % 2 == 0 ? "_even" : "_odd")")
132-
// dataset.append(key)
133-
// _ = try connection.set(key, to: "\(index)").wait()
134-
// }
135-
//
136-
// var (cursor, keys) = try connection.scan(count: 5).wait()
137-
// XCTAssertGreaterThanOrEqual(cursor, 0)
138-
// XCTAssertGreaterThanOrEqual(keys.count, 5)
139-
//
140-
// (_, keys) = try connection.scan(startingFrom: cursor, count: 8).wait()
141-
// XCTAssertGreaterThanOrEqual(keys.count, 8)
142-
//
143-
// (cursor, keys) = try connection.scan(matching: "*_odd").wait()
144-
// XCTAssertGreaterThanOrEqual(cursor, 0)
145-
// XCTAssertGreaterThanOrEqual(keys.count, 1)
146-
// XCTAssertLessThanOrEqual(keys.count, 7)
147-
//
148-
// (cursor, keys) = try connection.scan(matching: "*_even*").wait()
149-
// XCTAssertGreaterThanOrEqual(cursor, 0)
150-
// XCTAssertGreaterThanOrEqual(keys.count, 1)
151-
// XCTAssertLessThanOrEqual(keys.count, 7)
152-
// }
128+
func test_scan() throws {
129+
var dataset: [RedisKey] = .init(repeating: "", count: 10)
130+
for index in 1...15 {
131+
let key = RedisKey("key\(index)\(index % 2 == 0 ? "_even" : "_odd")")
132+
dataset.append(key)
133+
_ = try connection.set(key, to: "\(index)").wait()
134+
}
135+
136+
var (cursor, keys) = try connection.scanKeys(count: 5).wait()
137+
XCTAssertGreaterThanOrEqual(cursor, 0)
138+
XCTAssertGreaterThanOrEqual(keys.count, 5)
139+
140+
(_, keys) = try connection.scanKeys(startingFrom: cursor, count: 8).wait()
141+
XCTAssertGreaterThanOrEqual(keys.count, 8)
142+
143+
(cursor, keys) = try connection.scanKeys(matching: "*_odd").wait()
144+
XCTAssertGreaterThanOrEqual(cursor, 0)
145+
XCTAssertGreaterThanOrEqual(keys.count, 1)
146+
XCTAssertLessThanOrEqual(keys.count, 7)
147+
148+
(cursor, keys) = try connection.scanKeys(matching: "*_even*").wait()
149+
XCTAssertGreaterThanOrEqual(cursor, 0)
150+
XCTAssertGreaterThanOrEqual(keys.count, 1)
151+
XCTAssertLessThanOrEqual(keys.count, 7)
152+
}
153153
}

0 commit comments

Comments
 (0)