Commit Graph

384 Commits

Author SHA1 Message Date
Fabian Fett 1ad1f208ab Merge branch 'main' into docs/jo/remove-test-table 2023-06-19 14:45:58 +02:00
Fabian Fett 11b4673523 Conform RedisByteDecoder to NIOSingleStepByteToMessageDecoder (#63) 2023-06-19 10:52:59 +02:00
Joannis Orlandos 976ef7a4a1 Merge branch 'main' into docs/jo/remove-test-table 2023-06-19 10:42:41 +02:00
Joannis Orlandos 1764c85160 Remove a footnote 2023-06-19 10:40:01 +02:00
Joannis Orlandos 89313153f2 Remove the supported OSes section 2023-06-19 10:37:35 +02:00
Fabian Fett ef5fdf7e63 Delay connection attempts without addresses. (#64)
In some circumstances users may have connection pools configured without
any SocketAddresses ready to go. This is particularly likely in service
discovery configurations. Right now, the effect of attempting to use
such a pool is two fold. First, we'll emit a bunch of error level logs
telling users we have no addresses. Second, we'll fall into the
exponential backoff phase of connection establishment.

The first property is annoying, but the second one is actively harmful.
If your construction is timed incorrectly, we'll have the awkward
problem of burning a bunch of CPU trying to create connections we know
we cannot, and then a lengthy delay after the addresses are actually
configured before we start trying to use them. That's the worst of all
worlds.

This patch adds logic to detect the attempt to create connections when
we don't have any configured addresses and delays them. This path should
improve performance and ergonomics when in this mode.

Authored-by: Cory Benfield <lukasa@apple.com>
2023-06-19 10:37:15 +02:00
Fabian Fett 5fadd5fe06 Require Swift 5.6 (#65) 2023-06-19 00:40:53 -07:00
Joannis Orlandos 2f3db6ef11 Remove reliance on the NIO umbrella module (#60) 2023-06-19 09:37:04 +02:00
Joannis Orlandos 18a78f2a4f Also remove the table that displays the dependencies & supported language releases 2023-06-18 14:07:33 +02:00
Joannis Orlandos b6a6e4c874 Delete the testing table 2023-06-18 14:05:53 +02:00
Fabian Fett 60021f99bc Remove codeclimate (#55) 2023-06-16 11:11:58 -07:00
Fabian Fett 4bdcd203fc Remove github funding and issue and pr template (#53) 2023-06-16 20:01:56 +02:00
Fabian Fett a0e908845e Cherry pick: Explicitly depend on Atomics (#57) 2023-06-16 19:55:58 +02:00
Fabian Fett 10a5c3949e Add soundness and api breakage CI (#58) 2023-06-16 19:50:46 +02:00
Fabian Fett 35e0d67e84 Fix crash in tests: Use explicit RedisCommand instead of tuple (#52) 2023-06-16 19:15:42 +02:00
Fabian Fett a7d196e813 Add swift-server CI (#54) 2023-06-16 18:37:34 +02:00
Marius Seufzer 43d94452a8 call onUnexpectedConnectionClose on closeFuture 1.4.1 2023-06-13 11:34:05 +02:00
Marius Seufzer 2fd4db68e9 fix compiler error for pre 5.7 swift versions 2023-06-12 13:19:09 +02:00
Nathan Harris 0862006557 [Misc] Update contributors list 1.4.0 2023-06-10 09:44:14 -05:00
Marius Seufzer 5875335e08 Add onUnexpectedConnectionClose callback to pool
Backports `onUnexpectedConnectionClose` on the pool to 1.x
2023-06-09 18:58:21 +00:00
Gwynne Raskind 3bd5940b07 Make the parameter-less RedisClientError factory statics computed properties. As stored properties, they trigger Thread Sanitizer errors when multiple connections trigger the same errors (usually connectionClosed) too close together due to lazy once-only initialization. 1.3.3 2023-05-27 21:56:49 -05:00
Nathan Harris 254e3e78b3 Add support for Swift Package Index documentation hosting
This is a cherry-pick of commit 4e2217cffd
1.3.2
2023-01-19 22:40:08 -06:00
Nathan Harris 4ed1aa5596 [Misc] Update contributors 2022-12-12 21:32:30 -06:00
Fabian Fett c85f857554 Add support for graceful shutdown to the RedisCommandHandler 2022-12-07 17:15:42 +01:00
Nathan Harris b5c0bc8e05 Bump minimum supported Swift version to 5.5
## Motivation

RediStack 1.x is going to be supported at least until 2.x is released, which is a few months away.

Developers who are on later versions of Swift will adopt later versions of NIO and other libraries, and after we merged !183 we required NIO 2.42.x which has a minimum Swift version of 5.5

## Changes

This back ports the CI config from `master` into this branch, with updates to the README to reflect the changes
2022-11-30 21:35:43 -06:00
Michael Stegeman 68ccc40414 Switch from NIOAtomic to ManagedAtomic. 2022-11-30 14:29:30 +01:00
Fabian Fett ff495ef0d8 Fix NIOLock warning
# Conflicts:
#	Package.swift
#	Sources/RediStack/RedisConnection.swift
2022-11-26 14:02:12 +01:00
Nathan Harris 5458d6476e Backdeploy #100 fix and deprecate Channel Redis pipeline APIs
This is a backdeploy of commit cfb99ba0f7.

This fixes issue #100
1.3.0
2022-04-23 22:58:39 -05:00
Nathan Harris ad435902f2 Update deprecation annotations to support "fixit" helpers in Xcode 2022-04-23 22:43:49 -05:00
Nathan Harris b277715a02 104 -- Use correct base method for zrevrange overload methods 1.2.2 2022-03-14 23:08:14 -05:00
Nathan Harris 16037bbb82 102 -- Remove usage of deprecated NIO ELF APIs 1.2.1 2022-01-03 12:42:58 -06:00
Nathan Harris 0c3beee7eb 95 -- Backport unexpected channel closure callback
This is a cherry-pick commit of ad316a97ac
1.2.0
2021-08-16 22:01:25 -07:00
Nathan Harris edadec93a1 Get pubsub numsub working
This was a cherry-pick of 3ca471b226
1.1.2
2021-05-04 20:59:50 -07:00
Nathan Harris a0af03c534 Get pubsub numpat working
This was a cherry-pick of e08b42616b

Only the unit test was needed to be back-ported
2021-05-04 20:58:33 -07:00
Nathan Harris 5f758ba866 Fix pubsub channels
This was a cherry-pick of 9958e2d13b

Only the unit test was needed to be back-ported
2021-05-04 20:57:32 -07:00
Nathan Harris 8bf26fb661 Rename RedisKeyLifetime to be nested in RedisKey
Motivation:

`RedisKeyLifetime` already has "RedisKey" as a prefix so it naturally fits as a nested type.

Modifications:

- Change: `RedisKeyLifetime` to be nested in `RedisKey` and named `Lifetime`
- Rename: `RedisKeyLifetime.Lifetime` to `Duration`
- Deprecate: `RedisKeyLifetime` and the nested type `Lifetime`

Result:

The global namespace is a little less cluttered with the types falling naturally where they already are.
2020-11-27 14:05:14 -08:00
Nathan Harris b2367ac33e 81 -- Add Configuration types for initialization 1.1.0 2020-11-22 00:17:22 -08:00
Nathan Harris ec1a38ba7f Update README to clarify Swift version support and update process 2020-11-22 03:53:14 +00:00
Nathan Harris 02ab82c1ac Update README to have latest correct information regarding versions 2020-11-22 03:45:14 +00:00
Nathan Harris 833fc33881 Fix RedisConnectionPool.leaseConnection code example 2020-10-18 18:48:46 +00:00
Nathan Harris 61cc879efe Change RedisConnection to end subscriptions when not allowed
Motivation:

When `RedisConnection.allowSubscriptions` is set to `false`, the connection could still be in a subscription state
leaving further commands to fail slowly from a full roundtrip to Redis, rather than succeeding as expected.

This changes the implementation so that it triggers a full unsubscribe from patterns and channels when set to `false`.

Modifications:

- Change: `RedisConnection.allowSubscriptions` to call `unsubscribe()` and `punsubscribe()` when set to `false`
- Change: `RedisPubSubHandler` to prefix storage of all dictionary keys to avoid name clashes between pattern and channel subscriptions

Result:

Developers should now have more deterministic and unsurprising behavior with PubSub
in regards to subscription management and connection state.
1.0.0
2020-10-16 22:14:56 -07:00
Nathan Harris e0d47f7330 Fix [p]unsubscribe from all
Motivation:

The methods of unsubscribing from all channels / patterns were not working as expected as they need to be special-case handled.

Modifications:

- Change: `RedisPubSubHandler` to be special-case unsubscribe when no arguments are provided

Result:

Developers should now properly be able to unsubscribe from all channels / patterns with a single method call.
2020-10-16 20:41:27 -07:00
Nathan Harris 42e8d4b127 Allow repeated commands to same connection in pool
Motivation:

Some Redis commands are very connection specific that have impacts on future access that makes it difficult in the current
checkout-use-return cycle that `RedisConnectionPool` uses.

Developers need a way to borrow a specific connection, chain several commands together, and then return the connection to the pool.

Modifications:

- Add: `leaseConnection` method to `RedisConnectionPool` which provides a connection from the pool and returns it after a provided closure's ELF resolves
- Add: `allowSubscriptions` property to `RedisConnection` for controlling the ability to make PubSub subscriptions
- Add: `RedisClientError.pubsubNotAllowed` case for when `RedisConnection.allowSubscriptions` is set to `false` and a subscription was still attempted

Result:

Developers should now have an "escape hatch" with `RedisConnectionPool` to do limited exclusive chains of operations on a specific connection.
2020-10-15 13:39:58 -07:00
Nathan Harris 56f0ab0bc0 Add test case for RedisConnectionPool connectionRetryTimeout 2020-10-06 20:19:26 -07:00
Nathan Harris c8cb256b59 Add default buffer connectionRetryTimeout to avoid literal immediate timeouts
Motivation:

When trying to allow users to configure the connection retry timeout offset,
not having a value provided (deadline of `now`) caused all attempts to use the pool to fail.

Modifications:

- Change: RedisConnectionPool to always have a timeout offset defined

Result:

If users don't specify any value, then the default of 60 seconds will be used.

If users specify "nil" (or `.none`) as the timeout, then a minimum of 10 milliseconds will be used to avoid immediate timeouts

Otherwise, use the user's specified `TimeAmount` as the offset of the timeout
1.0.0-rc.2
2020-10-06 20:06:29 -07:00
Nathan Harris 3e28e75b6a Add configuration option for RedisConnectionPool lease timeout
Motivation:

With RedisConnectionPool a timeout is provided to prevent infinite loops of
retrying connections, but right now it is hardcoded to 60 seconds.

Users of downstream projects such as Vapor are noticing a "regression" of sorts, as previously
EventLoopFutures would fail immediately if a connection was not made available.

Modifications:

- Add: `connectionRetryTimeout` parameter to `RedisConnectionPool` initializer that still defaults to 60 seconds
- Change: RedisConnectionPool to use the new parameter if available to offset a deadline from "now"

Result:

Users can now configure the connection pool to fail immediately if connections are not available.
1.0.0-rc.1
2020-10-06 19:33:43 -07:00
Nathan Harris e858c0a66e Resolve PubSub post-commit feedback
Motivation:

To ship PubSub faster, it was merged to the master branch without a peer review. This commit is to address the critical points of feedback given in a post-commit review.

Modifications:

- Add: New RedisClientError case where a "race condition" of removing a pubsub handler and subscription can happen
- Add: New state to RedisPubSubHandler for when it has been removed from a ChannelPipeline
- Change: RedisPubSubHandler to require an `eventLoop` in its initializer
- Change: The subscribe and unsubscribe methods on RedisPubSubHandler to handle the EventLoop hopping to be thread-safe

Result:

PubSub should have a more robust and thread-safe implementation.
2020-10-01 22:30:59 -07:00
Nathan Harris e7b597fc65 Add support for PubSub
Motivation:

One of the great features of Redis is being able to subscribe and receive messages published to specific channels
as a way of acting as a message queue for processing jobs.

PubSub requires a specific understanding of the connection model that can only be implemented directly in this library.

Modifications:

- Add: `RedisPubSubHandler` to sit in front of `RedisCommandHandler` to manage subscription callbacks and Redis registration
- Add: `publish` and the `pubsub` commands
- Add: `addPubSubHandler` extension to `NIO.Channel`
- Add: Type-safe String wrapper of `RedisChannelName` for PubSub methods
- Add: `pubsubSubscriptionNotFound` error case
- Add: `isSubscribed` property to `RedisConnection`
- Add: `availableConnectionCount` and `leasedConnectionCount` properties to `RedisConnectionPool`
- Add: Metrics for PubSub
- Add: `makeNewPool` factory method to `RedisConnectionPoolIntegrationTestCase`
- Change: `RedisClient` to require methods for PubSub management, as they are intrinsicly tied to the client's connection model
- Change: Parsing of `PING` response for handling special case in PubSub mode
- Rename: `ActiveConnectionGauge` to `RedisMetrics.IncrementalGauge`

Result:

Developers will now be able to use Redis in PubSub mode with both connections and pools.

This resolves #6
1.0.0-beta.2
2020-09-29 22:23:44 -07:00
Nathan Harris 45f665b985 [CI] -- Update to use official Swift 5.3 release images 2020-09-17 23:02:15 -07:00
Nathan Harris 6fe37cb7e4 Fix RedisCommandHandler never reaching error state 2020-09-08 10:56:44 -07:00