Commit Graph
373 Commits
Author SHA1 Message Date
Nathan Harris 9def1b9aab [CI] Restructure CI to be simpler with overrides 2021-11-02 23:44:46 -07:00
Nathan Harris 5ed6375e43 Set Swift 5.3 as the minimum version 2021-11-02 23:43:25 -07:00
Nathan Harris ad316a97ac 95 -- Add callback closure on RedisConnection invoked on channel close 2021-08-16 21:47:20 -07:00
Nathan Harris 2cc63ec8f2 [Docs] Add security policy 2021-06-01 14:05:30 -07:00
Peter Adams 3ca471b226 Get pubsub numsub working 1.1.1 2.0.0-alpha.3 2021-05-04 16:26:35 +00:00
Peter Adams e08b42616b Get pubsub numpat working 2021-05-03 20:49:16 +00:00
Peter Adams 410a5b2d03 Change the scan test to accept up to 8 odd keys
This attempts to fix #23
2021-05-03 20:43:04 +00:00
Peter Adams 9958e2d13b Fix pubsub channels 2021-05-02 20:39:18 +01:00
Nathan Harris f0d123fdaa Disable scan unit tests again as they are still flaky 2021-04-29 09:31:38 -07:00
Peter Adams 0c13e4f26c Get scan working on the same as redis-cli 6.2.1 2021-04-28 13:45:06 +01:00
Nathan Harris 03a066f8f5 Audit log message severity levels
Motivation:

Following the SSWG guidelines for libraries and log levels, because much of the library's behavior is expressed in the language and NIO framework as errors and failed ELFs, logging at error is "verbose" and takes away control from developers.

Modifications:

Log messages have been adjusted to more accurately represent when and how the log message should be used, especially when ELFs are failed or errors are thrown.

Result:

Developers won't have log messages at error or critical unless they opt-in from their own code, unless the library has no way of expressing the failure condition through the language.
2021-04-08 20:22:10 -07:00
Peter Adams 328ef17c2c Correct minor typo in documentation 2021-03-16 15:48:41 +00:00
Nathan Harris c8637c1ffa [Docs] Update README to include new dependency 2.0.0-alpha.2 2021-03-08 10:51:15 -08:00
Cory Benfield 1168ed09f7 Add support for service discovery.
The newly-released Service Discovery framework gives us the interesting
opportunity to make RediStack aware of complex service discovery tools.
This patch supplies a simple adaptor to integrat Service Discovery with
RediStack's pooled client, allowing users to work with arbitrary service
discovery systems.
2021-03-08 17:18:38 +00:00
Cory Benfield 338a6f4aa1 Delay connection attempts without addresses.
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.
2021-03-03 21:53:45 +00:00
Nathan Harris 5b05e26300 Remove 1.x deprecation support 2021-02-22 11:08:04 -08:00
Nathan Harris 79d0fd8652 [Docs] Update README to use emoji instead of markdown for docsgen 2.0.0-alpha.1 2021-02-16 11:14:36 -08:00
Nathan Harris 40d521c148 [Docs] Update README to better reflect the reality of the library's development 2021-02-16 11:08:03 -08:00
Nathan Harris e2e8890cbf [CI] Add definition for 5.4 docker images, update README 2021-02-16 11:01:44 -08:00
Nathan Harris edb550f233 [CI] Simplify config setup 2021-02-06 20:12:03 -08:00
Nathan Harris 3c6713038d Refactor RedisCommand into a general use object
Motivation:

RediStack today represents a command as a temporary object for the purpose of writing to the channel.

While it is useful to have an object for that purpose, commands handled in this way require immediate execution
and aren't available for other purposes.

Commands can serve a better purpose as a lightweight object to support delayed execution,
so that pipeling as described in issue #63 could be possible.

Modifications:

- Add: `get` overloads for JSON codable interaction on `RedisClient`
- Add: New `RedisZRangeResultOption` type for better interactions with zrange operations that can optionally return scores
- Add: New `RedisHashFieldKey` for type-safety when working with Hash field keys much like `RedisKey`
- Change: A few API types from enums to structs for library evolution
- Change: `RedisCommandHandler` to operate on a tuple of `RESPValue, EventLoopPromise<RESPValue>` rather than `RedisCommand`
- Change: `RedisCommand` to be a generic struct with the keyword, arguments, and a transform closure to defer execution
- Change: Almost all `RedisClient` command extensions to be factory methods on `RedisCommand` instead
- Change: Many response types to be optional to avoid developers having to do `isNull` checks on their own
- Change: `RedisClient.send(command:arguments:)` to be generic with `send(_:)` as the signature
- Rename: RedisClient extensions for scan methods to be more discoverable and legible as `scanHashField`, etc.

Result:

It should be easier to support a clean pipelining API with deferred command execution,
with extensions being easier for 2nd party developers, and the maintenance overhead of all of the command extensions
should be a little lighter when it comes to changing HOW commands are sent such as adding a context parameter
2020-12-02 08:41:59 +00:00
Nathan Harris 61fb40b194 Remove Trunk column of historical test matrix in README 2020-12-02 00:41:19 -08:00
Nathan Harris ba35a1f91d Add historical test matrix to README 2020-12-02 00:39:43 -08:00
Nathan Harris b148491635 Set Swift 5.2 as the minimum version 2020-12-02 00:29:17 -08: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
Nathan Harris 8fb1aed715 Update contributors 1.0.0-beta.1 2020-08-31 22:37:03 -07:00
Nathan Harris 90244e327b Refactor Logging implementation
Motivation:

The original implementation of Logging was done in more haste than should have been, without proper attention given to the semantic requirements.

As the Swift ecosystem has matured a bit, lessons have been learned on handling metadata and passing of external context into internal subcomponents.

A mixture of the "protocol-based context passing" and "explicit context passing" patterns have been adopted.

Both patterns are more fully described in the Swift forum discussion: https://forums.swift.org/t/the-context-passing-problem/39162

Modifications:

- Add: `RedisLogging` namespace with references to static keys and labels that are used for Logging throughout the library
- Add: `Logger` static computed properties to access the Logger prototypes used in connection and connection pools
- Add: `RedisClientWithUserContext` protocol and `UserContextRedisClient` types to assist with wrapping client types for custom logger contexts
- Remove: `logger` property from `RedisClient` requirements
- Change: Many log statements to have higher or lower log levels for their appropriate context
- Change: `RedisConnection` and `RedisConnectionPool` to conform to `RedisClientWithUserContext`
- Change: `logging(to:)` protocol requirement to return a `RedisClient` existential
- Change: ConnectionPool to explicitly pass a logger instance around for pooling methods

Result:

Logging in RediStack will now have a stronger contract of where and how logs will be generated and which context will be used.

Fixes #79 and #74
2020-08-31 22:07:59 -07:00
Nathan Harris 1cf438ea2b Add Swift 5.3 testing for more platforms 2020-08-30 16:20:54 -07:00
Nathan Harris cfb02ba827 Add CI testing on CentOS 7 2020-08-30 15:27:35 -07:00
Nathan Harris 5c4fe9619b Disable logging unit tests until they are fixed 2020-08-30 14:42:52 -07:00
Nathan Harris 610915a909 Add new 'RedisTypes' module
Motivation:

Redis is written in C, so even though it has concepts of "types" such as SortedSet or List
its commands are all "free-floating" functions.

This can make it unfamiliar for those new to Redis to work within its systems and understand the relation of all of the commands.

RediStack can improve this by giving a way of having a consistent reference to a Redis type and all of its associated methods.

Modifications:

- Add: New library product called "RedisTypes"
- Add: First type to "RedisTypes", `RedisSet`

Result:

Newcomers to Redis will have an easier time getting familiar with the APIs and working with its types by having wrappers that
provide a familiar Swift Standard Library API tailored to Redis APIs.
2020-08-30 14:33:21 -07:00
Nathan Harris 85cbb614b8 Add GitHub issue template to redirect users to GitLab 2020-08-30 14:02:44 -07:00
Nathan Harris e56df0c469 Fix project logo in README 2020-08-29 21:04:40 -07:00
Nathan Harris d2fcb61f56 Drop support for Swift 5.0 2020-08-09 16:34:59 -07:00
tanner 40d1a587f1 Add optional promise parameter to RedisConnectionPool.close
Motivation:

The actual process for closing a connection pool involves closing each individual connection, which is all asynchronous.

There is currently no way to work off of the event when all of the connections have completed their close process.

Modifications:

- Add: `poolHasActiveConnections` error value to `RedisConnectionPoolError`
- Add: `promise` parameter to the `RedisConnectionPool.close` method
- Add: Documentation comments for the close method

Result:

Developers should now have a way of chaining callbacks when all connections in a pool have been closed.
2020-08-04 22:16:38 -07:00
Nathan Harris ff25332d9d Add official Swift 5.2 releases for other Linux distros to CI 2020-08-01 23:15:50 -07:00