Skip to content

Commit

Permalink
formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ktoso committed Nov 8, 2024
1 parent 57506b4 commit 1d5a2f7
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 36 deletions.
4 changes: 3 additions & 1 deletion Sources/RediStack/ChannelHandlers/RedisCommandHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ extension RedisCommandHandler: ChannelInboundHandler {
self.state = .error(error)
let queue = self.commandResponseQueue
self.commandResponseQueue.removeAll()
queue.forEach { $0.fail(error) }
for element in queue {
element.fail(error)
}
}

/// Invoked by SwiftNIO when a read has been fired from earlier in the response chain.
Expand Down
12 changes: 7 additions & 5 deletions Sources/RediStack/ChannelHandlers/RedisPubSubHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,12 @@ extension RedisPubSubHandler {

// create them
let pendingSubscriptions: [(String, EventLoopPromise<Int>)] = targets.map {
return (self.prefixKey($0, with: keyPrefix), self.eventLoop.makePromise())
(self.prefixKey($0, with: keyPrefix), self.eventLoop.makePromise())
}
// add the subscription change handler to the appropriate queue for each individual subscription target
pendingSubscriptions.forEach { self[keyPath: pendingQueue].updateValue($1, forKey: $0) }
for (key, value) in pendingSubscriptions {
self[keyPath: pendingQueue].updateValue(value, forKey: key)
}

// synchronize all of the individual subscription changes
let subscriptionCountFuture = EventLoopFuture<Int>
Expand Down Expand Up @@ -480,9 +482,9 @@ extension RedisPubSubHandler: ChannelInboundHandler {

let receivers = self.subscriptions
self.subscriptions.removeAll()
receivers.forEach {
$0.value.onUnsubscribe?($0.key, 0)
$0.value.type.gauge.decrement()
for receiver in receivers {
receiver.value.onUnsubscribe?(receiver.key, 0)
receiver.value.type.gauge.decrement()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public protocol RedisClusterShardDescriptionProtocol: Identifiable, Sendable {
associatedtype NodeDescription: RedisClusterNodeDescriptionProtocol

/// The shard's primary node
var master: NodeDescription { get } // #ignore-unacceptable-language
var master: NodeDescription { get } // #ignore-unacceptable-language

/// The shard's replica nodes
var replicas: [NodeDescription] { get }
Expand Down
2 changes: 1 addition & 1 deletion Sources/RediStack/Commands/BasicCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ extension RedisClient {
}
let elements =
response
.map { return $0[1] }
.map { $0[1] }
.tryConverting(to: resultType)

return position.and(elements)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ extension RedisConnectionPool {
connectionRetryTimeout ?? .milliseconds(10) // always default to a baseline 10ms
)
self.onUnexpectedConnectionClose = onUnexpectedConnectionClose
self.poolDefaultLogger = poolDefaultLogger ?? .redisBaseConnectionPoolLogger
self.poolDefaultLogger = poolDefaultLogger ?? .redisBaseConnectionPool
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion Sources/RediStack/RESP/RESPTranslator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ extension ByteBuffer {
self.writeStaticString("*")
self.writeString("\(array.count)")
self.writeStaticString(respEnd)
array.forEach { self.writeRESPValue($0) }
for element in array {
self.writeRESPValue(element)
}
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions Sources/RediStack/RESP/RESPValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ extension RangeReplaceableCollection where Element == RESPValue {
guard elementsToCopy.count > 0 else { return }

self.reserveCapacity(self.count + elementsToCopy.count)
elementsToCopy.forEach { self.append($0.convertedToRESPValue()) }
for element in elementsToCopy {
self.append(element.convertedToRESPValue())
}
}

/// Adds the elements of a collection to this array, delegating the details of how they are added to the given closure.
Expand Down Expand Up @@ -254,7 +256,9 @@ extension RangeReplaceableCollection where Element == RESPValue {
let sizeToAdd = overestimatedCountBeingAdded ?? elementsToCopy.count
self.reserveCapacity(self.count + sizeToAdd)

elementsToCopy.forEach { closure(&self, $0) }
for element in elementsToCopy {
closure(&self, element)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/RediStack/RedisClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public struct RedisClientError: LocalizedError, Equatable, Hashable {

private init(_ baseError: BaseError) { self.baseError = baseError }

/* Protocol Conformances and Private Type implementation */
// Protocol Conformances and Private Type implementation

public static func == (lhs: RedisClientError, rhs: RedisClientError) -> Bool {
lhs.localizedDescription == rhs.localizedDescription
Expand Down
2 changes: 1 addition & 1 deletion Sources/RediStack/RedisConnection+Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extension RedisConnection {
}
}

internal static let defaultLogger = Logger.redisBaseConnectionLogger
internal static let defaultLogger = Logger.redisBaseConnection

/// The hostname of the connection address. If the address is a Unix socket, then it will be `nil`.
public var hostname: String? {
Expand Down
4 changes: 2 additions & 2 deletions Sources/RediStack/RedisLogging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public enum RedisLogging {

extension Logger {
/// The prototypical instance used for Redis connections.
public static var redisBaseConnectionLogger: Logger { RedisLogging.baseConnectionLogger }
public static var redisBaseConnection: Logger { RedisLogging.baseConnectionLogger }
/// The prototypical instance used for Redis connection pools.
public static var redisBaseConnectionPoolLogger: Logger { RedisLogging.baseConnectionPoolLogger }
public static var redisBaseConnectionPool: Logger { RedisLogging.baseConnectionPoolLogger }
}

// MARK: Protocol-based Context Passing
Expand Down
6 changes: 3 additions & 3 deletions Sources/RediStack/_Deprecations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extension RedisConnection {
to socket: SocketAddress,
on eventLoop: EventLoop,
password: String? = nil,
logger: Logger = .redisBaseConnectionLogger,
logger: Logger = .redisBaseConnection,
tcpClient: ClientBootstrap? = nil
) -> EventLoopFuture<RedisConnection> {
let config: Configuration
Expand Down Expand Up @@ -105,9 +105,9 @@ extension RedisConnectionPool {
maximumConnectionCount: RedisConnectionPoolSize,
minimumConnectionCount: Int = 1,
connectionPassword: String? = nil, // config
connectionLogger: Logger = .redisBaseConnectionLogger, // config
connectionLogger: Logger = .redisBaseConnection, // config
connectionTCPClient: ClientBootstrap? = nil,
poolLogger: Logger = .redisBaseConnectionPoolLogger,
poolLogger: Logger = .redisBaseConnectionPool,
connectionBackoffFactor: Float32 = 2,
initialConnectionBackoffDelay: TimeAmount = .milliseconds(100),
connectionRetryTimeout: TimeAmount? = .seconds(60)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ final class ListCommandsTests: RediStackIntegrationTestCase {
size = try connection.lpushx(30, into: #function).wait()
XCTAssertEqual(size, 2)
let element = try connection.rpop(from: #function)
.map { return Int(fromRESP: $0) }
.map { Int(fromRESP: $0) }
.wait()
XCTAssertEqual(element, 10)
}
Expand Down Expand Up @@ -238,7 +238,7 @@ final class ListCommandsTests: RediStackIntegrationTestCase {
size = try connection.rpushx(30, into: #function).wait()
XCTAssertEqual(size, 2)
let element = try connection.lpop(from: #function)
.map { return Int(fromRESP: $0) }
.map { Int(fromRESP: $0) }
.wait()
XCTAssertEqual(element, 10)
}
Expand All @@ -248,7 +248,7 @@ final class ListCommandsTests: RediStackIntegrationTestCase {
_ = try self.connection.delete(#function).wait()
_ = try self.connection.lpush([5, 4, 3, 2, 1], into: #function).wait()
}
let getElements = { return try self.connection.lrange(from: #function, fromIndex: 0).wait() }
let getElements = { try self.connection.lrange(from: #function, fromIndex: 0).wait() }

try setup()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ final class SortedSetCommandsTests: RediStackIntegrationTestCase {
XCTAssertEqual(elements.count, 6)

let values = try RedisConnection._mapSortedSetResponse(elements, scoreIsFirst: false)
.map { (value, _) in return Int(fromRESP: value) }
.map { (value, _) in Int(fromRESP: value) }

XCTAssertEqual(values[0], 2)
XCTAssertEqual(values[1], 3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ final class StringCommandsTests: RediStackIntegrationTestCase {

func test_mget() throws {
let keys = ["one", "two"].map(RedisKey.init(_:))
try keys.forEach { _ = try connection.set($0, to: $0).wait() }
for key in keys {
_ = try connection.set(key, to: key).wait()
}

let values = try connection.mget(keys + ["empty"]).wait()
XCTAssertEqual(values.count, 3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ extension RedisConnectionPoolTests {
let promises: [EventLoopPromise<Void>] = [pool.eventLoop.makePromise(), pool.eventLoop.makePromise()]
let futures = promises.indices
.map { index in
return
pool
pool
.leaseConnection { connection -> EventLoopFuture<Void> in
XCTAssertTrue(pool.availableConnectionCount < maxConnectionCount)

Expand Down
6 changes: 3 additions & 3 deletions Tests/RediStackIntegrationTests/RedisLoggingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import XCTest
final class RedisLoggingTests: RediStackIntegrationTestCase {
func test_connectionUsesCustomLogger() throws {
let handler = TestLogHandler()
let logger = Logger(label: #function, factory: { _ in return handler })
let logger = Logger(label: #function, factory: { _ in handler })
_ = try self.connection
.logging(to: logger)
.ping()
Expand All @@ -30,7 +30,7 @@ final class RedisLoggingTests: RediStackIntegrationTestCase {

func test_connectionLoggerMetadata() throws {
let handler = TestLogHandler()
let logger = Logger(label: #function, factory: { _ in return handler })
let logger = Logger(label: #function, factory: { _ in handler })

_ = try self.connection
.logging(to: logger)
Expand All @@ -44,7 +44,7 @@ final class RedisLoggingTests: RediStackIntegrationTestCase {

func test_poolLoggerMetadata() throws {
let handler = TestLogHandler()
let logger = Logger(label: #function, factory: { _ in return handler })
let logger = Logger(label: #function, factory: { _ in handler })

let pool = RedisConnectionPool(
configuration: .init(
Expand Down
14 changes: 7 additions & 7 deletions Tests/RediStackTests/ConnectionPoolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class ConnectionPoolTests: XCTestCase {
let channel = self.server.createConnectedChannel()

// Wrap it
return RedisConnection(configuredRESPChannel: channel, backgroundLogger: .redisBaseConnectionLogger)
return RedisConnection(configuredRESPChannel: channel, backgroundLogger: .redisBaseConnection)
}

func createPool(maximumConnectionCount: Int, minimumConnectionCount: Int, leaky: Bool) -> ConnectionPool {
Expand All @@ -47,7 +47,7 @@ final class ConnectionPoolTests: XCTestCase {
minimumConnectionCount: minimumConnectionCount,
leaky: leaky,
loop: self.server.loop,
backgroundLogger: .redisBaseConnectionPoolLogger
backgroundLogger: .redisBaseConnectionPool
) { loop in
loop.makeSucceededFuture(self.createAConnection())
}
Expand All @@ -64,7 +64,7 @@ final class ConnectionPoolTests: XCTestCase {
minimumConnectionCount: minimumConnectionCount,
leaky: leaky,
loop: self.server.loop,
backgroundLogger: .redisBaseConnectionPoolLogger,
backgroundLogger: .redisBaseConnectionPool,
connectionFactory: connectionFactory
)
}
Expand Down Expand Up @@ -838,18 +838,18 @@ extension ConnectionPoolTests {
// MARK: ConnectionPool context erasing overloads

extension ConnectionPool {
func activate() { self.activate(logger: .redisBaseConnectionPoolLogger) }
func activate() { self.activate(logger: .redisBaseConnectionPool) }

func leaseConnection(deadline: NIODeadline) -> EventLoopFuture<RedisConnection> {
self.leaseConnection(deadline: deadline, logger: .redisBaseConnectionPoolLogger)
self.leaseConnection(deadline: deadline, logger: .redisBaseConnectionPool)
}

func returnConnection(_ connection: RedisConnection) {
self.returnConnection(connection, logger: .redisBaseConnectionPoolLogger)
self.returnConnection(connection, logger: .redisBaseConnectionPool)
}

func close(promise: EventLoopPromise<Void>? = nil) {
self.close(promise: promise, logger: .redisBaseConnectionPoolLogger)
self.close(promise: promise, logger: .redisBaseConnectionPool)
}
}

Expand Down

0 comments on commit 1d5a2f7

Please sign in to comment.