Commit Graph

263 Commits

Author SHA1 Message Date
Nathan Harris c18ff4341c no message 2019-12-06 19:54:00 -08:00
Nathan Harris 0bd95cc347 no message 2019-11-28 16:24:43 -08:00
Nathan Harris d384deb011 Replace SHA1 Implementation
Motivation:

The `CNIOSHA1` module from SwiftNIO is an implementation detail. The fact that we were able to import and build the project with it is a bug/feature of Swift Package Manager.

Should the Swift ecosystem standardize on an implementation, that will replace the one we have chosen later.

Modifications:

Use the SHA1 native Swift implementation from CryptoSwift by reproducing the necessary code in our project.
Updates to the appropriate files to provide attribution to CryptoSwift have been included.

Result:
A reliable and pure Swift implementation of the SHA1 digest algorithm in the project for the sake of Lua script cache hashing.
2019-11-28 11:59:21 -08:00
Nathan Harris 893c516cfb Merge branch 'scripting' into '44-lua-scripting'
Add scripting support

See merge request Mordil/swift-redi-stack!88
2019-11-28 18:38:00 +00:00
Liam Don be11ac5410 Consider this a first draft for adding scripting support to RediStack.
### General usage
Most users should only need to use the `evalScript` method. We take the approach recommended by the [redis EVAL docs](https://redis.io/commands/eval):
>>>
The client library implementation can always optimistically send EVALSHA under the hood even when the client actually calls EVAL, in the hope the script was already seen by the server. If the NOSCRIPT error is returned EVAL will be used instead.
>>>

To facilitate this, we introduce a RedisScript struct, which calculates the sha1 hash on the client and stores it alongside the script source. I took inspiration for this approach from the [radix golang library](https://github.com/mediocregopher/radix). The struct makes using scripts a bit easier/nicer, and guides the developer toward the highest performance approach, but I'm curious whether you think it's an unnecessary abstraction.

One disadvantage of the optimistic approach using `EVALSHA` is that the `evalScript` may not be atomic if the script is not cached yet, which will be a problem if we are using it during an explicit pipeline or MULTI/EXEC operation. The redis docs recommend using `SCRIPT LOAD` before a multi/exec operation to avoid this. I think we could leave this up to the application developer.

### Should we implement the basic commands?
The approach above forces the application developer to use the evalScript method instead of exposing either `EVAL` or `EVALSHA` directly. This is to avoid the behavior of only using `EVAL` without caching, which might otherwise seem like the natural choice. If you think this is too opinionated, we can also add basic `eval` and `evalSha` methods.

### SHA1 calculation
I've copied the approach used by the SwiftNIO developers - RediStack already includes the `CNIOSHA1` module required.
There's a comment in [their private implementation](https://github.com/apple/swift-nio/blob/master/Sources/NIOWebSocket/SHA1.swift#L17) which indicates they're not entirely happy with this, but consider it the best approach for server-side Swift for now. I think we could follow their lead and migrate to a standard library method if/when it becomes available.

The `sha1` method is added as an extension property on String. Because it can theoretically fail, the `sha1` property is optional and thus the RedisScript initializer is failable, which is a bit unpleasant. I don't think the sha1 calculation should never actually fail given a String input. A force unwrap in the sha1 property would remove several code smells [like this](https://gitlab.com/liamdon/swift-redi-stack/blob/scripting/Sources/RediStack/Commands/ScriptingCommands.swift#L92), but I left it out in case you have a strong opposition to force unwraps - let me know what you think.

### Not implemented
I have not implemented `SCRIPT DEBUG` or `SCRIPT KILL`, because these seem more like sysadmin tasks that should not be in a client library. But they can easily be added if we want full coverage of the scripting commands.
2019-11-28 18:38:00 +00:00
Nathan Harris e0ebf9266b Merge branch 'variadic-overloads' into 'master'
Add variadic overloads for several commands

See merge request Mordil/swift-redi-stack!87
1.0.0-alpha.6.1
2019-10-27 07:01:05 +00:00
Nathan Harris adcff65030 Add variadic overloads for several commands
Motivation:

For ergonomics, users sometimes want to provide arguments as a variadic list rather than an array.

Modifications:

- Add variadic overloads for almost all methods that accept lists of homogenous types

Result:

Users should have more flexibility in the way arguments are passed to command methods
2019-10-26 23:55:47 -07:00
Nathan Harris 8ce1dd8257 Merge branch 'generic-get' into 'master'
Add RedisClient.get generic overload

See merge request Mordil/swift-redi-stack!86
2019-10-27 06:28:52 +00:00
Nathan Harris 9e5179f3e4 Add RedisClient.get generic overload
Motivation:

It is wrong to always assume that a GET operation is expecting a String response type, as users may be storing other types of data.

Modifications:

- Add `get` generic method with a constraint for types of `RESPValueConvertible` to convert values to the user desired type
- Change existing `get` method to specialize the generic overload
- Fix incorrect doc block regarding the ELF failure condition

Result:

Users should now be able to specialize the return type of a "GET" command
2019-10-26 22:50:58 -07:00
Nathan Harris 5c39c83663 Add dev Docker Compose file 2019-10-26 22:47:23 -07:00
Nathan Harris a3f6d3b834 Merge branch 'remove-assertions' into 'master'
Remove unnecessary assertions in `RedisCommandHandler`

See merge request Mordil/swift-redi-stack!85
2019-10-07 14:38:33 +00:00
Nathan Harris ba66ebf81e Remove unnecessary assertions in RedisCommandHandler
Motivation:

The assertions in `errorCaught(context:error:)` and `channelRead(context:data:)` are holdovers from when SwiftLog was not integrated into the package. The conditions where they were triggered are safely handled in other ways, so the asserts are not guarding against undefined behavior or bad app state.

Modifications:

Remove the two asserts regarding the `RedisCommandHandler.commandResponseQueue` to rely on Logging to bubble up errors to the user.

Result:

Debug builds using RediStack should not encounter unexpected assertions and should rely on other, better, error handling.

This contributes to issue #65
2019-10-07 07:24:00 -07:00
Nathan Harris 237f049c81 Merge branch 'thread-sanitizer' into 'master'
Run thread sanitizer on 5.1 test CI jobs

See merge request Mordil/swift-redi-stack!84
1.0.0-alpha.6
2019-09-24 03:06:15 +00:00
Nathan Harris 939e41b832 Fix data race with RedisMetrics.activeConnectionCount
Motivation:

After enabling the thread sanitizer during testing, a data race with the `activeConnectionCount` in `RedisMetrics` was caught due to changing a primitive `Int` across threads.

Modifications:

Add a specialized class `ActiveConnectionGauge` to wrap the semantics of the `activeConnectionCount` with an `Atomic<Int>` property.

Result:

No data races should occur with the `RedisMetrics` subsystem.
2019-09-23 20:03:20 -07:00
Nathan Harris dfca57046c Run thread sanitizer on 5.1 test CI jobs
Motivation:

Now that SwiftPM with 5.1 supports Linux thread sanitizers, we should run this as part of the normal test pass to catch threading issues.

Modifications:

Add `--sanitize=thread` argument to `swift test` commands for any job that runs Swift >=5.1.

Result:

More bugs should be caught as soon as possible now that thread races are being monitored.
2019-09-23 19:36:07 -07:00
Nathan Harris 2a27a598c3 Merge branch 'update-test-matrix' into 'master'
Update Test Matrix to include Swift 5.1 Official Release

See merge request Mordil/swift-redi-stack!83
2019-09-24 02:27:45 +00:00
Nathan Harris 3c4b5c407a Update Test Matrix to include Swift 5.1 Official Release
Motivation:

With the release of Swift 5.1, the official docker containers are available for both 16.04 and 18.04 of Linux - so the test matrix should include them.

Modifications:

- Add new 5.1 jobs for 18.04 linux and change 16.04 5.1 jobs to use the official docker images.
- Update the README to capture the changes

Result:

The number of configurations the library is tested against should be as wide as possible for regular interval testing passes.
2019-09-23 19:19:31 -07:00
Nathan Harris 9741a2ef4f Merge branch 'respvalue-nil-init' into 'master'
Change `RESPValue.init(bulk:)` initializers to accept a wider range of values

See merge request Mordil/swift-redi-stack!81
2019-07-29 05:19:09 +00:00
Nathan Harris 479c024d4b Change RESPValue.init(bulk:) initializers to accept a wider range of values
Motivation:

While working to add more test coverage with `RESPTranslator`, it was made apparent that a `.bulkString(.none)` is impossible to create directly with the `RESPValue` initializers, even though it is a reasonable possibility.

Additionally, forcing all integer types to have to be stored in an `Int` is unnecessarily restrictive.

Modifications:

- Change `RESPValue.init(bulk:)` initializers to accept `Optional` instances
- Change `RESPValue.init(bulk:)` for `Int` initializer to be generic on `FixedWidthInteger`

Result:

Converting types to and from `RESPValue` should be more bi-directional and seamless.
2019-07-29 05:05:39 +00:00
Nathan Harris b70923623b Merge branch 'more-resptranslator-tests' into 'master'
Add more test coverage of `RESPTranslator`

See merge request Mordil/swift-redi-stack!82
2019-07-29 05:04:19 +00:00
Nathan Harris b9b703078e Add more test coverage of RESPTranslator
Motivation:

Diagnostics for why `.bulkString` parses might fail were weak, and edge cases fell through gaps in coverage were found.

Modifications:

Added new cases to `RESPTranslator.ParsingError` for `.bulkString` parsing with additional test coverage.

Result:

Users should have better diagnostics for bogus data or failed parsing state.
2019-07-28 21:42:43 -07:00
Nathan Harris 8c3bdbac86 Merge branch 'update-linuxmain' into 'master'
Add missing `ByteToMessageDecoderVerifier` tests to Linux Main

See merge request Mordil/swift-redi-stack!80
2019-07-29 03:25:48 +00:00
Nathan Harris 0d4b520bb7 Add missing ByteToMessageDecoderVerifier tests to Linux Main
Motivation:

While working on issue #56, it was forgotten to add the new test cases to the linux manifest file.

Modifications:

Update the linux manifests to include all current unit tests

Result:

All written unit tests should be ran on Linux
2019-07-28 20:23:09 -07:00
Nathan Harris 879afb4c27 Merge branch 'faster-mr-ci' into 'master'
Speed up CI pipelines for Merge Requests

See merge request Mordil/swift-redi-stack!79
2019-07-29 03:18:16 +00:00
Nathan Harris 02d8d02176 Speed up CI pipelines for Merge Requests
Motivation:

MRs take unnecessarily too long to have completed pipelines with "redundant" builds happening in sequence.

The entire stage of building in release is an additional QA layer that can happen on merges into master, but for MRs are just added CPU cycles.

While it's useful to ensure that building in release is possible, we will get almost all build failures from the test stage, and the most important checks are the unit and integration tests.

Modifications:

Change the ordering of build vs. test, as well as only running "build in release" jobs on the master branch.

Result:

MRs should be able to be merged sooner as CI pipelines take less time to run.
2019-07-28 20:12:21 -07:00
Nathan Harris 50dba5c93a Merge branch '56-b2m-verifier-tests' into 'master'
56 -- Add `ByteToMessageDecoderVerifier` unit tests

Closes #56

See merge request Mordil/swift-redi-stack!78
2019-07-29 03:11:51 +00:00
Nathan Harris 556da6475f 56 -- Add ByteToMessageDecoderVerifier unit tests 2019-07-28 20:05:14 -07:00
Nathan Harris cd40320873 Merge branch 'test-util-connections' into 'master'
Change test utils RedisConnection process to be less opinionated.

See merge request Mordil/swift-redi-stack!74
2019-07-28 07:31:25 +00:00
Nathan Harris a09c434612 Change test utils RedisConnection process to be less opinionated.
Motivation:

After working with RedisKit with RediStackTestUtils as a dependency, it was realized how opinionated the module is in how RedisConnections can be created in test environments.

Modifications:

Require more information, with reasonable defaults for `RedisConnection.init()`. Provide subclass hooks for `RedisIntegrationTestCase` for implementors to make decisions for themselves at how to connect to Redis.

Result:

Users should have more freedom in how they connect to Redis in their units tests.
2019-07-28 00:21:07 -07:00
Nathan Harris 30a0774a2f Merge branch 'split-tests' into 'master'
Split tests into two targets: Unit tests and Integration tests

See merge request Mordil/swift-redi-stack!75
2019-07-28 07:17:14 +00:00
Nathan Harris ce43dad72e Split tests into two targets: Unit tests and Integration tests
Motivation:

For users looking to contribute, and for those looking to validate the library, it was unclear what tests require an actual connection to a Redis instance in order to run.

Modifications:

Add a `RediStackIntegrationTests` that takes all tests that require a Redis instance in order to run.

Result:

Those looking to run just unit tests, or contribute new tests, can now directly point to a specific testTarget as defined in the Package manifest.
2019-07-28 00:09:19 -07:00
Nathan Harris 1b4b5fa67d Merge branch 'rediserror-equatable' into 'master'
Add `Equatable` conformance for `RedisError`

See merge request Mordil/swift-redi-stack!77
2019-07-28 06:55:13 +00:00
Nathan Harris d702121f59 Add Equatable conformance for RedisError
Motivation:

There is a reasonable way to compare if two `RedisErrors` are equal, which was seen as needed in the `Equatable` conformance for `RESPValue`.

Modifications:

Added `Equatable` conformance for `RedisError` by comparing the messages.

Result:

Two `RedisError` instances are now equatable.
2019-07-27 23:48:40 -07:00
Nathan Harris 1d21f663de Merge branch 'respvalue-equatable' into 'master'
Add `Equatable` conformance to `RESPValue`

See merge request Mordil/swift-redi-stack!76
2019-07-28 06:42:19 +00:00
Nathan Harris 081c7ca855 Add Equatable conformance to RESPValue
Motivation:

While working on unit tests the need for conformance to `Equatable` for `RESPValue` has been needed a few times and it was decided to make it public.

Modifications:

Added conformance to `Equatable` for `RESPValue` with unit test.

Result:

Users should now be able to compare two `RESPValue` instances for equality.
2019-07-27 23:25:03 -07:00
Nathan Harris ca16cee332 Fix relative links in README to legal docs 1.0.0-alpha.5.0.2 2019-07-12 20:31:50 -07:00
Nathan Harris fae8eadad9 Make RedisConnection.sendCommandsImmediately public
Motivation:

During the refactor work (commit ea7c755) that was merged with MRs !71 and !53 - `sendCommandsImmediately` was accidentally lowered to `internal`

Modifications:

Properly mark `RedisConnection.sendCommandsImmediately` as `public`

Result:

Developers should now have proper access to the `sendCommandsImmediately` property
2019-07-12 20:30:53 -07:00
Nathan Harris 611cc4ebf8 Use swift test --generate-linuxmain to handle index of unit tests
Motivation:

A handful of times, unit tests were forgotten to be added to the `allTests` extension, or were incorrectly copy/pasted.

Modifications:

Remove manual entries of `allTest` and use generated result from `swift test --generate-linuxmain`

Result:

There should be proper test parity between macOS and Linux.
2019-07-12 19:41:20 -07:00
Nathan Harris 6791ba80e9 Fix relative links in README that were broken for docs site users 2019-07-11 14:52:02 -07:00
Nathan Harris aeae1f6c78 Properly export module 1.0.0-alpha.5.0.1 2019-07-10 22:46:20 -07:00
Nathan Harris f788056ecb Update documentation URL to new docs.redistack.info URL 2019-07-09 13:45:43 -07:00
Nathan Harris 0fbc2eb39f Add links to new support email.
Motivation:

As this project might take off and support be needed, users will want a direct line of communication to file support tickets.

Modifications:

Update docs to include references and links for contacting the RediStack maintainers for assistance.

Result:

Users should have more information on how to contact project maintainers.
2019-07-09 13:20:10 -07:00
Nathan Harris 0ecb3c1ef3 Iterate on type safety for zadd
Motivation:

Issue #60 called for improving the type safety of the options available for the `zadd` command, and MR !70 made some great headway, but attempted to cram too much into a single enum.

Modifications:

- Break the `RedisSortedSetAddOption.returnChangedCount` value into an additional boolean param

Result:

Using `zadd` should now be more straight forward, while being type safe.
1.0.0-alpha.5
2019-07-09 00:26:52 -07:00
Nathan Harris 2605763810 Rename RedisCommand properties to avoid overloading terms and being more specific.
Motivation:

There are several cases where "command" could refer to a command keyword, or an entire message (keyword + args). This made working with `RedisCommand` and it's documentation ambiguous.

Modifications:

- Rename `RedisCommand.command` to `message`
- Rename initializer labels to `message` and `responsePromise`

Result:

When encountering a `RedisCommand` everyone should know that they are dealing with a message that should be sent to Redis as soon as possible.
2019-07-08 23:48:19 -07:00
Nathan Harris 04aa1f93a3 Polish project documents
Motivation:

To give a better first impression, and providing more comprehensive information for first time viewers, the README file needed reworking.

Modifications:

- Add a CHANGELOG file that at least redirects readers to the releases page of GitLab
- Update the CONTRIBUTORS list
- Change project README to have more information, flow better, and to have a better "first impression"

Result:

The README should give a stronger indication into the project's health.
2019-07-08 23:06:57 -07:00
Nathan Harris f2df346097 Update Jazzy Doc Generation Script
Motivation:

Up until now, Jazzy docs were generated on a private CI runner hosting macOS - which doesn't make CI portable as it requires that runner to always be available.

Modifications:

- Change: CI config to use a Linux Jazzy Docker image for portability
- Change: Doc theme templates to not reference GitHub

Result:

Jazzy docs should be able to be generated at any time, as the CI infrastructure is using GitLab's cloud solution with a Docker image
2019-07-08 20:36:04 -07:00
Nathan Harris fd73e0abed Merge branch '61-rebrand' into 'master'
61 -- Rebrand from `RedisNIO` to `RediStack`

Closes #61

See merge request Mordil/swift-redis-nio-client!73
2019-07-09 02:53:58 +00:00
Nathan Harris 7e7e354697 61 -- Rebrand from RedisNIO to RediStack 2019-07-08 19:45:33 -07:00
Nathan Harris 57168eda35 Merge branch 'rename-errors' into 'master'
Rename `RedisNIOError` to `RedisClientError`

See merge request Mordil/swift-redis-nio-client!72
2019-07-09 02:42:13 +00:00
Nathan Harris 13432f0c09 Rename RedisNIOError to RedisClientError
Motivation:

To make it a little more generic, and to avoid turnover during renames (such as the planned rebranding in issue #61), `RedisClientError` more accurately reflects the source of the errors, as well as the responsibility of causing the bug.

Modifications:

- Rename `RedisNIOError` to `RedisClientError`
- Rename `RedisError` file to `RedisErrors`
- Add documentation of `RedisClientError`
- Remove no longer used `.unsupportedOperation(method:message:)` value
- Rename `.responseConversion(to:)` to `.failedRESPConversion(to:)`

Result:

Names of `RedisClientError` should be more descriptive, less prone to turnover, and more documented for users to understand the issues related to these thrown errors.
2019-07-08 19:34:57 -07:00