mirror of
https://github.com/swift-server/RediStack.git
synced 2026-05-03 07:32:28 +00:00
018a9b9626
We want to be able to efficiently encode Redis commands that are sent to a server. This patch adds a new `RedisCommandEncoder` that allows us to efficiently create Redis commands without needing to go through RESP representations, that may require us to create Arrays. Further it introduces a `RESP3BlobStringEncodable` that must be implement to send blob strings using `RedisCommandEncoder`. This patch also adds implementations for `String` and `ByteBuffer` for the new `RESP3BlobStringEncodable` protocol.
84 lines
2.3 KiB
Bash
Executable File
84 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
##===----------------------------------------------------------------------===##
|
|
##
|
|
## This source file is part of the RediStack open source project
|
|
##
|
|
## Copyright (c) 2023 RediStack project authors
|
|
## Licensed under Apache License v2.0
|
|
##
|
|
## See LICENSE.txt for license information
|
|
## See CONTRIBUTORS.txt for the list of RediStack project authors
|
|
##
|
|
## SPDX-License-Identifier: Apache-2.0
|
|
##
|
|
##===----------------------------------------------------------------------===##
|
|
|
|
set -eu
|
|
|
|
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
function genWithContextParameter() {
|
|
how_many=$1
|
|
|
|
if [[ $how_many -ne 1 ]] ; then
|
|
echo ""
|
|
fi
|
|
|
|
echo " @inlinable"
|
|
echo -n " mutating func encodeRESPArray<T0: RESP3BlobStringEncodable"
|
|
for ((n = 1; n<$how_many; n +=1)); do
|
|
echo -n ", T$(($n)): RESP3BlobStringEncodable"
|
|
done
|
|
|
|
echo -n ">(_ t0: T0"
|
|
for ((n = 1; n<$how_many; n +=1)); do
|
|
echo -n ", _ t$(($n)): T$(($n))"
|
|
done
|
|
echo ") {"
|
|
|
|
echo " self.buffer.writeBytes(\"*"$how_many"\\r\\n\".utf8)"
|
|
|
|
for ((n = 0; n<$how_many; n +=1)); do
|
|
echo " t$(($n)).encodeRedisBlobString(into: &self.buffer)"
|
|
done
|
|
echo " }"
|
|
}
|
|
|
|
grep -q "ByteBuffer" "${BASH_SOURCE[0]}" || {
|
|
echo >&2 "ERROR: ${BASH_SOURCE[0]}: file or directory not found (this should be this script)"
|
|
exit 1
|
|
}
|
|
|
|
{
|
|
cat <<"EOF"
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the RediStack open source project
|
|
//
|
|
// Copyright (c) 2023 RediStack project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of RediStack project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// NOTE: THIS FILE IS AUTO-GENERATED BY scripts/generate_rediscommandencoder_multi_encode.sh
|
|
EOF
|
|
echo
|
|
|
|
echo "#if swift(<5.9)"
|
|
echo "extension RedisCommandEncoder {"
|
|
|
|
# note:
|
|
# - widening the inverval below (eg. going from {1..15} to {1..25}) is Semver minor
|
|
# - narrowing the interval below is SemVer _MAJOR_!
|
|
for n in {1..7}; do
|
|
genWithContextParameter "$n"
|
|
done
|
|
echo "}"
|
|
echo "#endif"
|
|
} > "$here/../Sources/RediStack/RedisCommandEncoder-multi-encode.swift"
|