Skip to content

Commit b0507c0

Browse files
committed
Removed support for swift4 and nio1.
1 parent 72c238b commit b0507c0

8 files changed

+59
-253
lines changed

.travis.yml

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ matrix:
77
include:
88
- os: Linux
99
dist: trusty
10-
env: SWIFT_SNAPSHOT_NAME="https://swift.org/builds/swift-4.2.3-release/ubuntu1404/swift-4.2.3-RELEASE/swift-4.2.3-RELEASE-ubuntu14.04.tar.gz"
10+
env: SWIFT_SNAPSHOT_NAME="https://swift.org/builds/swift-5.0-release/ubuntu1404/swift-5.0-RELEASE/swift-5.0-RELEASE-ubuntu14.04.tar.gz"
1111
sudo: required
1212
- os: Linux
1313
dist: trusty
14-
env: SWIFT_SNAPSHOT_NAME="https://swift.org/builds/swift-5.0-release/ubuntu1404/swift-5.0-RELEASE/swift-5.0-RELEASE-ubuntu14.04.tar.gz"
14+
env: SWIFT_SNAPSHOT_NAME="https://swift.org/builds/swift-5.1.1-release/ubuntu1404/swift-5.1.1-RELEASE/swift-5.1.1-RELEASE-ubuntu14.04.tar.gz"
1515
sudo: required
16-
- os: osx
17-
osx_image: xcode10.1
1816
- os: osx
1917
osx_image: xcode10.2
20-
18+
- os: osx
19+
osx_image: xcode11.2
2120

2221
before_install:
2322
- ./.travis.d/before-install.sh

Package.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:4.2
1+
// swift-tools-version:5.0
22

33
import PackageDescription
44

@@ -9,9 +9,9 @@ let package = Package(
99
],
1010
dependencies: [
1111
.package(url: "https://github.com/apple/swift-nio.git",
12-
from: "1.13.2"),
12+
from: "2.0.0"),
1313
.package(url: "https://github.com/SwiftNIOExtras/swift-nio-redis.git",
14-
from: "0.9.0")
14+
from: "0.10.2")
1515
],
1616
targets: [
1717
.target (name: "Redis", dependencies: [ "NIORedis" ]),

[email protected]

-20
This file was deleted.

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# SwiftNIO Redis Client
22

3-
![Swift4](https://img.shields.io/badge/swift-4-blue.svg)
43
![Swift5](https://img.shields.io/badge/swift-5-blue.svg)
54
![macOS](https://img.shields.io/badge/os-macOS-green.svg?style=flat)
65
![tuxOS](https://img.shields.io/badge/os-tuxOS-green.svg?style=flat)

Sources/Redis/RedisClient.swift

+28-92
Original file line numberDiff line numberDiff line change
@@ -164,35 +164,21 @@ open class RedisClient : RedisCommandTarget {
164164
_ = bootstrap.channelOption(ChannelOptions.reuseAddr, value: 1)
165165

166166
_ = bootstrap.channelInitializer { [weak self] channel in
167-
#if swift(>=5)
168-
return channel.pipeline
169-
.configureRedisPipeline()
170-
.flatMap { [weak self] in
171-
guard let me = self else {
172-
//assert(self != nil, "bootstrap running, but client gone?!")
173-
let error = channel.eventLoop.makePromise(of: Void.self)
174-
error.fail(Error.internalInconsistency)
175-
return error.futureResult
176-
}
177-
178-
return channel.pipeline
179-
.addHandler(Handler(client: me),
180-
name: "de.zeezide.nio.redis.client")
181-
}
182-
#else
167+
168+
return channel.pipeline
169+
.configureRedisPipeline()
170+
.flatMap { [weak self] in
171+
guard let me = self else {
172+
//assert(self != nil, "bootstrap running, but client gone?!")
173+
let error = channel.eventLoop.makePromise(of: Void.self)
174+
error.fail(Error.internalInconsistency)
175+
return error.futureResult
176+
}
177+
183178
return channel.pipeline
184-
.configureRedisPipeline()
185-
.thenThrowing { [weak self] in
186-
guard let me = self else {
187-
//assert(self != nil, "bootstrap running, but client gone?!")
188-
throw Error.internalInconsistency
189-
}
190-
191-
let handler = Handler(client: me)
192-
_ = channel.pipeline.add(name: "de.zeezide.nio.redis.client",
193-
handler: handler)
194-
}
195-
#endif
179+
.addHandler(Handler(client: me),
180+
name: "de.zeezide.nio.redis.client")
181+
}
196182
}
197183
}
198184
#if false
@@ -353,13 +339,8 @@ open class RedisClient : RedisCommandTarget {
353339

354340
// MARK: - Commands
355341

356-
#if swift(>=5)
357342
var callQueue = CircularBuffer<RedisCommandCall>(initialCapacity: 16)
358343
var pendingCalls = CircularBuffer<RedisCommandCall>(initialCapacity: 16)
359-
#else
360-
var callQueue = CircularBuffer<RedisCommandCall>(initialRingCapacity: 16)
361-
var pendingCalls = CircularBuffer<RedisCommandCall>(initialRingCapacity: 16)
362-
#endif
363344

364345
public func enqueueCommandCall(_ call: RedisCommandCall) { // Q: any
365346
guard eventLoop.inEventLoop else {
@@ -383,18 +364,10 @@ open class RedisClient : RedisCommandTarget {
383364
_ = _connect(host: options.hostname ?? "localhost", port: options.port)
384365

385366
case .requestedQuit, .quit:
386-
#if swift(>=5)
387-
callQueue.forEach { $0.promise.fail(Error.stopped) }
388-
#else
389-
callQueue.forEach { $0.promise.fail(error: Error.stopped) }
390-
#endif
367+
callQueue.forEach { $0.promise.fail(Error.stopped) }
391368

392369
case .error(let error):
393-
#if swift(>=5)
394-
callQueue.forEach { $0.promise.fail(error) }
395-
#else
396-
callQueue.forEach { $0.promise.fail(error: error) }
397-
#endif
370+
callQueue.forEach { $0.promise.fail(error) }
398371

399372
case .connecting, .authenticating: break
400373

@@ -412,11 +385,7 @@ open class RedisClient : RedisCommandTarget {
412385
channel.write(call.command)
413386
.map { self.pendingCalls.append(call) }
414387
.whenFailure {
415-
#if swift(>=5)
416-
call.promise.fail(Error.writeError($0))
417-
#else
418-
call.promise.fail(error: Error.writeError($0))
419-
#endif
388+
call.promise.fail(Error.writeError($0))
420389
}
421390
}
422391
channel.flush()
@@ -428,19 +397,11 @@ open class RedisClient : RedisCommandTarget {
428397
if !pendingCalls.isEmpty {
429398
let call = pendingCalls.removeFirst()
430399

431-
#if swift(>=5)
432-
if !call.command.isSubscribe {
433-
call.promise.succeed(value)
434-
return
435-
}
436-
call.promise.succeed(.bulkString(nil)) // TBD
437-
#else
438-
if !call.command.isSubscribe {
439-
call.promise.succeed(result: value)
440-
return
441-
}
442-
call.promise.succeed(result: .bulkString(nil)) // TBD
443-
#endif
400+
if !call.command.isSubscribe {
401+
call.promise.succeed(value)
402+
return
403+
}
404+
call.promise.succeed(.bulkString(nil)) // TBD
444405
}
445406

446407
// PubSub handling
@@ -490,21 +451,12 @@ open class RedisClient : RedisCommandTarget {
490451
var channel : Channel? { @inline(__always) get { return state.channel } }
491452

492453
public func quit() {
493-
#if swift(>=5)
494-
_enqueueCommandCall(RedisCommandCall(["QUIT"], eventLoop: eventLoop))
495-
.whenComplete { _ in
496-
self.state = .quit
497-
self.subscribeListeners.removeAll()
498-
self.messageListeners.removeAll()
499-
}
500-
#else
501-
_enqueueCommandCall(RedisCommandCall(["QUIT"], eventLoop: eventLoop))
502-
.whenComplete {
503-
self.state = .quit
504-
self.subscribeListeners.removeAll()
505-
self.messageListeners.removeAll()
506-
}
507-
#endif
454+
_enqueueCommandCall(RedisCommandCall(["QUIT"], eventLoop: eventLoop))
455+
.whenComplete { _ in
456+
self.state = .quit
457+
self.subscribeListeners.removeAll()
458+
self.messageListeners.removeAll()
459+
}
508460
_processQueue()
509461
}
510462

@@ -675,22 +627,6 @@ open class RedisClient : RedisCommandTarget {
675627
self.client.handlerCaughtError(error, in: context)
676628
_ = context.close(promise: nil)
677629
}
678-
679-
#if swift(>=5) // NIO 2 API - default
680-
#else // NIO 1 API Shims
681-
func channelInactive(ctx context: ChannelHandlerContext) {
682-
channelInactive(context: context)
683-
}
684-
685-
func channelRead(ctx context: ChannelHandlerContext, data: NIOAny) {
686-
channelRead(context: context, data: data)
687-
}
688-
689-
public func errorCaught(ctx context: ChannelHandlerContext, error: Error)
690-
{
691-
errorCaught(context: context, error: error)
692-
}
693-
#endif // NIO 1 API Shims
694630
}
695631

696632
}

Sources/Redis/RedisCommand.swift

+1-5
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,7 @@ public class RedisCommandCall {
5252
convenience init<T: Collection>(_ values: T, eventLoop: EventLoop)
5353
where T.Element : RESPEncodable
5454
{
55-
#if swift(>=5)
56-
self.init(command: RedisCommand(values), promise: eventLoop.makePromise())
57-
#else
58-
self.init(command: RedisCommand(values), promise: eventLoop.newPromise())
59-
#endif
55+
self.init(command: RedisCommand(values), promise: eventLoop.makePromise())
6056
}
6157
}
6258

Sources/Redis/RedisCommandTarget.swift

+23-55
Original file line numberDiff line numberDiff line change
@@ -341,55 +341,29 @@ import class NIO.EventLoopFuture
341341
import enum NIORedis.RESPValue
342342
import protocol NIORedis.RESPEncodable
343343

344-
#if swift(>=5)
345-
fileprivate extension EventLoopFuture {
346-
347-
func whenCB(file: StaticString = #file, line: UInt = #line,
348-
_ cb: @escaping ( Swift.Error?, Value? ) -> Void) -> Void
349-
{
350-
self.map(file: file, line: line) { cb(nil, $0) }
351-
.whenFailure { cb($0, nil) }
352-
}
353-
}
354-
355-
fileprivate extension EventLoopFuture where Value == RESPValue {
356-
357-
func whenCB<U: RedisTypeTransformable>(file: StaticString = #file,
358-
line: UInt = #line,
359-
_ cb: @escaping ( Swift.Error?, U? ) -> Void) -> Void
360-
{
361-
self.map(file: file, line: line) {
362-
do { cb(nil, try U.extractFromRESPValue($0)) }
363-
catch { cb(error, nil) }
364-
}
365-
.whenFailure { cb($0, nil) }
366-
}
367-
}
368-
#else // NIO1
369-
fileprivate extension EventLoopFuture {
370-
371-
func whenCB(file: StaticString = #file, line: UInt = #line,
372-
_ cb: @escaping ( Swift.Error?, T? ) -> Void) -> Void
373-
{
374-
self.map(file: file, line: line) { cb(nil, $0) }
375-
.whenFailure { cb($0, nil) }
376-
}
344+
fileprivate extension EventLoopFuture {
345+
346+
func whenCB(file: StaticString = #file, line: UInt = #line,
347+
_ cb: @escaping ( Swift.Error?, Value? ) -> Void) -> Void
348+
{
349+
self.map(file: file, line: line) { cb(nil, $0) }
350+
.whenFailure { cb($0, nil) }
377351
}
352+
}
378353

379-
fileprivate extension EventLoopFuture where T == RESPValue {
380-
381-
func whenCB<U: RedisTypeTransformable>(file: StaticString = #file,
382-
line: UInt = #line,
383-
_ cb: @escaping ( Swift.Error?, U? ) -> Void) -> Void
384-
{
385-
self.map(file: file, line: line) {
386-
do { cb(nil, try U.extractFromRESPValue($0)) }
387-
catch { cb(error, nil) }
388-
}
389-
.whenFailure { cb($0, nil) }
390-
}
354+
fileprivate extension EventLoopFuture where Value == RESPValue {
355+
356+
func whenCB<U: RedisTypeTransformable>(file: StaticString = #file,
357+
line: UInt = #line,
358+
_ cb: @escaping ( Swift.Error?, U? ) -> Void) -> Void
359+
{
360+
self.map(file: file, line: line) {
361+
do { cb(nil, try U.extractFromRESPValue($0)) }
362+
catch { cb(error, nil) }
363+
}
364+
.whenFailure { cb($0, nil) }
391365
}
392-
#endif // NIO1
366+
}
393367

394368
public extension RedisCommandTarget {
395369

@@ -400,15 +374,9 @@ public extension RedisCommandTarget {
400374
{
401375
let call = RedisCommandCall(values, eventLoop: eventLoop)
402376

403-
#if swift(>=5)
404-
let future = call.promise.futureResult.flatMapThrowing {
405-
try U.extractFromRESPValue($0)
406-
}
407-
#else
408-
let future = call.promise.futureResult.thenThrowing {
409-
try U.extractFromRESPValue($0)
410-
}
411-
#endif
377+
let future = call.promise.futureResult.flatMapThrowing {
378+
try U.extractFromRESPValue($0)
379+
}
412380
enqueueCommandCall(call)
413381
return future
414382
}

0 commit comments

Comments
 (0)