Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.version == 'nightly' }}
strategy:
fail-fast: false
matrix:
Expand All @@ -20,29 +21,38 @@ jobs:
arch:
- x64
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
- uses: actions/cache@v4
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@v1
- name: Update /etc/hosts for TLS test
run: echo "127.0.0.1 redisjltest" | sudo tee -a /etc/hosts
- name: Start redis server
run: |
echo "Starting redis server"
pwd
test/conf/redis.sh
sleep 5
echo "Redis started"
- name: Start redis cluster
run: |
echo "Starting redis cluster"
chmod +x test/conf/redis-cluster.sh
test/conf/redis-cluster.sh
sleep 10
echo "Redis cluster started"
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
Expand Down
3 changes: 2 additions & 1 deletion src/Redis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using MbedTLS
import Base.get, Base.keys, Base.time

export RedisException, ConnectionException, ServerException, ProtocolException, ClientException
export RedisConnection, SentinelConnection, TransactionConnection, SubscriptionConnection,
export RedisConnection, SentinelConnection, TransactionConnection, SubscriptionConnection, RedisClusterConnection,
disconnect, is_connected, open_transaction, reset_transaction, open_subscription,
open_pipeline, read_pipeline
# Key commands
Expand Down Expand Up @@ -65,5 +65,6 @@ include("connection.jl")
include("parser.jl")
include("client.jl")
include("commands.jl")
include("cluster_commands.jl")

end
73 changes: 66 additions & 7 deletions src/client.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
import DataStructures.OrderedSet

const CLUSTER_MULTI_KEY_COMMANDS = Set([
# String commands - multi-key operations
"mget", "mset", "msetnx",

# Key commands - require same slot or special handling
"del", "rename", "renamenx", "keys", "randomkey",

# List commands - require same slot
"rpoplpush", "brpoplpush",

# Set commands - multi-key operations
"smove", "sdiff", "sinter", "sunion",
"sdiffstore", "sinterstore", "sunionstore",

# HyperLogLog commands - multi-key operations
"pfcount", "pfmerge",

# Sorted Set commands - multi-key operations
"zinterstore", "zunionstore",

# Bit commands - multi-key operations
"bitop",

# Script commands - may involve multiple keys
"eval", "evalsha",

# Server commands - need to broadcast to all nodes
"flushall", "flushdb", "_time",

# Pub/Sub commands - need special handling
"publish"
])

flatten(token) = string(token)
flatten(token::Vector{UInt8}) = [token]
flatten(token::String) = token
Expand Down Expand Up @@ -171,11 +204,14 @@ end
macro redisfunction(command::AbstractString, ret_type, args...)
is_exec = Symbol(command) == :exec
func_name = esc(Symbol(command))
command = lstrip(command,'_')
command = split(command, '_')
command_str = lstrip(command, '_')
command = split(command_str, '_')

# Check if command needs special cluster handling (multi-key commands)
needs_special_cluster_handling = command_str in CLUSTER_MULTI_KEY_COMMANDS

if length(args) > 0
return quote
base_functions = quote
function $(func_name)(conn::RedisConnection, $(args...))
response = execute_command(conn, flatten_command($(command...), $(args...)))
convert_response($ret_type, response)
Expand All @@ -191,6 +227,17 @@ macro redisfunction(command::AbstractString, ret_type, args...)
execute_command_without_reply(conn, flatten_command($(command...), $(args...)))
end
end

if !needs_special_cluster_handling
push!(base_functions.args, :(
function $(func_name)(conn::RedisClusterConnection, $(args...))
response = execute_command(conn, flatten_command($(command...), $(args...)))
convert_response($ret_type, response)
end
))
end
return base_functions

else
q1 = quote
function $(func_name)(conn::RedisConnection)
Expand All @@ -209,12 +256,24 @@ macro redisfunction(command::AbstractString, ret_type, args...)
conn.num_commands += 1
end
end

exprs = [q1.args[2]]
if !needs_special_cluster_handling
q1_cluster = quote
function $(func_name)(conn::RedisClusterConnection)
response = execute_command(conn, flatten_command($(command...)))
convert_response($ret_type, response)
end
end
push!(exprs, q1_cluster.args[2])
end

# To avoid redefining `function exec(conn::TransactionConnection)`
if is_exec
return Expr(:block, q1.args[2], q3.args[2])
else
return Expr(:block, q1.args[2], q2.args[2], q3.args[2])
if !is_exec
push!(exprs, q2.args[2])
end
push!(exprs, q3.args[2])
return Expr(:block, exprs...)
end
end

Expand Down
Loading
Loading