From f4708614a1c7a99bcd806503334885787de3b211 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 16 Feb 2026 21:33:16 +0000 Subject: [PATCH] chore(deps): update module github.com/redis/go-redis/v9 to v9.18.0 --- go.mod | 2 +- go.sum | 25 +- .../github.com/redis/go-redis/v9/.gitignore | 6 +- .../redis/go-redis/v9/.golangci.yml | 2 + vendor/github.com/redis/go-redis/v9/Makefile | 41 +- vendor/github.com/redis/go-redis/v9/README.md | 10 +- .../redis/go-redis/v9/RELEASE-NOTES.md | 164 +- .../github.com/redis/go-redis/v9/adapters.go | 7 + .../v9/auth/reauth_credentials_listener.go | 2 +- .../redis/go-redis/v9/cluster_commands.go | 6 + .../github.com/redis/go-redis/v9/command.go | 2380 ++++++++++++++++- .../go-redis/v9/command_policy_resolver.go | 209 ++ .../github.com/redis/go-redis/v9/commands.go | 11 + .../redis/go-redis/v9/docker-compose.yml | 80 +- vendor/github.com/redis/go-redis/v9/error.go | 14 + .../redis/go-redis/v9/geo_commands.go | 10 +- .../redis/go-redis/v9/hotkeys_commands.go | 122 + .../v9/internal/interfaces/interfaces.go | 5 + .../maintnotifications/logs/log_messages.go | 54 +- .../go-redis/v9/internal/otel/metrics.go | 279 ++ .../redis/go-redis/v9/internal/pool/conn.go | 31 +- .../go-redis/v9/internal/pool/conn_state.go | 14 +- .../redis/go-redis/v9/internal/pool/pool.go | 346 ++- .../redis/go-redis/v9/internal/pool/pubsub.go | 3 +- .../v9/internal/proto/redis_errors.go | 39 + .../v9/internal/routing/aggregator.go | 1000 +++++++ .../go-redis/v9/internal/routing/policy.go | 144 + .../v9/internal/routing/shard_picker.go | 57 + .../redis/go-redis/v9/internal/semaphore.go | 2 +- .../go-redis/v9/internal/util/atomic_max.go | 97 + .../go-redis/v9/internal/util/atomic_min.go | 96 + .../redis/go-redis/v9/internal/util/math.go | 27 - .../redis/go-redis/v9/internal/util/unsafe.go | 9 +- vendor/github.com/redis/go-redis/v9/json.go | 47 +- .../redis/go-redis/v9/list_commands.go | 8 + .../v9/maintnotifications/FEATURES.md | 41 +- .../go-redis/v9/maintnotifications/README.md | 10 +- .../go-redis/v9/maintnotifications/config.go | 11 +- .../v9/maintnotifications/handoff_worker.go | 19 +- .../go-redis/v9/maintnotifications/manager.go | 52 +- .../push_notification_handler.go | 260 +- .../github.com/redis/go-redis/v9/options.go | 44 +- .../redis/go-redis/v9/osscluster.go | 462 +++- .../redis/go-redis/v9/osscluster_router.go | 992 +++++++ vendor/github.com/redis/go-redis/v9/otel.go | 204 ++ .../redis/go-redis/v9/probabilistic.go | 72 +- vendor/github.com/redis/go-redis/v9/pubsub.go | 39 +- .../redis/go-redis/v9/pubsub_commands.go | 14 +- vendor/github.com/redis/go-redis/v9/redis.go | 205 +- vendor/github.com/redis/go-redis/v9/ring.go | 24 +- .../redis/go-redis/v9/search_commands.go | 377 ++- .../github.com/redis/go-redis/v9/sentinel.go | 164 +- .../redis/go-redis/v9/set_commands.go | 151 +- .../redis/go-redis/v9/sortedset_commands.go | 15 + .../redis/go-redis/v9/stream_commands.go | 92 +- .../redis/go-redis/v9/string_commands.go | 11 +- .../redis/go-redis/v9/timeseries_commands.go | 41 +- .../github.com/redis/go-redis/v9/universal.go | 138 +- .../github.com/redis/go-redis/v9/version.go | 2 +- vendor/go.uber.org/atomic/.codecov.yml | 19 + vendor/go.uber.org/atomic/.gitignore | 15 + vendor/go.uber.org/atomic/CHANGELOG.md | 127 + vendor/go.uber.org/atomic/LICENSE.txt | 19 + vendor/go.uber.org/atomic/Makefile | 79 + vendor/go.uber.org/atomic/README.md | 63 + vendor/go.uber.org/atomic/bool.go | 88 + vendor/go.uber.org/atomic/bool_ext.go | 53 + vendor/go.uber.org/atomic/doc.go | 23 + vendor/go.uber.org/atomic/duration.go | 89 + vendor/go.uber.org/atomic/duration_ext.go | 40 + vendor/go.uber.org/atomic/error.go | 72 + vendor/go.uber.org/atomic/error_ext.go | 39 + vendor/go.uber.org/atomic/float32.go | 77 + vendor/go.uber.org/atomic/float32_ext.go | 76 + vendor/go.uber.org/atomic/float64.go | 77 + vendor/go.uber.org/atomic/float64_ext.go | 76 + vendor/go.uber.org/atomic/gen.go | 27 + vendor/go.uber.org/atomic/int32.go | 109 + vendor/go.uber.org/atomic/int64.go | 109 + vendor/go.uber.org/atomic/nocmp.go | 35 + vendor/go.uber.org/atomic/pointer_go118.go | 31 + .../atomic/pointer_go118_pre119.go | 60 + vendor/go.uber.org/atomic/pointer_go119.go | 61 + vendor/go.uber.org/atomic/string.go | 72 + vendor/go.uber.org/atomic/string_ext.go | 54 + vendor/go.uber.org/atomic/time.go | 55 + vendor/go.uber.org/atomic/time_ext.go | 36 + vendor/go.uber.org/atomic/uint32.go | 109 + vendor/go.uber.org/atomic/uint64.go | 109 + vendor/go.uber.org/atomic/uintptr.go | 109 + vendor/go.uber.org/atomic/unsafe_pointer.go | 65 + vendor/go.uber.org/atomic/value.go | 31 + vendor/modules.txt | 7 +- 93 files changed, 10294 insertions(+), 606 deletions(-) create mode 100644 vendor/github.com/redis/go-redis/v9/command_policy_resolver.go create mode 100644 vendor/github.com/redis/go-redis/v9/hotkeys_commands.go create mode 100644 vendor/github.com/redis/go-redis/v9/internal/otel/metrics.go create mode 100644 vendor/github.com/redis/go-redis/v9/internal/routing/aggregator.go create mode 100644 vendor/github.com/redis/go-redis/v9/internal/routing/policy.go create mode 100644 vendor/github.com/redis/go-redis/v9/internal/routing/shard_picker.go create mode 100644 vendor/github.com/redis/go-redis/v9/internal/util/atomic_max.go create mode 100644 vendor/github.com/redis/go-redis/v9/internal/util/atomic_min.go delete mode 100644 vendor/github.com/redis/go-redis/v9/internal/util/math.go create mode 100644 vendor/github.com/redis/go-redis/v9/osscluster_router.go create mode 100644 vendor/github.com/redis/go-redis/v9/otel.go create mode 100644 vendor/go.uber.org/atomic/.codecov.yml create mode 100644 vendor/go.uber.org/atomic/.gitignore create mode 100644 vendor/go.uber.org/atomic/CHANGELOG.md create mode 100644 vendor/go.uber.org/atomic/LICENSE.txt create mode 100644 vendor/go.uber.org/atomic/Makefile create mode 100644 vendor/go.uber.org/atomic/README.md create mode 100644 vendor/go.uber.org/atomic/bool.go create mode 100644 vendor/go.uber.org/atomic/bool_ext.go create mode 100644 vendor/go.uber.org/atomic/doc.go create mode 100644 vendor/go.uber.org/atomic/duration.go create mode 100644 vendor/go.uber.org/atomic/duration_ext.go create mode 100644 vendor/go.uber.org/atomic/error.go create mode 100644 vendor/go.uber.org/atomic/error_ext.go create mode 100644 vendor/go.uber.org/atomic/float32.go create mode 100644 vendor/go.uber.org/atomic/float32_ext.go create mode 100644 vendor/go.uber.org/atomic/float64.go create mode 100644 vendor/go.uber.org/atomic/float64_ext.go create mode 100644 vendor/go.uber.org/atomic/gen.go create mode 100644 vendor/go.uber.org/atomic/int32.go create mode 100644 vendor/go.uber.org/atomic/int64.go create mode 100644 vendor/go.uber.org/atomic/nocmp.go create mode 100644 vendor/go.uber.org/atomic/pointer_go118.go create mode 100644 vendor/go.uber.org/atomic/pointer_go118_pre119.go create mode 100644 vendor/go.uber.org/atomic/pointer_go119.go create mode 100644 vendor/go.uber.org/atomic/string.go create mode 100644 vendor/go.uber.org/atomic/string_ext.go create mode 100644 vendor/go.uber.org/atomic/time.go create mode 100644 vendor/go.uber.org/atomic/time_ext.go create mode 100644 vendor/go.uber.org/atomic/uint32.go create mode 100644 vendor/go.uber.org/atomic/uint64.go create mode 100644 vendor/go.uber.org/atomic/uintptr.go create mode 100644 vendor/go.uber.org/atomic/unsafe_pointer.go create mode 100644 vendor/go.uber.org/atomic/value.go diff --git a/go.mod b/go.mod index 1fe700bf..ff5db3bb 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/BlueMonday/go-scryfall v0.9.1 github.com/SevereCloud/vksdk/v3 v3.2.2 github.com/cockroachdb/errors v1.12.0 - github.com/redis/go-redis/v9 v9.17.3 + github.com/redis/go-redis/v9 v9.18.0 github.com/spf13/cobra v1.10.2 github.com/spf13/viper v1.21.0 github.com/tdewolff/minify/v2 v2.24.8 diff --git a/go.sum b/go.sum index 758e47df..1826a0cc 100644 --- a/go.sum +++ b/go.sum @@ -67,7 +67,6 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= -github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129/go.mod h1:rFgpPQZYZ8vdbc+48xibu8ALc3yeyd64IhHS+PU6Yyg= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= @@ -104,7 +103,6 @@ github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWH github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= -github.com/cockroachdb/datadriven v1.0.2/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU= github.com/cockroachdb/errors v1.12.0 h1:d7oCs6vuIMUQRVbi6jWWWEJZahLCfJpnJSVobd1/sUo= github.com/cockroachdb/errors v1.12.0/go.mod h1:SvzfYNNBshAVbZ8wzNc/UPK3w1vf0dKDUP41ucAIf7g= github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506 h1:ASDL+UJcILMqgNeV5jiqR4j+sTuvQNHdf2chuKj1M5k= @@ -120,7 +118,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= -github.com/djherbis/atime v1.1.0/go.mod h1:28OF6Y8s3NQWwacXc5eZTsEsiMzp7LF8MbXE+XJPdBE= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= @@ -165,11 +162,9 @@ github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9L github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/goccy/go-yaml v1.9.5/go.mod h1:U/jl18uSupI5rdI2jmuCswEA2htH9eXfferR3KfscvA= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/gogo/googleapis v1.4.1/go.mod h1:2lpHqI5OcWCtVElxXnPt+s8oJvMpySlOyM6xDCrzib4= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/gogo/status v1.1.0/go.mod h1:BFv9nrluPLmrS0EmGVvLaPNmRosr9KapBYd5/hpY1WM= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -201,7 +196,6 @@ github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= @@ -253,7 +247,6 @@ github.com/googleapis/gax-go/v2 v2.2.0/go.mod h1:as02EH8zWkzwUoLbBaFeQ+arQaj/Oth github.com/googleapis/gax-go/v2 v2.3.0/go.mod h1:b8LNqSzNabLiUpXKkY7HAR5jr6bIT99EXz9pXxye9YM= github.com/googleapis/gax-go/v2 v2.4.0/go.mod h1:XOTVJ59hdnfJLIP/dh8n5CGryZR2LxK9wbMD5+iXC6c= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= -github.com/gorilla/schema v1.4.1/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM= github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= @@ -286,12 +279,10 @@ github.com/hashicorp/mdns v1.0.4/go.mod h1:mtBihi+LeNXGtG8L9dX59gAEa12BDtBQSp4v/ github.com/hashicorp/memberlist v0.3.0/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= github.com/hashicorp/serf v0.9.6/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4= github.com/hashicorp/serf v0.9.7/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4= -github.com/hydrogen18/memlistener v1.0.0/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= @@ -306,6 +297,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= +github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= @@ -386,8 +379,8 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= -github.com/redis/go-redis/v9 v9.17.3 h1:fN29NdNrE17KttK5Ndf20buqfDZwGNgoUr9qjl1DQx4= -github.com/redis/go-redis/v9 v9.17.3/go.mod h1:u410H11HMLoB+TP67dz8rL9s6QW2j76l0//kSOd3370= +github.com/redis/go-redis/v9 v9.18.0 h1:pMkxYPkEbMPwRdenAzUNyFNrDgHx9U+DrBabWNfSRQs= +github.com/redis/go-redis/v9 v9.18.0/go.mod h1:k3ufPphLU5YXwNTUcCRXGxUoF1fqxnhFQmscfkCoDA0= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= @@ -439,7 +432,6 @@ github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= -github.com/tdewolff/argp v0.0.0-20250430135133-0f54527d2b1e/go.mod h1:xw2b1X81m4zY1OGytzHNr/YKXbf/STHkK5idoNamlYE= github.com/tdewolff/minify/v2 v2.24.8 h1:58/VjsbevI4d5FGV0ZSuBrHMSSkH4MCH0sIz/eKIauE= github.com/tdewolff/minify/v2 v2.24.8/go.mod h1:0Ukj0CRpo/sW/nd8uZ4ccXaV1rEVIWA3dj8U7+Shhfw= github.com/tdewolff/parse/v2 v2.8.5 h1:ZmBiA/8Do5Rpk7bDye0jbbDUpXXbCdc3iah4VeUvwYU= @@ -456,6 +448,8 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0= +github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA= go.etcd.io/etcd/api/v3 v3.5.4/go.mod h1:5GB2vv4A4AOn3yk7MftYGHkUfGtDHnEraIjym4dYz5A= go.etcd.io/etcd/client/pkg/v3 v3.5.4/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= go.etcd.io/etcd/client/v2 v2.305.4/go.mod h1:Ud+VUwIi9/uQHOMA+4ekToJ12lTxlv0zB/+DHwTGEbU= @@ -524,7 +518,6 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.30.0/go.mod h1:lAsf5O2EvJeSFMiBxXDki7sCgAxEUcZHXoXMKT4GJKc= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -572,7 +565,6 @@ golang.org/x/net v0.0.0-20220325170049-de3da57026de/go.mod h1:CfG3xpIq0wQ8r1q4Su golang.org/x/net v0.0.0-20220412020605-290c469a71a5/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -605,7 +597,6 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220513210516-0976fa681c29/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -757,7 +748,6 @@ golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.39.0/go.mod h1:JnefbkDPyD8UU2kI5fuf8ZX4/yUeh9W877ZeBONxUqQ= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -888,7 +878,6 @@ google.golang.org/genproto v0.0.0-20220421151946-72621c1f0bd3/go.mod h1:8w6bsBMX google.golang.org/genproto v0.0.0-20220429170224-98d788798c3e/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo= google.golang.org/genproto v0.0.0-20220505152158-f39f71e6c8f3/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4= google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4= -google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1/go.mod h1:nKE/iIaLqn2bQwXBg8f1g2Ylh6r5MN5CmZvuzZCgsCU= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= @@ -919,7 +908,6 @@ google.golang.org/grpc v1.44.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ5 google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ= google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= google.golang.org/grpc v1.46.2/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= -google.golang.org/grpc v1.56.3/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= @@ -935,7 +923,6 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/vendor/github.com/redis/go-redis/v9/.gitignore b/vendor/github.com/redis/go-redis/v9/.gitignore index 00710d50..93affec7 100644 --- a/vendor/github.com/redis/go-redis/v9/.gitignore +++ b/vendor/github.com/redis/go-redis/v9/.gitignore @@ -10,6 +10,10 @@ coverage.txt .vscode tmp/* *.test - +extra/redisotel-native/metrics-collector-app/ # maintenanceNotifications upgrade documentation (temporary) maintenanceNotifications/docs/ + +# Docker-generated files (TLS certificates, cluster data, etc.) +dockers/*/tls/ +dockers/osscluster-tls/ diff --git a/vendor/github.com/redis/go-redis/v9/.golangci.yml b/vendor/github.com/redis/go-redis/v9/.golangci.yml index 872454ff..dd13c2c2 100644 --- a/vendor/github.com/redis/go-redis/v9/.golangci.yml +++ b/vendor/github.com/redis/go-redis/v9/.golangci.yml @@ -26,6 +26,8 @@ linters: - builtin$ - examples$ formatters: + enable: + - gofmt exclusions: generated: lax paths: diff --git a/vendor/github.com/redis/go-redis/v9/Makefile b/vendor/github.com/redis/go-redis/v9/Makefile index c2264a4e..370f3880 100644 --- a/vendor/github.com/redis/go-redis/v9/Makefile +++ b/vendor/github.com/redis/go-redis/v9/Makefile @@ -1,8 +1,8 @@ GO_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort) -REDIS_VERSION ?= 8.4 +REDIS_VERSION ?= 8.6 RE_CLUSTER ?= false RCE_DOCKER ?= true -CLIENT_LIBS_TEST_IMAGE ?= redislabs/client-libs-test:8.4.0 +CLIENT_LIBS_TEST_IMAGE ?= redislabs/client-libs-test:custom-21860421418-debian-amd64 docker.start: export RE_CLUSTER=$(RE_CLUSTER) && \ @@ -14,6 +14,17 @@ docker.start: docker.stop: docker compose --profile all down +docker.e2e.start: + @echo "Starting Redis and cae-resp-proxy for E2E tests..." + docker compose --profile e2e up -d --quiet-pull + @echo "Waiting for services to be ready..." + @sleep 3 + @echo "Services ready!" + +docker.e2e.stop: + @echo "Stopping E2E services..." + docker compose --profile e2e down + test: $(MAKE) docker.start @if [ -z "$(REDIS_VERSION)" ]; then \ @@ -66,7 +77,31 @@ bench: export REDIS_VERSION=$(REDIS_VERSION) && \ go test ./... -test.run=NONE -test.bench=. -test.benchmem -skip Example -.PHONY: all test test.ci test.ci.skip-vectorsets bench fmt +test.e2e: + @echo "Running E2E tests with auto-start proxy..." + $(MAKE) docker.e2e.start + @echo "Running tests..." + @E2E_SCENARIO_TESTS=true go test -v ./maintnotifications/e2e/ -timeout 30m || ($(MAKE) docker.e2e.stop && exit 1) + $(MAKE) docker.e2e.stop + @echo "E2E tests completed!" + +test.e2e.docker: + @echo "Running Docker-compatible E2E tests..." + $(MAKE) docker.e2e.start + @echo "Running unified injector tests..." + @E2E_SCENARIO_TESTS=true go test -v -run "TestUnifiedInjector|TestCreateTestFaultInjectorLogic|TestFaultInjectorClientCreation" ./maintnotifications/e2e/ -timeout 10m || ($(MAKE) docker.e2e.stop && exit 1) + $(MAKE) docker.e2e.stop + @echo "Docker E2E tests completed!" + +test.e2e.logic: + @echo "Running E2E logic tests (no proxy required)..." + @E2E_SCENARIO_TESTS=true \ + REDIS_ENDPOINTS_CONFIG_PATH=/tmp/test_endpoints_verify.json \ + FAULT_INJECTION_API_URL=http://localhost:8080 \ + go test -v -run "TestCreateTestFaultInjectorLogic|TestFaultInjectorClientCreation" ./maintnotifications/e2e/ + @echo "Logic tests completed!" + +.PHONY: all test test.ci test.ci.skip-vectorsets bench fmt test.e2e test.e2e.logic docker.e2e.start docker.e2e.stop build: export RE_CLUSTER=$(RE_CLUSTER) && \ diff --git a/vendor/github.com/redis/go-redis/v9/README.md b/vendor/github.com/redis/go-redis/v9/README.md index 38bd17b5..160714ab 100644 --- a/vendor/github.com/redis/go-redis/v9/README.md +++ b/vendor/github.com/redis/go-redis/v9/README.md @@ -21,13 +21,12 @@ In `go-redis` we are aiming to support the last three releases of Redis. Current - [Redis 8.2](https://raw.githubusercontent.com/redis/redis/8.2/00-RELEASENOTES) - using Redis CE 8.2 - [Redis 8.4](https://raw.githubusercontent.com/redis/redis/8.4/00-RELEASENOTES) - using Redis CE 8.4 -Although the `go.mod` states it requires at minimum `go 1.18`, our CI is configured to run the tests against all three -versions of Redis and latest two versions of Go ([1.23](https://go.dev/doc/devel/release#go1.23.0), -[1.24](https://go.dev/doc/devel/release#go1.24.0)). We observe that some modules related test may not pass with +Although the `go.mod` states it requires at minimum `go 1.21`, our CI is configured to run the tests against all three +versions of Redis and multiple versions of Go ([1.21](https://go.dev/doc/devel/release#go1.21.0), +[1.23](https://go.dev/doc/devel/release#go1.23.0), oldstable, and stable). We observe that some modules related test may not pass with Redis Stack 7.2 and some commands are changed with Redis CE 8.0. Although it is not officially supported, `go-redis/v9` should be able to work with any Redis 7.0+. -Please do refer to the documentation and the tests if you experience any issues. We do plan to update the go version -in the `go.mod` to `go 1.24` in one of the next releases. +Please do refer to the documentation and the tests if you experience any issues. ## How do I Redis? @@ -111,6 +110,7 @@ func ExampleClient() { Password: "", // no password set DB: 0, // use default DB }) + defer rdb.Close() err := rdb.Set(ctx, "key", "value", 0).Err() if err != nil { diff --git a/vendor/github.com/redis/go-redis/v9/RELEASE-NOTES.md b/vendor/github.com/redis/go-redis/v9/RELEASE-NOTES.md index c7dea398..7b705ee6 100644 --- a/vendor/github.com/redis/go-redis/v9/RELEASE-NOTES.md +++ b/vendor/github.com/redis/go-redis/v9/RELEASE-NOTES.md @@ -1,42 +1,178 @@ # Release Notes -# 9.17.3 (2026-01-25) +# 9.18.0 (2026-02-16) + +## ๐Ÿš€ Highlights + +### Redis 8.6 Support + +Added support for Redis 8.6, including new commands and features for streams idempotent production and HOTKEYS. + +### Smart Client Handoff (Maintenance Notifications) for Cluster + +This release introduces comprehensive support for Redis Cluster maintenance notifications via SMIGRATING/SMIGRATED push notifications. The client now automatically handles slot migrations by: +- **Relaxing timeouts during migration** (SMIGRATING) to prevent false failures +- **Triggering lazy cluster state reloads** upon completion (SMIGRATED) +- Enabling seamless operations during Redis Enterprise maintenance windows + +([#3643](https://github.com/redis/go-redis/pull/3643)) by [@ndyakov](https://github.com/ndyakov) + +### OpenTelemetry Native Metrics Support + +Added comprehensive OpenTelemetry metrics support following the [OpenTelemetry Database Client Semantic Conventions](https://opentelemetry.io/docs/specs/semconv/database/database-metrics/). The implementation uses a Bridge Pattern to keep the core library dependency-free while providing optional metrics instrumentation through the new `extra/redisotel-native` package. + +**Metric groups include:** +- Command metrics: Operation duration with retry tracking +- Connection basic: Connection count and creation time +- Resiliency: Errors, handoffs, timeout relaxation +- Connection advanced: Wait time and use time +- Pubsub metrics: Published and received messages +- Stream metrics: Processing duration and maintenance notifications + +([#3637](https://github.com/redis/go-redis/pull/3637)) by [@ofekshenawa](https://github.com/ofekshenawa) + +## โœจ New Features + +- **HOTKEYS Commands**: Added support for Redis HOTKEYS feature for identifying hot keys based on CPU consumption and network utilization ([#3695](https://github.com/redis/go-redis/pull/3695)) by [@ofekshenawa](https://github.com/ofekshenawa) +- **Streams Idempotent Production**: Added support for Redis 8.6+ Streams Idempotent Production with `ProducerID`, `IdempotentID`, `IdempotentAuto` in `XAddArgs` and new `XCFGSET` command ([#3693](https://github.com/redis/go-redis/pull/3693)) by [@ofekshenawa](https://github.com/ofekshenawa) +- **NaN Values for TimeSeries**: Added support for NaN (Not a Number) values in Redis time series commands ([#3687](https://github.com/redis/go-redis/pull/3687)) by [@ofekshenawa](https://github.com/ofekshenawa) +- **DialerRetries Options**: Added `DialerRetries` and `DialerRetryTimeout` to `ClusterOptions`, `RingOptions`, and `FailoverOptions` ([#3686](https://github.com/redis/go-redis/pull/3686)) by [@naveenchander30](https://github.com/naveenchander30) +- **ConnMaxLifetimeJitter**: Added jitter configuration to distribute connection expiration times and prevent thundering herd ([#3666](https://github.com/redis/go-redis/pull/3666)) by [@cyningsun](https://github.com/cyningsun) +- **Digest Helper Functions**: Added `DigestString` and `DigestBytes` helper functions for client-side xxh3 hashing compatible with Redis DIGEST command ([#3679](https://github.com/redis/go-redis/pull/3679)) by [@ofekshenawa](https://github.com/ofekshenawa) +- **SMIGRATED New Format**: Updated SMIGRATED parser to support new format and remember original host:port ([#3697](https://github.com/redis/go-redis/pull/3697)) by [@ndyakov](https://github.com/ndyakov) +- **Cluster State Reload Interval**: Added cluster state reload interval option for maintenance notifications ([#3663](https://github.com/redis/go-redis/pull/3663)) by [@ndyakov](https://github.com/ndyakov) ## ๐Ÿ› Bug Fixes -- **Connection Pool**: Fixed zombie `wantConn` elements accumulation in `wantConnQueue` that could cause resource leaks in high concurrency scenarios with dial failures ([#3680](https://github.com/redis/go-redis/pull/3680)) by [@cyningsun](https://github.com/cyningsun) -- **Stream Commands**: Fixed `XADD` and `XTRIM` commands to use exact threshold (`=`) when `Approx` is false, ensuring precise stream trimming behavior ([#3684](https://github.com/redis/go-redis/pull/3684)) by [@ndyakov](https://github.com/ndyakov) -- **Connection Pool**: Added `ConnMaxLifetimeJitter` configuration to distribute connection expiration times and prevent the thundering herd problem when many connections expire simultaneously ([#3666](https://github.com/redis/go-redis/pull/3666)) by [@cyningsun](https://github.com/cyningsun) -- **Client Options**: Added `DialerRetries` and `DialerRetryTimeout` fields to `ClusterOptions`, `RingOptions`, and `FailoverOptions` to allow configuring connection retry behavior for cluster, ring, and sentinel clients ([#3686](https://github.com/redis/go-redis/pull/3686)) by [@naveenchander30](https://github.com/naveenchander30) +- **PubSub nil pointer dereference**: Fixed nil pointer dereference in PubSub after `WithTimeout()` - `pubSubPool` is now properly cloned ([#3710](https://github.com/redis/go-redis/pull/3710)) by [@Copilot](https://github.com/apps/copilot-swe-agent) +- **MaintNotificationsConfig nil check**: Guard against nil `MaintNotificationsConfig` in `initConn` ([#3707](https://github.com/redis/go-redis/pull/3707)) by [@veeceey](https://github.com/veeceey) +- **wantConnQueue zombie elements**: Fixed zombie `wantConn` elements accumulation in `wantConnQueue` ([#3680](https://github.com/redis/go-redis/pull/3680)) by [@cyningsun](https://github.com/cyningsun) +- **XADD/XTRIM approx flag**: Fixed XADD and XTRIM to use `=` when approx is false ([#3684](https://github.com/redis/go-redis/pull/3684)) by [@ndyakov](https://github.com/ndyakov) +- **Sentinel timeout retry**: When connection to a sentinel times out, attempt to connect to other sentinels ([#3654](https://github.com/redis/go-redis/pull/3654)) by [@cxljs](https://github.com/cxljs) + +## โšก Performance + +- **Fuzz test optimization**: Eliminated repeated string conversions, used functional approach for cleaner operation selection ([#3692](https://github.com/redis/go-redis/pull/3692)) by [@feiguoL](https://github.com/feiguoL) +- **Pre-allocate capacity**: Pre-allocate slice capacity to prevent multiple capacity expansions ([#3689](https://github.com/redis/go-redis/pull/3689)) by [@feelshu](https://github.com/feelshu) + +## ๐Ÿงช Testing + +- **Comprehensive TLS tests**: Added comprehensive TLS tests and example for standalone, cluster, and certificate authentication ([#3681](https://github.com/redis/go-redis/pull/3681)) by [@ndyakov](https://github.com/ndyakov) +- **Redis 8.6**: Updated CI to use Redis 8.6-pre ([#3685](https://github.com/redis/go-redis/pull/3685)) by [@ndyakov](https://github.com/ndyakov) + +## ๐Ÿงฐ Maintenance + +- **Deprecation warnings**: Added deprecation warnings for commands based on Redis documentation ([#3673](https://github.com/redis/go-redis/pull/3673)) by [@ndyakov](https://github.com/ndyakov) +- **Use errors.Join()**: Replaced custom error join function with standard library `errors.Join()` ([#3653](https://github.com/redis/go-redis/pull/3653)) by [@cxljs](https://github.com/cxljs) +- **Use Go 1.21 min/max**: Use Go 1.21's built-in min/max functions ([#3656](https://github.com/redis/go-redis/pull/3656)) by [@cxljs](https://github.com/cxljs) +- **Proper formatting**: Code formatting improvements ([#3670](https://github.com/redis/go-redis/pull/3670)) by [@12ya](https://github.com/12ya) +- **Set commands documentation**: Added comprehensive documentation to all set command methods ([#3642](https://github.com/redis/go-redis/pull/3642)) by [@iamamirsalehi](https://github.com/iamamirsalehi) +- **MaxActiveConns docs**: Added default value documentation for `MaxActiveConns` ([#3674](https://github.com/redis/go-redis/pull/3674)) by [@codykaup](https://github.com/codykaup) +- **README example update**: Updated README example ([#3657](https://github.com/redis/go-redis/pull/3657)) by [@cxljs](https://github.com/cxljs) +- **Cluster maintnotif example**: Added example application for cluster maintenance notifications ([#3651](https://github.com/redis/go-redis/pull/3651)) by [@ndyakov](https://github.com/ndyakov) + +## ๐Ÿ‘ฅ Contributors -## Contributors We'd like to thank all the contributors who worked on this release! -[@cyningsun](https://github.com/cyningsun), [@naveenchander30](https://github.com/naveenchander30), and [@ndyakov](https://github.com/ndyakov) +[@12ya](https://github.com/12ya), [@Copilot](https://github.com/apps/copilot-swe-agent), [@codykaup](https://github.com/codykaup), [@cxljs](https://github.com/cxljs), [@cyningsun](https://github.com/cyningsun), [@feelshu](https://github.com/feelshu), [@feiguoL](https://github.com/feiguoL), [@iamamirsalehi](https://github.com/iamamirsalehi), [@naveenchander30](https://github.com/naveenchander30), [@ndyakov](https://github.com/ndyakov), [@ofekshenawa](https://github.com/ofekshenawa), [@veeceey](https://github.com/veeceey) --- -**Full Changelog**: https://github.com/redis/go-redis/compare/v9.17.2...v9.17.3 +**Full Changelog**: https://github.com/redis/go-redis/compare/v9.17.0...v9.18.0 + +# 9.18.0-beta.2 (2025-12-09) + +## ๐Ÿš€ Highlights + +### Go Version Update + +This release updates the minimum required Go version to 1.21. This is part of a gradual migration strategy where the minimum supported Go version will be three versions behind the latest release. With each new Go version release, we will bump the minimum version by one, ensuring compatibility while staying current with the Go ecosystem. -# 9.17.2 (2025-12-01) +### Stability Improvements + +This release includes several important stability fixes: +- Fixed a critical panic in the handoff worker manager that could occur when handling nil errors +- Improved test reliability for Smart Client Handoff functionality +- Fixed logging format issues that could cause runtime errors + +## โœจ New Features + +- OpenTelemetry metrics improvements for nil response handling ([#3638](https://github.com/redis/go-redis/pull/3638)) by [@fengve](https://github.com/fengve) + +## ๐Ÿ› Bug Fixes + +- Fixed panic on nil error in handoffWorkerManager closeConnFromRequest ([#3633](https://github.com/redis/go-redis/pull/3633)) by [@ccoVeille](https://github.com/ccoVeille) +- Fixed bad sprintf syntax in logging ([#3632](https://github.com/redis/go-redis/pull/3632)) by [@ccoVeille](https://github.com/ccoVeille) + +## ๐Ÿงฐ Maintenance + +- Updated minimum Go version to 1.21 ([#3640](https://github.com/redis/go-redis/pull/3640)) by [@ndyakov](https://github.com/ndyakov) +- Use Go 1.20 idiomatic string<->byte conversion ([#3435](https://github.com/redis/go-redis/pull/3435)) by [@justinhwang](https://github.com/justinhwang) +- Reduce flakiness of Smart Client Handoff test ([#3641](https://github.com/redis/go-redis/pull/3641)) by [@kiryazovi-redis](https://github.com/kiryazovi-redis) +- Revert PR #3634 (Observability metrics phase1) ([#3635](https://github.com/redis/go-redis/pull/3635)) by [@ofekshenawa](https://github.com/ofekshenawa) + +## ๐Ÿ‘ฅ Contributors + +We'd like to thank all the contributors who worked on this release! + +[@justinhwang](https://github.com/justinhwang), [@ndyakov](https://github.com/ndyakov), [@kiryazovi-redis](https://github.com/kiryazovi-redis), [@fengve](https://github.com/fengve), [@ccoVeille](https://github.com/ccoVeille), [@ofekshenawa](https://github.com/ofekshenawa) + +--- + +**Full Changelog**: https://github.com/redis/go-redis/compare/v9.18.0-beta.1...v9.18.0-beta.2 + +# 9.18.0-beta.1 (2025-12-01) + +## ๐Ÿš€ Highlights + +### Request and Response Policy Based Routing in Cluster Mode + +This beta release introduces comprehensive support for Redis COMMAND-based request and response policy routing for cluster clients. This feature enables intelligent command routing and response aggregation based on Redis command metadata. + +**Key Features:** +- **Command Policy Loader**: Automatically parses and caches COMMAND metadata with routing/aggregation hints +- **Enhanced Routing Engine**: Supports all request policies including: + - `default(keyless)` - Commands without keys + - `default(hashslot)` - Commands with hash slot routing + - `all_shards` - Commands that need to run on all shards + - `all_nodes` - Commands that need to run on all nodes + - `multi_shard` - Commands that span multiple shards + - `special` - Commands with custom routing logic +- **Response Aggregator**: Intelligently combines multi-shard replies based on response policies: + - `all_succeeded` - All shards must succeed + - `one_succeeded` - At least one shard must succeed + - `agg_sum` - Aggregate numeric responses + - `special` - Custom aggregation logic (e.g., FT.CURSOR) +- **Raw Command Support**: Policies are enforced on `Client.Do(ctx, args...)` + +This feature is particularly useful for Redis Stack commands like RediSearch that need to operate across multiple shards in a cluster. + +### Connection Pool Improvements + +Fixed a critical defect in the connection pool's turn management mechanism that could lead to connection leaks under certain conditions. The fix ensures proper 1:1 correspondence between turns and connections. + +## โœจ New Features + +- Request and Response Policy Based Routing in Cluster Mode ([#3422](https://github.com/redis/go-redis/pull/3422)) by [@ofekshenawa](https://github.com/ofekshenawa) ## ๐Ÿ› Bug Fixes -- **Connection Pool**: Fixed critical race condition in turn management that could cause connection leaks when dial goroutines complete after request timeout ([#3626](https://github.com/redis/go-redis/pull/3626)) by [@cyningsun](https://github.com/cyningsun) -- **Context Timeout**: Improved context timeout calculation to use minimum of remaining time and DialTimeout, preventing goroutines from waiting longer than necessary ([#3626](https://github.com/redis/go-redis/pull/3626)) by [@cyningsun](https://github.com/cyningsun) +- Fixed connection pool turn management to prevent connection leaks ([#3626](https://github.com/redis/go-redis/pull/3626)) by [@cyningsun](https://github.com/cyningsun) ## ๐Ÿงฐ Maintenance - chore(deps): bump rojopolis/spellcheck-github-actions from 0.54.0 to 0.55.0 ([#3627](https://github.com/redis/go-redis/pull/3627)) -## Contributors +## ๐Ÿ‘ฅ Contributors + We'd like to thank all the contributors who worked on this release! -[@cyningsun](https://github.com/cyningsun) and [@ndyakov](https://github.com/ndyakov) +[@cyningsun](https://github.com/cyningsun), [@ofekshenawa](https://github.com/ofekshenawa), [@ndyakov](https://github.com/ndyakov) --- -**Full Changelog**: https://github.com/redis/go-redis/compare/v9.17.1...v9.17.2 +**Full Changelog**: https://github.com/redis/go-redis/compare/v9.17.1...v9.18.0-beta.1 # 9.17.1 (2025-11-25) diff --git a/vendor/github.com/redis/go-redis/v9/adapters.go b/vendor/github.com/redis/go-redis/v9/adapters.go index 4146153b..952a4c26 100644 --- a/vendor/github.com/redis/go-redis/v9/adapters.go +++ b/vendor/github.com/redis/go-redis/v9/adapters.go @@ -61,6 +61,13 @@ func (oa *optionsAdapter) GetAddr() string { return oa.options.Addr } +// GetNodeAddress returns the address of the Redis node as reported by the server. +// For cluster clients, this is the endpoint from CLUSTER SLOTS before any transformation. +// For standalone clients, this defaults to Addr. +func (oa *optionsAdapter) GetNodeAddress() string { + return oa.options.NodeAddress +} + // IsTLSEnabled returns true if TLS is enabled. func (oa *optionsAdapter) IsTLSEnabled() bool { return oa.options.TLSConfig != nil diff --git a/vendor/github.com/redis/go-redis/v9/auth/reauth_credentials_listener.go b/vendor/github.com/redis/go-redis/v9/auth/reauth_credentials_listener.go index f4b31983..40076a0b 100644 --- a/vendor/github.com/redis/go-redis/v9/auth/reauth_credentials_listener.go +++ b/vendor/github.com/redis/go-redis/v9/auth/reauth_credentials_listener.go @@ -44,4 +44,4 @@ func NewReAuthCredentialsListener(reAuth func(credentials Credentials) error, on } // Ensure ReAuthCredentialsListener implements the CredentialsListener interface. -var _ CredentialsListener = (*ReAuthCredentialsListener)(nil) \ No newline at end of file +var _ CredentialsListener = (*ReAuthCredentialsListener)(nil) diff --git a/vendor/github.com/redis/go-redis/v9/cluster_commands.go b/vendor/github.com/redis/go-redis/v9/cluster_commands.go index 4857b01e..a02683f2 100644 --- a/vendor/github.com/redis/go-redis/v9/cluster_commands.go +++ b/vendor/github.com/redis/go-redis/v9/cluster_commands.go @@ -42,6 +42,9 @@ func (c cmdable) ClusterMyID(ctx context.Context) *StringCmd { return cmd } +// ClusterSlots returns the mapping of cluster slots to nodes. +// +// Deprecated: Use ClusterShards instead as of Redis 7.0.0. func (c cmdable) ClusterSlots(ctx context.Context) *ClusterSlotsCmd { cmd := NewClusterSlotsCmd(ctx, "cluster", "slots") _ = c(ctx, cmd) @@ -153,6 +156,9 @@ func (c cmdable) ClusterSaveConfig(ctx context.Context) *StatusCmd { return cmd } +// ClusterSlaves lists the replica nodes of a master node. +// +// Deprecated: Use ClusterReplicas instead as of Redis 5.0.0. func (c cmdable) ClusterSlaves(ctx context.Context, nodeID string) *StringSliceCmd { cmd := NewStringSliceCmd(ctx, "cluster", "slaves", nodeID) _ = c(ctx, cmd) diff --git a/vendor/github.com/redis/go-redis/v9/command.go b/vendor/github.com/redis/go-redis/v9/command.go index 2dbc2ad8..a2a2f051 100644 --- a/vendor/github.com/redis/go-redis/v9/command.go +++ b/vendor/github.com/redis/go-redis/v9/command.go @@ -4,6 +4,7 @@ import ( "bufio" "context" "fmt" + "maps" "net" "regexp" "strconv" @@ -14,6 +15,7 @@ import ( "github.com/redis/go-redis/v9/internal" "github.com/redis/go-redis/v9/internal/hscan" "github.com/redis/go-redis/v9/internal/proto" + "github.com/redis/go-redis/v9/internal/routing" "github.com/redis/go-redis/v9/internal/util" ) @@ -35,6 +37,7 @@ var keylessCommands = map[string]struct{}{ "failover": {}, "function": {}, "hello": {}, + "hotkeys": {}, "latency": {}, "lolwut": {}, "module": {}, @@ -67,6 +70,118 @@ var keylessCommands = map[string]struct{}{ "wait": {}, } +// CmdTyper interface for getting command type +type CmdTyper interface { + GetCmdType() CmdType +} + +// CmdTypeGetter interface for getting command type without circular imports +type CmdTypeGetter interface { + GetCmdType() CmdType +} + +type CmdType uint8 + +const ( + CmdTypeGeneric CmdType = iota + CmdTypeString + CmdTypeInt + CmdTypeBool + CmdTypeFloat + CmdTypeStringSlice + CmdTypeIntSlice + CmdTypeFloatSlice + CmdTypeBoolSlice + CmdTypeMapStringString + CmdTypeMapStringInt + CmdTypeMapStringInterface + CmdTypeMapStringInterfaceSlice + CmdTypeSlice + CmdTypeStatus + CmdTypeDuration + CmdTypeTime + CmdTypeKeyValueSlice + CmdTypeStringStructMap + CmdTypeXMessageSlice + CmdTypeXStreamSlice + CmdTypeXPending + CmdTypeXPendingExt + CmdTypeXAutoClaim + CmdTypeXAutoClaimJustID + CmdTypeXInfoConsumers + CmdTypeXInfoGroups + CmdTypeXInfoStream + CmdTypeXInfoStreamFull + CmdTypeZSlice + CmdTypeZWithKey + CmdTypeScan + CmdTypeClusterSlots + CmdTypeGeoLocation + CmdTypeGeoSearchLocation + CmdTypeGeoPos + CmdTypeCommandsInfo + CmdTypeSlowLog + CmdTypeMapStringStringSlice + CmdTypeMapMapStringInterface + CmdTypeKeyValues + CmdTypeZSliceWithKey + CmdTypeFunctionList + CmdTypeFunctionStats + CmdTypeLCS + CmdTypeKeyFlags + CmdTypeClusterLinks + CmdTypeClusterShards + CmdTypeRankWithScore + CmdTypeClientInfo + CmdTypeACLLog + CmdTypeInfo + CmdTypeMonitor + CmdTypeJSON + CmdTypeJSONSlice + CmdTypeIntPointerSlice + CmdTypeScanDump + CmdTypeBFInfo + CmdTypeCFInfo + CmdTypeCMSInfo + CmdTypeTopKInfo + CmdTypeTDigestInfo + CmdTypeFTSynDump + CmdTypeAggregate + CmdTypeFTInfo + CmdTypeFTSpellCheck + CmdTypeFTSearch + CmdTypeTSTimestampValue + CmdTypeTSTimestampValueSlice + CmdTypeHotKeys +) + +type ( + CmdTypeXAutoClaimValue struct { + messages []XMessage + start string + } + + CmdTypeXAutoClaimJustIDValue struct { + ids []string + start string + } + + CmdTypeScanValue struct { + keys []string + cursor uint64 + } + + CmdTypeKeyValuesValue struct { + key string + values []string + } + + CmdTypeZSliceWithKeyValue struct { + key string + zSlice []Z + } +) + type Cmder interface { // command name. // e.g. "set k v ex 10" -> "set", "cluster info" -> "cluster". @@ -84,15 +199,23 @@ type Cmder interface { // e.g. "set k v ex 10" -> "set k v ex 10: OK", "get k" -> "get k: v". String() string + // Clone creates a copy of the command. + Clone() Cmder + stringArg(int) string firstKeyPos() int8 SetFirstKeyPos(int8) + stepCount() int8 + SetStepCount(int8) readTimeout() *time.Duration readReply(rd *proto.Reader) error readRawReply(rd *proto.Reader) error SetErr(error) Err() error + + // GetCmdType returns the command type for fast value extraction + GetCmdType() CmdType } func setCmdsErr(cmds []Cmder, e error) { @@ -186,8 +309,10 @@ type baseCmd struct { args []interface{} err error keyPos int8 + _stepCount int8 rawVal interface{} _readTimeout *time.Duration + cmdType CmdType } var _ Cmder = (*Cmd)(nil) @@ -243,6 +368,14 @@ func (cmd *baseCmd) SetFirstKeyPos(keyPos int8) { cmd.keyPos = keyPos } +func (cmd *baseCmd) stepCount() int8 { + return cmd._stepCount +} + +func (cmd *baseCmd) SetStepCount(stepCount int8) { + cmd._stepCount = stepCount +} + func (cmd *baseCmd) SetErr(e error) { cmd.err = e } @@ -264,6 +397,33 @@ func (cmd *baseCmd) readRawReply(rd *proto.Reader) (err error) { return err } +func (cmd *baseCmd) GetCmdType() CmdType { + return cmd.cmdType +} + +func (cmd *baseCmd) cloneBaseCmd() baseCmd { + var readTimeout *time.Duration + if cmd._readTimeout != nil { + timeout := *cmd._readTimeout + readTimeout = &timeout + } + + // Create a copy of args slice + args := make([]interface{}, len(cmd.args)) + copy(args, cmd.args) + + return baseCmd{ + ctx: cmd.ctx, + args: args, + err: cmd.err, + keyPos: cmd.keyPos, + _stepCount: cmd._stepCount, + rawVal: cmd.rawVal, + _readTimeout: readTimeout, + cmdType: cmd.cmdType, + } +} + //------------------------------------------------------------------------------ type Cmd struct { @@ -275,8 +435,9 @@ type Cmd struct { func NewCmd(ctx context.Context, args ...interface{}) *Cmd { return &Cmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeGeneric, }, } } @@ -549,6 +710,13 @@ func (cmd *Cmd) readReply(rd *proto.Reader) (err error) { return err } +func (cmd *Cmd) Clone() Cmder { + return &Cmd{ + baseCmd: cmd.cloneBaseCmd(), + val: cmd.val, + } +} + //------------------------------------------------------------------------------ type SliceCmd struct { @@ -562,8 +730,9 @@ var _ Cmder = (*SliceCmd)(nil) func NewSliceCmd(ctx context.Context, args ...interface{}) *SliceCmd { return &SliceCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeSlice, }, } } @@ -609,6 +778,18 @@ func (cmd *SliceCmd) readReply(rd *proto.Reader) (err error) { return err } +func (cmd *SliceCmd) Clone() Cmder { + var val []interface{} + if cmd.val != nil { + val = make([]interface{}, len(cmd.val)) + copy(val, cmd.val) + } + return &SliceCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ type StatusCmd struct { @@ -622,8 +803,9 @@ var _ Cmder = (*StatusCmd)(nil) func NewStatusCmd(ctx context.Context, args ...interface{}) *StatusCmd { return &StatusCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeStatus, }, } } @@ -653,6 +835,13 @@ func (cmd *StatusCmd) readReply(rd *proto.Reader) (err error) { return err } +func (cmd *StatusCmd) Clone() Cmder { + return &StatusCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: cmd.val, + } +} + //------------------------------------------------------------------------------ type IntCmd struct { @@ -666,8 +855,9 @@ var _ Cmder = (*IntCmd)(nil) func NewIntCmd(ctx context.Context, args ...interface{}) *IntCmd { return &IntCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeInt, }, } } @@ -697,6 +887,13 @@ func (cmd *IntCmd) readReply(rd *proto.Reader) (err error) { return err } +func (cmd *IntCmd) Clone() Cmder { + return &IntCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: cmd.val, + } +} + //------------------------------------------------------------------------------ // DigestCmd is a command that returns a uint64 xxh3 hash digest. @@ -745,6 +942,13 @@ func (cmd *DigestCmd) String() string { return cmdString(cmd, cmd.val) } +func (cmd *DigestCmd) Clone() Cmder { + return &DigestCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: cmd.val, + } +} + func (cmd *DigestCmd) readReply(rd *proto.Reader) (err error) { // Redis DIGEST command returns a hex string (e.g., "a1b2c3d4e5f67890") // We parse it as a uint64 xxh3 hash value @@ -772,8 +976,9 @@ var _ Cmder = (*IntSliceCmd)(nil) func NewIntSliceCmd(ctx context.Context, args ...interface{}) *IntSliceCmd { return &IntSliceCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeIntSlice, }, } } @@ -808,6 +1013,18 @@ func (cmd *IntSliceCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *IntSliceCmd) Clone() Cmder { + var val []int64 + if cmd.val != nil { + val = make([]int64, len(cmd.val)) + copy(val, cmd.val) + } + return &IntSliceCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ type DurationCmd struct { @@ -822,8 +1039,9 @@ var _ Cmder = (*DurationCmd)(nil) func NewDurationCmd(ctx context.Context, precision time.Duration, args ...interface{}) *DurationCmd { return &DurationCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeDuration, }, precision: precision, } @@ -861,6 +1079,14 @@ func (cmd *DurationCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *DurationCmd) Clone() Cmder { + return &DurationCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: cmd.val, + precision: cmd.precision, + } +} + //------------------------------------------------------------------------------ type TimeCmd struct { @@ -874,8 +1100,9 @@ var _ Cmder = (*TimeCmd)(nil) func NewTimeCmd(ctx context.Context, args ...interface{}) *TimeCmd { return &TimeCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeTime, }, } } @@ -912,6 +1139,13 @@ func (cmd *TimeCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *TimeCmd) Clone() Cmder { + return &TimeCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: cmd.val, + } +} + //------------------------------------------------------------------------------ type BoolCmd struct { @@ -925,8 +1159,9 @@ var _ Cmder = (*BoolCmd)(nil) func NewBoolCmd(ctx context.Context, args ...interface{}) *BoolCmd { return &BoolCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeBool, }, } } @@ -959,6 +1194,13 @@ func (cmd *BoolCmd) readReply(rd *proto.Reader) (err error) { return err } +func (cmd *BoolCmd) Clone() Cmder { + return &BoolCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: cmd.val, + } +} + //------------------------------------------------------------------------------ type StringCmd struct { @@ -972,8 +1214,9 @@ var _ Cmder = (*StringCmd)(nil) func NewStringCmd(ctx context.Context, args ...interface{}) *StringCmd { return &StringCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeString, }, } } @@ -1005,28 +1248,28 @@ func (cmd *StringCmd) Int() (int, error) { if cmd.err != nil { return 0, cmd.err } - return strconv.Atoi(cmd.Val()) + return strconv.Atoi(cmd.val) } func (cmd *StringCmd) Int64() (int64, error) { if cmd.err != nil { return 0, cmd.err } - return strconv.ParseInt(cmd.Val(), 10, 64) + return strconv.ParseInt(cmd.val, 10, 64) } func (cmd *StringCmd) Uint64() (uint64, error) { if cmd.err != nil { return 0, cmd.err } - return strconv.ParseUint(cmd.Val(), 10, 64) + return strconv.ParseUint(cmd.val, 10, 64) } func (cmd *StringCmd) Float32() (float32, error) { if cmd.err != nil { return 0, cmd.err } - f, err := strconv.ParseFloat(cmd.Val(), 32) + f, err := strconv.ParseFloat(cmd.val, 32) if err != nil { return 0, err } @@ -1037,14 +1280,14 @@ func (cmd *StringCmd) Float64() (float64, error) { if cmd.err != nil { return 0, cmd.err } - return strconv.ParseFloat(cmd.Val(), 64) + return strconv.ParseFloat(cmd.val, 64) } func (cmd *StringCmd) Time() (time.Time, error) { if cmd.err != nil { return time.Time{}, cmd.err } - return time.Parse(time.RFC3339Nano, cmd.Val()) + return time.Parse(time.RFC3339Nano, cmd.val) } func (cmd *StringCmd) Scan(val interface{}) error { @@ -1063,6 +1306,13 @@ func (cmd *StringCmd) readReply(rd *proto.Reader) (err error) { return err } +func (cmd *StringCmd) Clone() Cmder { + return &StringCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: cmd.val, + } +} + //------------------------------------------------------------------------------ type FloatCmd struct { @@ -1076,8 +1326,9 @@ var _ Cmder = (*FloatCmd)(nil) func NewFloatCmd(ctx context.Context, args ...interface{}) *FloatCmd { return &FloatCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeFloat, }, } } @@ -1103,6 +1354,13 @@ func (cmd *FloatCmd) readReply(rd *proto.Reader) (err error) { return err } +func (cmd *FloatCmd) Clone() Cmder { + return &FloatCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: cmd.val, + } +} + //------------------------------------------------------------------------------ type FloatSliceCmd struct { @@ -1116,8 +1374,9 @@ var _ Cmder = (*FloatSliceCmd)(nil) func NewFloatSliceCmd(ctx context.Context, args ...interface{}) *FloatSliceCmd { return &FloatSliceCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeFloatSlice, }, } } @@ -1158,6 +1417,18 @@ func (cmd *FloatSliceCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *FloatSliceCmd) Clone() Cmder { + var val []float64 + if cmd.val != nil { + val = make([]float64, len(cmd.val)) + copy(val, cmd.val) + } + return &FloatSliceCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ type StringSliceCmd struct { @@ -1171,8 +1442,9 @@ var _ Cmder = (*StringSliceCmd)(nil) func NewStringSliceCmd(ctx context.Context, args ...interface{}) *StringSliceCmd { return &StringSliceCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeStringSlice, }, } } @@ -1194,7 +1466,7 @@ func (cmd *StringSliceCmd) String() string { } func (cmd *StringSliceCmd) ScanSlice(container interface{}) error { - return proto.ScanSlice(cmd.Val(), container) + return proto.ScanSlice(cmd.val, container) } func (cmd *StringSliceCmd) readReply(rd *proto.Reader) error { @@ -1216,6 +1488,18 @@ func (cmd *StringSliceCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *StringSliceCmd) Clone() Cmder { + var val []string + if cmd.val != nil { + val = make([]string, len(cmd.val)) + copy(val, cmd.val) + } + return &StringSliceCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ type KeyValue struct { @@ -1234,8 +1518,9 @@ var _ Cmder = (*KeyValueSliceCmd)(nil) func NewKeyValueSliceCmd(ctx context.Context, args ...interface{}) *KeyValueSliceCmd { return &KeyValueSliceCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeKeyValueSlice, }, } } @@ -1310,6 +1595,18 @@ func (cmd *KeyValueSliceCmd) readReply(rd *proto.Reader) error { // nolint:dupl return nil } +func (cmd *KeyValueSliceCmd) Clone() Cmder { + var val []KeyValue + if cmd.val != nil { + val = make([]KeyValue, len(cmd.val)) + copy(val, cmd.val) + } + return &KeyValueSliceCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ type BoolSliceCmd struct { @@ -1323,8 +1620,9 @@ var _ Cmder = (*BoolSliceCmd)(nil) func NewBoolSliceCmd(ctx context.Context, args ...interface{}) *BoolSliceCmd { return &BoolSliceCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeBoolSlice, }, } } @@ -1359,6 +1657,18 @@ func (cmd *BoolSliceCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *BoolSliceCmd) Clone() Cmder { + var val []bool + if cmd.val != nil { + val = make([]bool, len(cmd.val)) + copy(val, cmd.val) + } + return &BoolSliceCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ type MapStringStringCmd struct { @@ -1372,8 +1682,9 @@ var _ Cmder = (*MapStringStringCmd)(nil) func NewMapStringStringCmd(ctx context.Context, args ...interface{}) *MapStringStringCmd { return &MapStringStringCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeMapStringString, }, } } @@ -1438,6 +1749,20 @@ func (cmd *MapStringStringCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *MapStringStringCmd) Clone() Cmder { + var val map[string]string + if cmd.val != nil { + val = make(map[string]string, len(cmd.val)) + for k, v := range cmd.val { + val[k] = v + } + } + return &MapStringStringCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ type MapStringIntCmd struct { @@ -1451,8 +1776,9 @@ var _ Cmder = (*MapStringIntCmd)(nil) func NewMapStringIntCmd(ctx context.Context, args ...interface{}) *MapStringIntCmd { return &MapStringIntCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeMapStringInt, }, } } @@ -1495,6 +1821,20 @@ func (cmd *MapStringIntCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *MapStringIntCmd) Clone() Cmder { + var val map[string]int64 + if cmd.val != nil { + val = make(map[string]int64, len(cmd.val)) + for k, v := range cmd.val { + val[k] = v + } + } + return &MapStringIntCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + // ------------------------------------------------------------------------------ type MapStringSliceInterfaceCmd struct { baseCmd @@ -1504,8 +1844,9 @@ type MapStringSliceInterfaceCmd struct { func NewMapStringSliceInterfaceCmd(ctx context.Context, args ...interface{}) *MapStringSliceInterfaceCmd { return &MapStringSliceInterfaceCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeMapStringInterfaceSlice, }, } } @@ -1591,6 +1932,24 @@ func (cmd *MapStringSliceInterfaceCmd) readReply(rd *proto.Reader) (err error) { return nil } +func (cmd *MapStringSliceInterfaceCmd) Clone() Cmder { + var val map[string][]interface{} + if cmd.val != nil { + val = make(map[string][]interface{}, len(cmd.val)) + for k, v := range cmd.val { + if v != nil { + newSlice := make([]interface{}, len(v)) + copy(newSlice, v) + val[k] = newSlice + } + } + } + return &MapStringSliceInterfaceCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ type StringStructMapCmd struct { @@ -1604,8 +1963,9 @@ var _ Cmder = (*StringStructMapCmd)(nil) func NewStringStructMapCmd(ctx context.Context, args ...interface{}) *StringStructMapCmd { return &StringStructMapCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeStringStructMap, }, } } @@ -1643,6 +2003,17 @@ func (cmd *StringStructMapCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *StringStructMapCmd) Clone() Cmder { + var val map[string]struct{} + if cmd.val != nil { + val = maps.Clone(cmd.val) + } + return &StringStructMapCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ type XMessage struct { @@ -1667,8 +2038,9 @@ var _ Cmder = (*XMessageSliceCmd)(nil) func NewXMessageSliceCmd(ctx context.Context, args ...interface{}) *XMessageSliceCmd { return &XMessageSliceCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeXMessageSlice, }, } } @@ -1694,6 +2066,28 @@ func (cmd *XMessageSliceCmd) readReply(rd *proto.Reader) (err error) { return err } +func (cmd *XMessageSliceCmd) Clone() Cmder { + var val []XMessage + if cmd.val != nil { + val = make([]XMessage, len(cmd.val)) + for i, msg := range cmd.val { + val[i] = XMessage{ + ID: msg.ID, + } + if msg.Values != nil { + val[i].Values = make(map[string]interface{}, len(msg.Values)) + for k, v := range msg.Values { + val[i].Values[k] = v + } + } + } + } + return &XMessageSliceCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + func readXMessageSlice(rd *proto.Reader) ([]XMessage, error) { n, err := rd.ReadArrayLen() if err != nil { @@ -1793,8 +2187,9 @@ var _ Cmder = (*XStreamSliceCmd)(nil) func NewXStreamSliceCmd(ctx context.Context, args ...interface{}) *XStreamSliceCmd { return &XStreamSliceCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeXStreamSlice, }, } } @@ -1847,6 +2242,36 @@ func (cmd *XStreamSliceCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *XStreamSliceCmd) Clone() Cmder { + var val []XStream + if cmd.val != nil { + val = make([]XStream, len(cmd.val)) + for i, stream := range cmd.val { + val[i] = XStream{ + Stream: stream.Stream, + } + if stream.Messages != nil { + val[i].Messages = make([]XMessage, len(stream.Messages)) + for j, msg := range stream.Messages { + val[i].Messages[j] = XMessage{ + ID: msg.ID, + } + if msg.Values != nil { + val[i].Messages[j].Values = make(map[string]interface{}, len(msg.Values)) + for k, v := range msg.Values { + val[i].Messages[j].Values[k] = v + } + } + } + } + } + } + return &XStreamSliceCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ type XPending struct { @@ -1866,8 +2291,9 @@ var _ Cmder = (*XPendingCmd)(nil) func NewXPendingCmd(ctx context.Context, args ...interface{}) *XPendingCmd { return &XPendingCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeXPending, }, } } @@ -1930,6 +2356,27 @@ func (cmd *XPendingCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *XPendingCmd) Clone() Cmder { + var val *XPending + if cmd.val != nil { + val = &XPending{ + Count: cmd.val.Count, + Lower: cmd.val.Lower, + Higher: cmd.val.Higher, + } + if cmd.val.Consumers != nil { + val.Consumers = make(map[string]int64, len(cmd.val.Consumers)) + for k, v := range cmd.val.Consumers { + val.Consumers[k] = v + } + } + } + return &XPendingCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ type XPendingExt struct { @@ -1949,8 +2396,9 @@ var _ Cmder = (*XPendingExtCmd)(nil) func NewXPendingExtCmd(ctx context.Context, args ...interface{}) *XPendingExtCmd { return &XPendingExtCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeXPendingExt, }, } } @@ -2005,6 +2453,18 @@ func (cmd *XPendingExtCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *XPendingExtCmd) Clone() Cmder { + var val []XPendingExt + if cmd.val != nil { + val = make([]XPendingExt, len(cmd.val)) + copy(val, cmd.val) + } + return &XPendingExtCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ type XAutoClaimCmd struct { @@ -2019,8 +2479,9 @@ var _ Cmder = (*XAutoClaimCmd)(nil) func NewXAutoClaimCmd(ctx context.Context, args ...interface{}) *XAutoClaimCmd { return &XAutoClaimCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeXAutoClaim, }, } } @@ -2075,6 +2536,29 @@ func (cmd *XAutoClaimCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *XAutoClaimCmd) Clone() Cmder { + var val []XMessage + if cmd.val != nil { + val = make([]XMessage, len(cmd.val)) + for i, msg := range cmd.val { + val[i] = XMessage{ + ID: msg.ID, + } + if msg.Values != nil { + val[i].Values = make(map[string]interface{}, len(msg.Values)) + for k, v := range msg.Values { + val[i].Values[k] = v + } + } + } + } + return &XAutoClaimCmd{ + baseCmd: cmd.cloneBaseCmd(), + start: cmd.start, + val: val, + } +} + //------------------------------------------------------------------------------ type XAutoClaimJustIDCmd struct { @@ -2089,8 +2573,9 @@ var _ Cmder = (*XAutoClaimJustIDCmd)(nil) func NewXAutoClaimJustIDCmd(ctx context.Context, args ...interface{}) *XAutoClaimJustIDCmd { return &XAutoClaimJustIDCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeXAutoClaimJustID, }, } } @@ -2153,6 +2638,19 @@ func (cmd *XAutoClaimJustIDCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *XAutoClaimJustIDCmd) Clone() Cmder { + var val []string + if cmd.val != nil { + val = make([]string, len(cmd.val)) + copy(val, cmd.val) + } + return &XAutoClaimJustIDCmd{ + baseCmd: cmd.cloneBaseCmd(), + start: cmd.start, + val: val, + } +} + //------------------------------------------------------------------------------ type XInfoConsumersCmd struct { @@ -2172,8 +2670,9 @@ var _ Cmder = (*XInfoConsumersCmd)(nil) func NewXInfoConsumersCmd(ctx context.Context, stream string, group string) *XInfoConsumersCmd { return &XInfoConsumersCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: []interface{}{"xinfo", "consumers", stream, group}, + ctx: ctx, + args: []interface{}{"xinfo", "consumers", stream, group}, + cmdType: CmdTypeXInfoConsumers, }, } } @@ -2239,6 +2738,18 @@ func (cmd *XInfoConsumersCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *XInfoConsumersCmd) Clone() Cmder { + var val []XInfoConsumer + if cmd.val != nil { + val = make([]XInfoConsumer, len(cmd.val)) + copy(val, cmd.val) + } + return &XInfoConsumersCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ type XInfoGroupsCmd struct { @@ -2262,8 +2773,9 @@ var _ Cmder = (*XInfoGroupsCmd)(nil) func NewXInfoGroupsCmd(ctx context.Context, stream string) *XInfoGroupsCmd { return &XInfoGroupsCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: []interface{}{"xinfo", "groups", stream}, + ctx: ctx, + args: []interface{}{"xinfo", "groups", stream}, + cmdType: CmdTypeXInfoGroups, }, } } @@ -2352,6 +2864,18 @@ func (cmd *XInfoGroupsCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *XInfoGroupsCmd) Clone() Cmder { + var val []XInfoGroup + if cmd.val != nil { + val = make([]XInfoGroup, len(cmd.val)) + copy(val, cmd.val) + } + return &XInfoGroupsCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ type XInfoStreamCmd struct { @@ -2370,6 +2894,13 @@ type XInfoStream struct { FirstEntry XMessage LastEntry XMessage RecordedFirstEntryID string + + IDMPDuration int64 + IDMPMaxSize int64 + PIDsTracked int64 + IIDsTracked int64 + IIDsAdded int64 + IIDsDuplicates int64 } var _ Cmder = (*XInfoStreamCmd)(nil) @@ -2377,8 +2908,9 @@ var _ Cmder = (*XInfoStreamCmd)(nil) func NewXInfoStreamCmd(ctx context.Context, stream string) *XInfoStreamCmd { return &XInfoStreamCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: []interface{}{"xinfo", "stream", stream}, + ctx: ctx, + args: []interface{}{"xinfo", "stream", stream}, + cmdType: CmdTypeXInfoStream, }, } } @@ -2462,6 +2994,36 @@ func (cmd *XInfoStreamCmd) readReply(rd *proto.Reader) error { if err != nil { return err } + case "idmp-duration": + cmd.val.IDMPDuration, err = rd.ReadInt() + if err != nil { + return err + } + case "idmp-maxsize": + cmd.val.IDMPMaxSize, err = rd.ReadInt() + if err != nil { + return err + } + case "pids-tracked": + cmd.val.PIDsTracked, err = rd.ReadInt() + if err != nil { + return err + } + case "iids-tracked": + cmd.val.IIDsTracked, err = rd.ReadInt() + if err != nil { + return err + } + case "iids-added": + cmd.val.IIDsAdded, err = rd.ReadInt() + if err != nil { + return err + } + case "iids-duplicates": + cmd.val.IIDsDuplicates, err = rd.ReadInt() + if err != nil { + return err + } default: return fmt.Errorf("redis: unexpected key %q in XINFO STREAM reply", key) } @@ -2469,11 +3031,50 @@ func (cmd *XInfoStreamCmd) readReply(rd *proto.Reader) error { return nil } -//------------------------------------------------------------------------------ - -type XInfoStreamFullCmd struct { - baseCmd - val *XInfoStreamFull +func (cmd *XInfoStreamCmd) Clone() Cmder { + var val *XInfoStream + if cmd.val != nil { + val = &XInfoStream{ + Length: cmd.val.Length, + RadixTreeKeys: cmd.val.RadixTreeKeys, + RadixTreeNodes: cmd.val.RadixTreeNodes, + Groups: cmd.val.Groups, + LastGeneratedID: cmd.val.LastGeneratedID, + MaxDeletedEntryID: cmd.val.MaxDeletedEntryID, + EntriesAdded: cmd.val.EntriesAdded, + RecordedFirstEntryID: cmd.val.RecordedFirstEntryID, + } + // Clone XMessage fields + val.FirstEntry = XMessage{ + ID: cmd.val.FirstEntry.ID, + } + if cmd.val.FirstEntry.Values != nil { + val.FirstEntry.Values = make(map[string]interface{}, len(cmd.val.FirstEntry.Values)) + for k, v := range cmd.val.FirstEntry.Values { + val.FirstEntry.Values[k] = v + } + } + val.LastEntry = XMessage{ + ID: cmd.val.LastEntry.ID, + } + if cmd.val.LastEntry.Values != nil { + val.LastEntry.Values = make(map[string]interface{}, len(cmd.val.LastEntry.Values)) + for k, v := range cmd.val.LastEntry.Values { + val.LastEntry.Values[k] = v + } + } + } + return &XInfoStreamCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + +//------------------------------------------------------------------------------ + +type XInfoStreamFullCmd struct { + baseCmd + val *XInfoStreamFull } type XInfoStreamFull struct { @@ -2486,6 +3087,12 @@ type XInfoStreamFull struct { Entries []XMessage Groups []XInfoStreamGroup RecordedFirstEntryID string + IDMPDuration int64 + IDMPMaxSize int64 + PIDsTracked int64 + IIDsTracked int64 + IIDsAdded int64 + IIDsDuplicates int64 } type XInfoStreamGroup struct { @@ -2524,8 +3131,9 @@ var _ Cmder = (*XInfoStreamFullCmd)(nil) func NewXInfoStreamFullCmd(ctx context.Context, args ...interface{}) *XInfoStreamFullCmd { return &XInfoStreamFullCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeXInfoStreamFull, }, } } @@ -2606,6 +3214,36 @@ func (cmd *XInfoStreamFullCmd) readReply(rd *proto.Reader) error { if err != nil { return err } + case "idmp-duration": + cmd.val.IDMPDuration, err = rd.ReadInt() + if err != nil { + return err + } + case "idmp-maxsize": + cmd.val.IDMPMaxSize, err = rd.ReadInt() + if err != nil { + return err + } + case "pids-tracked": + cmd.val.PIDsTracked, err = rd.ReadInt() + if err != nil { + return err + } + case "iids-tracked": + cmd.val.IIDsTracked, err = rd.ReadInt() + if err != nil { + return err + } + case "iids-added": + cmd.val.IIDsAdded, err = rd.ReadInt() + if err != nil { + return err + } + case "iids-duplicates": + cmd.val.IIDsDuplicates, err = rd.ReadInt() + if err != nil { + return err + } default: return fmt.Errorf("redis: unexpected key %q in XINFO STREAM FULL reply", key) } @@ -2810,6 +3448,45 @@ func readXInfoStreamConsumers(rd *proto.Reader) ([]XInfoStreamConsumer, error) { return consumers, nil } +func (cmd *XInfoStreamFullCmd) Clone() Cmder { + var val *XInfoStreamFull + if cmd.val != nil { + val = &XInfoStreamFull{ + Length: cmd.val.Length, + RadixTreeKeys: cmd.val.RadixTreeKeys, + RadixTreeNodes: cmd.val.RadixTreeNodes, + LastGeneratedID: cmd.val.LastGeneratedID, + MaxDeletedEntryID: cmd.val.MaxDeletedEntryID, + EntriesAdded: cmd.val.EntriesAdded, + RecordedFirstEntryID: cmd.val.RecordedFirstEntryID, + } + // Clone Entries + if cmd.val.Entries != nil { + val.Entries = make([]XMessage, len(cmd.val.Entries)) + for i, msg := range cmd.val.Entries { + val.Entries[i] = XMessage{ + ID: msg.ID, + } + if msg.Values != nil { + val.Entries[i].Values = make(map[string]interface{}, len(msg.Values)) + for k, v := range msg.Values { + val.Entries[i].Values[k] = v + } + } + } + } + // Clone Groups - simplified copy for now due to complexity + if cmd.val.Groups != nil { + val.Groups = make([]XInfoStreamGroup, len(cmd.val.Groups)) + copy(val.Groups, cmd.val.Groups) + } + } + return &XInfoStreamFullCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ type ZSliceCmd struct { @@ -2823,8 +3500,9 @@ var _ Cmder = (*ZSliceCmd)(nil) func NewZSliceCmd(ctx context.Context, args ...interface{}) *ZSliceCmd { return &ZSliceCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeZSlice, }, } } @@ -2888,6 +3566,18 @@ func (cmd *ZSliceCmd) readReply(rd *proto.Reader) error { // nolint:dupl return nil } +func (cmd *ZSliceCmd) Clone() Cmder { + var val []Z + if cmd.val != nil { + val = make([]Z, len(cmd.val)) + copy(val, cmd.val) + } + return &ZSliceCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ type ZWithKeyCmd struct { @@ -2901,8 +3591,9 @@ var _ Cmder = (*ZWithKeyCmd)(nil) func NewZWithKeyCmd(ctx context.Context, args ...interface{}) *ZWithKeyCmd { return &ZWithKeyCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeZWithKey, }, } } @@ -2942,6 +3633,23 @@ func (cmd *ZWithKeyCmd) readReply(rd *proto.Reader) (err error) { return nil } +func (cmd *ZWithKeyCmd) Clone() Cmder { + var val *ZWithKey + if cmd.val != nil { + val = &ZWithKey{ + Z: Z{ + Score: cmd.val.Score, + Member: cmd.val.Member, + }, + Key: cmd.val.Key, + } + } + return &ZWithKeyCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ type ScanCmd struct { @@ -2958,8 +3666,9 @@ var _ Cmder = (*ScanCmd)(nil) func NewScanCmd(ctx context.Context, process cmdable, args ...interface{}) *ScanCmd { return &ScanCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeScan, }, process: process, } @@ -3007,6 +3716,20 @@ func (cmd *ScanCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *ScanCmd) Clone() Cmder { + var page []string + if cmd.page != nil { + page = make([]string, len(cmd.page)) + copy(page, cmd.page) + } + return &ScanCmd{ + baseCmd: cmd.cloneBaseCmd(), + page: page, + cursor: cmd.cursor, + process: cmd.process, + } +} + // Iterator creates a new ScanIterator. func (cmd *ScanCmd) Iterator() *ScanIterator { return &ScanIterator{ @@ -3039,8 +3762,9 @@ var _ Cmder = (*ClusterSlotsCmd)(nil) func NewClusterSlotsCmd(ctx context.Context, args ...interface{}) *ClusterSlotsCmd { return &ClusterSlotsCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeClusterSlots, }, } } @@ -3153,6 +3877,38 @@ func (cmd *ClusterSlotsCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *ClusterSlotsCmd) Clone() Cmder { + var val []ClusterSlot + if cmd.val != nil { + val = make([]ClusterSlot, len(cmd.val)) + for i, slot := range cmd.val { + val[i] = ClusterSlot{ + Start: slot.Start, + End: slot.End, + } + if slot.Nodes != nil { + val[i].Nodes = make([]ClusterNode, len(slot.Nodes)) + for j, node := range slot.Nodes { + val[i].Nodes[j] = ClusterNode{ + ID: node.ID, + Addr: node.Addr, + } + if node.NetworkingMetadata != nil { + val[i].Nodes[j].NetworkingMetadata = make(map[string]string, len(node.NetworkingMetadata)) + for k, v := range node.NetworkingMetadata { + val[i].Nodes[j].NetworkingMetadata[k] = v + } + } + } + } + } + } + return &ClusterSlotsCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ // GeoLocation is used with GeoAdd to add geospatial location. @@ -3192,8 +3948,9 @@ var _ Cmder = (*GeoLocationCmd)(nil) func NewGeoLocationCmd(ctx context.Context, q *GeoRadiusQuery, args ...interface{}) *GeoLocationCmd { return &GeoLocationCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: geoLocationArgs(q, args...), + ctx: ctx, + args: geoLocationArgs(q, args...), + cmdType: CmdTypeGeoLocation, }, q: q, } @@ -3301,6 +4058,34 @@ func (cmd *GeoLocationCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *GeoLocationCmd) Clone() Cmder { + var q *GeoRadiusQuery + if cmd.q != nil { + q = &GeoRadiusQuery{ + Radius: cmd.q.Radius, + Unit: cmd.q.Unit, + WithCoord: cmd.q.WithCoord, + WithDist: cmd.q.WithDist, + WithGeoHash: cmd.q.WithGeoHash, + Count: cmd.q.Count, + Sort: cmd.q.Sort, + Store: cmd.q.Store, + StoreDist: cmd.q.StoreDist, + withLen: cmd.q.withLen, + } + } + var locations []GeoLocation + if cmd.locations != nil { + locations = make([]GeoLocation, len(cmd.locations)) + copy(locations, cmd.locations) + } + return &GeoLocationCmd{ + baseCmd: cmd.cloneBaseCmd(), + q: q, + locations: locations, + } +} + //------------------------------------------------------------------------------ // GeoSearchQuery is used for GEOSearch/GEOSearchStore command query. @@ -3408,8 +4193,9 @@ func NewGeoSearchLocationCmd( ) *GeoSearchLocationCmd { return &GeoSearchLocationCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: geoSearchLocationArgs(opt, args), + cmdType: CmdTypeGeoSearchLocation, }, opt: opt, } @@ -3482,6 +4268,40 @@ func (cmd *GeoSearchLocationCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *GeoSearchLocationCmd) Clone() Cmder { + var opt *GeoSearchLocationQuery + if cmd.opt != nil { + opt = &GeoSearchLocationQuery{ + GeoSearchQuery: GeoSearchQuery{ + Member: cmd.opt.Member, + Longitude: cmd.opt.Longitude, + Latitude: cmd.opt.Latitude, + Radius: cmd.opt.Radius, + RadiusUnit: cmd.opt.RadiusUnit, + BoxWidth: cmd.opt.BoxWidth, + BoxHeight: cmd.opt.BoxHeight, + BoxUnit: cmd.opt.BoxUnit, + Sort: cmd.opt.Sort, + Count: cmd.opt.Count, + CountAny: cmd.opt.CountAny, + }, + WithCoord: cmd.opt.WithCoord, + WithDist: cmd.opt.WithDist, + WithHash: cmd.opt.WithHash, + } + } + var val []GeoLocation + if cmd.val != nil { + val = make([]GeoLocation, len(cmd.val)) + copy(val, cmd.val) + } + return &GeoSearchLocationCmd{ + baseCmd: cmd.cloneBaseCmd(), + opt: opt, + val: val, + } +} + //------------------------------------------------------------------------------ type GeoPos struct { @@ -3499,8 +4319,9 @@ var _ Cmder = (*GeoPosCmd)(nil) func NewGeoPosCmd(ctx context.Context, args ...interface{}) *GeoPosCmd { return &GeoPosCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeGeoPos, }, } } @@ -3556,17 +4377,37 @@ func (cmd *GeoPosCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *GeoPosCmd) Clone() Cmder { + var val []*GeoPos + if cmd.val != nil { + val = make([]*GeoPos, len(cmd.val)) + for i, pos := range cmd.val { + if pos != nil { + val[i] = &GeoPos{ + Longitude: pos.Longitude, + Latitude: pos.Latitude, + } + } + } + } + return &GeoPosCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ type CommandInfo struct { - Name string - Arity int8 - Flags []string - ACLFlags []string - FirstKeyPos int8 - LastKeyPos int8 - StepCount int8 - ReadOnly bool + Name string + Arity int8 + Flags []string + ACLFlags []string + FirstKeyPos int8 + LastKeyPos int8 + StepCount int8 + ReadOnly bool + CommandPolicy *routing.CommandPolicy } type CommandsInfoCmd struct { @@ -3580,8 +4421,9 @@ var _ Cmder = (*CommandsInfoCmd)(nil) func NewCommandsInfoCmd(ctx context.Context, args ...interface{}) *CommandsInfoCmd { return &CommandsInfoCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeCommandsInfo, }, } } @@ -3605,7 +4447,7 @@ func (cmd *CommandsInfoCmd) String() string { func (cmd *CommandsInfoCmd) readReply(rd *proto.Reader) error { const numArgRedis5 = 6 const numArgRedis6 = 7 - const numArgRedis7 = 10 + const numArgRedis7 = 10 // Also matches redis 8 n, err := rd.ReadArrayLen() if err != nil { @@ -3693,9 +4535,33 @@ func (cmd *CommandsInfoCmd) readReply(rd *proto.Reader) error { } if nn >= numArgRedis7 { - if err := rd.DiscardNext(); err != nil { + // The 8th argument is an array of tips. + tipsLen, err := rd.ReadArrayLen() + if err != nil { return err } + + rawTips := make(map[string]string, tipsLen) + if cmdInfo.ReadOnly { + rawTips[routing.ReadOnlyCMD] = "" + } + for f := 0; f < tipsLen; f++ { + tip, err := rd.ReadString() + if err != nil { + return err + } + + k, v, ok := strings.Cut(tip, ":") + if !ok { + // Handle tips that don't have a colon (like "nondeterministic_output") + rawTips[tip] = "" + } else { + // Handle normal key:value tips + rawTips[k] = v + } + } + cmdInfo.CommandPolicy = parseCommandPolicies(rawTips, cmdInfo.FirstKeyPos) + if err := rd.DiscardNext(); err != nil { return err } @@ -3710,13 +4576,47 @@ func (cmd *CommandsInfoCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *CommandsInfoCmd) Clone() Cmder { + var val map[string]*CommandInfo + if cmd.val != nil { + val = make(map[string]*CommandInfo, len(cmd.val)) + for k, v := range cmd.val { + if v != nil { + newInfo := &CommandInfo{ + Name: v.Name, + Arity: v.Arity, + FirstKeyPos: v.FirstKeyPos, + LastKeyPos: v.LastKeyPos, + StepCount: v.StepCount, + ReadOnly: v.ReadOnly, + CommandPolicy: v.CommandPolicy, // CommandPolicy can be shared as it's immutable + } + if v.Flags != nil { + newInfo.Flags = make([]string, len(v.Flags)) + copy(newInfo.Flags, v.Flags) + } + if v.ACLFlags != nil { + newInfo.ACLFlags = make([]string, len(v.ACLFlags)) + copy(newInfo.ACLFlags, v.ACLFlags) + } + val[k] = newInfo + } + } + } + return &CommandsInfoCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ type cmdsInfoCache struct { fn func(ctx context.Context) (map[string]*CommandInfo, error) - once internal.Once - cmds map[string]*CommandInfo + once internal.Once + refreshLock sync.Mutex + cmds map[string]*CommandInfo } func newCmdsInfoCache(fn func(ctx context.Context) (map[string]*CommandInfo, error)) *cmdsInfoCache { @@ -3726,6 +4626,9 @@ func newCmdsInfoCache(fn func(ctx context.Context) (map[string]*CommandInfo, err } func (c *cmdsInfoCache) Get(ctx context.Context) (map[string]*CommandInfo, error) { + c.refreshLock.Lock() + defer c.refreshLock.Unlock() + err := c.once.Do(func() error { cmds, err := c.fn(ctx) if err != nil { @@ -3745,6 +4648,44 @@ func (c *cmdsInfoCache) Get(ctx context.Context) (map[string]*CommandInfo, error return c.cmds, err } +func (c *cmdsInfoCache) Refresh() { + c.refreshLock.Lock() + defer c.refreshLock.Unlock() + + c.once = internal.Once{} +} + +// ------------------------------------------------------------------------------ +const requestPolicy = "request_policy" +const responsePolicy = "response_policy" + +func parseCommandPolicies(commandInfoTips map[string]string, firstKeyPos int8) *routing.CommandPolicy { + req := routing.ReqDefault + resp := routing.RespDefaultKeyless + if firstKeyPos > 0 { + resp = routing.RespDefaultHashSlot + } + + tips := make(map[string]string, len(commandInfoTips)) + for k, v := range commandInfoTips { + if k == requestPolicy { + if p, err := routing.ParseRequestPolicy(v); err == nil { + req = p + } + continue + } + if k == responsePolicy { + if p, err := routing.ParseResponsePolicy(v); err == nil { + resp = p + } + continue + } + tips[k] = v + } + + return &routing.CommandPolicy{Request: req, Response: resp, Tips: tips} +} + //------------------------------------------------------------------------------ type SlowLog struct { @@ -3769,8 +4710,9 @@ var _ Cmder = (*SlowLogCmd)(nil) func NewSlowLogCmd(ctx context.Context, args ...interface{}) *SlowLogCmd { return &SlowLogCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeSlowLog, }, } } @@ -3855,6 +4797,30 @@ func (cmd *SlowLogCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *SlowLogCmd) Clone() Cmder { + var val []SlowLog + if cmd.val != nil { + val = make([]SlowLog, len(cmd.val)) + for i, log := range cmd.val { + val[i] = SlowLog{ + ID: log.ID, + Time: log.Time, + Duration: log.Duration, + ClientAddr: log.ClientAddr, + ClientName: log.ClientName, + } + if log.Args != nil { + val[i].Args = make([]string, len(log.Args)) + copy(val[i].Args, log.Args) + } + } + } + return &SlowLogCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //----------------------------------------------------------------------- type Latency struct { @@ -3932,6 +4898,255 @@ func (cmd *LatencyCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *LatencyCmd) Clone() Cmder { + var val []Latency + if cmd.val != nil { + val = make([]Latency, len(cmd.val)) + copy(val, cmd.val) + } + return &LatencyCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + +//----------------------------------------------------------------------- + +// HotKeysSlotRange represents a slot or slot range in the response. +// Single element slice = individual slot, two element slice = slot range [start, end]. +type HotKeysSlotRange []int64 + +// HotKeysKeyEntry represents a hot key entry with its metric value. +type HotKeysKeyEntry struct { + Key string + Value interface{} // Can be int64 or string +} + +// HotKeysResult represents the response data from HOTKEYS GET command. +// Field names match the Redis response format. +type HotKeysResult struct { + TrackingActive bool + SampleRatio uint8 + SelectedSlots []HotKeysSlotRange + SampledCommandsSelectedSlots time.Duration // Present when sample-ratio > 1 and selected-slots is not empty + AllCommandsSelectedSlots time.Duration // Present when selected-slots is not empty + AllCommandsAllSlots time.Duration + NetBytesSampledCommandsSelectedSlots int64 // Present when sample-ratio > 1 and selected-slots is not empty + NetBytesAllCommandsSelectedSlots int64 // Present when selected-slots is not empty + NetBytesAllCommandsAllSlots int64 + CollectionStartTime time.Time + CollectionDuration time.Duration + UsedCPUSys time.Duration + UsedCPUUser time.Duration + TotalNetBytes int64 + ByCPUTime []HotKeysKeyEntry + ByNetBytes []HotKeysKeyEntry +} + +type HotKeysCmd struct { + baseCmd + + val *HotKeysResult +} + +var _ Cmder = (*HotKeysCmd)(nil) + +func NewHotKeysCmd(ctx context.Context, args ...interface{}) *HotKeysCmd { + return &HotKeysCmd{ + baseCmd: baseCmd{ + ctx: ctx, + args: args, + cmdType: CmdTypeHotKeys, + }, + } +} + +func (cmd *HotKeysCmd) SetVal(val *HotKeysResult) { + cmd.val = val +} + +func (cmd *HotKeysCmd) Val() *HotKeysResult { + return cmd.val +} + +func (cmd *HotKeysCmd) Result() (*HotKeysResult, error) { + return cmd.val, cmd.err +} + +func (cmd *HotKeysCmd) String() string { + return cmdString(cmd, cmd.val) +} + +func (cmd *HotKeysCmd) readReply(rd *proto.Reader) error { + // HOTKEYS GET response is wrapped in an array for aggregation support + arrayLen, err := rd.ReadArrayLen() + if err != nil { + return err + } + + if arrayLen == 0 { + // Empty array means no tracking was started or after reset + cmd.val = nil + return nil + } + + // Read the first (and typically only) element which is a map + n, err := rd.ReadMapLen() + if err != nil { + return err + } + + result := &HotKeysResult{} + data := make(map[string]interface{}, n) + + for i := 0; i < n; i++ { + k, err := rd.ReadString() + if err != nil { + return err + } + v, err := rd.ReadReply() + if err != nil { + if err == Nil { + data[k] = Nil + continue + } + if err, ok := err.(proto.RedisError); ok { + data[k] = err + continue + } + return err + } + data[k] = v + } + + if v, ok := data["tracking-active"].(int64); ok { + result.TrackingActive = v == 1 + } + if v, ok := data["sample-ratio"].(int64); ok { + result.SampleRatio = uint8(v) + } + if v, ok := data["selected-slots"].([]interface{}); ok { + result.SelectedSlots = make([]HotKeysSlotRange, 0, len(v)) + for _, slot := range v { + switch s := slot.(type) { + case int64: + // Single slot + result.SelectedSlots = append(result.SelectedSlots, HotKeysSlotRange{s}) + case []interface{}: + // Slot range + slotRange := make(HotKeysSlotRange, 0, len(s)) + for _, sr := range s { + if val, ok := sr.(int64); ok { + slotRange = append(slotRange, val) + } + } + result.SelectedSlots = append(result.SelectedSlots, slotRange) + } + } + } + if v, ok := data["sampled-commands-selected-slots-us"].(int64); ok { + result.SampledCommandsSelectedSlots = time.Duration(v) * time.Microsecond + } + if v, ok := data["all-commands-selected-slots-us"].(int64); ok { + result.AllCommandsSelectedSlots = time.Duration(v) * time.Microsecond + } + if v, ok := data["all-commands-all-slots-us"].(int64); ok { + result.AllCommandsAllSlots = time.Duration(v) * time.Microsecond + } + if v, ok := data["net-bytes-sampled-commands-selected-slots"].(int64); ok { + result.NetBytesSampledCommandsSelectedSlots = v + } + if v, ok := data["net-bytes-all-commands-selected-slots"].(int64); ok { + result.NetBytesAllCommandsSelectedSlots = v + } + if v, ok := data["net-bytes-all-commands-all-slots"].(int64); ok { + result.NetBytesAllCommandsAllSlots = v + } + if v, ok := data["collection-start-time-unix-ms"].(int64); ok { + result.CollectionStartTime = time.UnixMilli(v) + } + if v, ok := data["collection-duration-ms"].(int64); ok { + result.CollectionDuration = time.Duration(v) * time.Millisecond + } + if v, ok := data["used-cpu-sys-ms"].(int64); ok { + result.UsedCPUSys = time.Duration(v) * time.Millisecond + } + if v, ok := data["used-cpu-user-ms"].(int64); ok { + result.UsedCPUUser = time.Duration(v) * time.Millisecond + } + if v, ok := data["total-net-bytes"].(int64); ok { + result.TotalNetBytes = v + } + + if v, ok := data["by-cpu-time-us"].([]interface{}); ok { + result.ByCPUTime = parseHotKeysKeyEntries(v) + } + + if v, ok := data["by-net-bytes"].([]interface{}); ok { + result.ByNetBytes = parseHotKeysKeyEntries(v) + } + + cmd.val = result + return nil +} + +// parseHotKeysKeyEntries parses the key-value pairs from HOTKEYS GET response. +func parseHotKeysKeyEntries(v []interface{}) []HotKeysKeyEntry { + entries := make([]HotKeysKeyEntry, 0, len(v)/2) + for i := 0; i < len(v); i += 2 { + if i+1 < len(v) { + key, keyOk := v[i].(string) + if keyOk { + entries = append(entries, HotKeysKeyEntry{ + Key: key, + Value: v[i+1], // Can be int64 or string + }) + } + } + } + return entries +} + +func (cmd *HotKeysCmd) Clone() Cmder { + var val *HotKeysResult + if cmd.val != nil { + val = &HotKeysResult{ + TrackingActive: cmd.val.TrackingActive, + SampleRatio: cmd.val.SampleRatio, + SampledCommandsSelectedSlots: cmd.val.SampledCommandsSelectedSlots, + AllCommandsSelectedSlots: cmd.val.AllCommandsSelectedSlots, + AllCommandsAllSlots: cmd.val.AllCommandsAllSlots, + NetBytesSampledCommandsSelectedSlots: cmd.val.NetBytesSampledCommandsSelectedSlots, + NetBytesAllCommandsSelectedSlots: cmd.val.NetBytesAllCommandsSelectedSlots, + NetBytesAllCommandsAllSlots: cmd.val.NetBytesAllCommandsAllSlots, + CollectionStartTime: cmd.val.CollectionStartTime, + CollectionDuration: cmd.val.CollectionDuration, + UsedCPUSys: cmd.val.UsedCPUSys, + UsedCPUUser: cmd.val.UsedCPUUser, + TotalNetBytes: cmd.val.TotalNetBytes, + } + if cmd.val.SelectedSlots != nil { + val.SelectedSlots = make([]HotKeysSlotRange, len(cmd.val.SelectedSlots)) + for i, sr := range cmd.val.SelectedSlots { + val.SelectedSlots[i] = make(HotKeysSlotRange, len(sr)) + copy(val.SelectedSlots[i], sr) + } + } + if cmd.val.ByCPUTime != nil { + val.ByCPUTime = make([]HotKeysKeyEntry, len(cmd.val.ByCPUTime)) + copy(val.ByCPUTime, cmd.val.ByCPUTime) + } + if cmd.val.ByNetBytes != nil { + val.ByNetBytes = make([]HotKeysKeyEntry, len(cmd.val.ByNetBytes)) + copy(val.ByNetBytes, cmd.val.ByNetBytes) + } + } + return &HotKeysCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //----------------------------------------------------------------------- type MapStringInterfaceCmd struct { @@ -3945,8 +5160,9 @@ var _ Cmder = (*MapStringInterfaceCmd)(nil) func NewMapStringInterfaceCmd(ctx context.Context, args ...interface{}) *MapStringInterfaceCmd { return &MapStringInterfaceCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeMapStringInterface, }, } } @@ -3996,6 +5212,20 @@ func (cmd *MapStringInterfaceCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *MapStringInterfaceCmd) Clone() Cmder { + var val map[string]interface{} + if cmd.val != nil { + val = make(map[string]interface{}, len(cmd.val)) + for k, v := range cmd.val { + val[k] = v + } + } + return &MapStringInterfaceCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //----------------------------------------------------------------------- type MapStringStringSliceCmd struct { @@ -4009,8 +5239,9 @@ var _ Cmder = (*MapStringStringSliceCmd)(nil) func NewMapStringStringSliceCmd(ctx context.Context, args ...interface{}) *MapStringStringSliceCmd { return &MapStringStringSliceCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeMapStringStringSlice, }, } } @@ -4060,6 +5291,25 @@ func (cmd *MapStringStringSliceCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *MapStringStringSliceCmd) Clone() Cmder { + var val []map[string]string + if cmd.val != nil { + val = make([]map[string]string, len(cmd.val)) + for i, m := range cmd.val { + if m != nil { + val[i] = make(map[string]string, len(m)) + for k, v := range m { + val[i][k] = v + } + } + } + } + return &MapStringStringSliceCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + // ----------------------------------------------------------------------- // MapMapStringInterfaceCmd represents a command that returns a map of strings to interface{}. @@ -4071,8 +5321,9 @@ type MapMapStringInterfaceCmd struct { func NewMapMapStringInterfaceCmd(ctx context.Context, args ...interface{}) *MapMapStringInterfaceCmd { return &MapMapStringInterfaceCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeMapMapStringInterface, }, } } @@ -4138,6 +5389,20 @@ func (cmd *MapMapStringInterfaceCmd) readReply(rd *proto.Reader) (err error) { return nil } +func (cmd *MapMapStringInterfaceCmd) Clone() Cmder { + var val map[string]interface{} + if cmd.val != nil { + val = make(map[string]interface{}, len(cmd.val)) + for k, v := range cmd.val { + val[k] = v + } + } + return &MapMapStringInterfaceCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //----------------------------------------------------------------------- type MapStringInterfaceSliceCmd struct { @@ -4151,8 +5416,9 @@ var _ Cmder = (*MapStringInterfaceSliceCmd)(nil) func NewMapStringInterfaceSliceCmd(ctx context.Context, args ...interface{}) *MapStringInterfaceSliceCmd { return &MapStringInterfaceSliceCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeMapStringInterfaceSlice, }, } } @@ -4203,6 +5469,25 @@ func (cmd *MapStringInterfaceSliceCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *MapStringInterfaceSliceCmd) Clone() Cmder { + var val []map[string]interface{} + if cmd.val != nil { + val = make([]map[string]interface{}, len(cmd.val)) + for i, m := range cmd.val { + if m != nil { + val[i] = make(map[string]interface{}, len(m)) + for k, v := range m { + val[i][k] = v + } + } + } + } + return &MapStringInterfaceSliceCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ type KeyValuesCmd struct { @@ -4217,8 +5502,9 @@ var _ Cmder = (*KeyValuesCmd)(nil) func NewKeyValuesCmd(ctx context.Context, args ...interface{}) *KeyValuesCmd { return &KeyValuesCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeKeyValues, }, } } @@ -4265,6 +5551,19 @@ func (cmd *KeyValuesCmd) readReply(rd *proto.Reader) (err error) { return nil } +func (cmd *KeyValuesCmd) Clone() Cmder { + var val []string + if cmd.val != nil { + val = make([]string, len(cmd.val)) + copy(val, cmd.val) + } + return &KeyValuesCmd{ + baseCmd: cmd.cloneBaseCmd(), + key: cmd.key, + val: val, + } +} + //------------------------------------------------------------------------------ type ZSliceWithKeyCmd struct { @@ -4279,8 +5578,9 @@ var _ Cmder = (*ZSliceWithKeyCmd)(nil) func NewZSliceWithKeyCmd(ctx context.Context, args ...interface{}) *ZSliceWithKeyCmd { return &ZSliceWithKeyCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeZSliceWithKey, }, } } @@ -4348,6 +5648,19 @@ func (cmd *ZSliceWithKeyCmd) readReply(rd *proto.Reader) (err error) { return nil } +func (cmd *ZSliceWithKeyCmd) Clone() Cmder { + var val []Z + if cmd.val != nil { + val = make([]Z, len(cmd.val)) + copy(val, cmd.val) + } + return &ZSliceWithKeyCmd{ + baseCmd: cmd.cloneBaseCmd(), + key: cmd.key, + val: val, + } +} + type Function struct { Name string Description string @@ -4372,8 +5685,9 @@ var _ Cmder = (*FunctionListCmd)(nil) func NewFunctionListCmd(ctx context.Context, args ...interface{}) *FunctionListCmd { return &FunctionListCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeFunctionList, }, } } @@ -4500,6 +5814,37 @@ func (cmd *FunctionListCmd) readFunctions(rd *proto.Reader) ([]Function, error) return functions, nil } +func (cmd *FunctionListCmd) Clone() Cmder { + var val []Library + if cmd.val != nil { + val = make([]Library, len(cmd.val)) + for i, lib := range cmd.val { + val[i] = Library{ + Name: lib.Name, + Engine: lib.Engine, + Code: lib.Code, + } + if lib.Functions != nil { + val[i].Functions = make([]Function, len(lib.Functions)) + for j, fn := range lib.Functions { + val[i].Functions[j] = Function{ + Name: fn.Name, + Description: fn.Description, + } + if fn.Flags != nil { + val[i].Functions[j].Flags = make([]string, len(fn.Flags)) + copy(val[i].Functions[j].Flags, fn.Flags) + } + } + } + } + } + return &FunctionListCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + // FunctionStats contains information about the scripts currently executing on the server, and the available engines // - Engines: // Statistics about the engine like number of functions and number of libraries @@ -4553,8 +5898,9 @@ var _ Cmder = (*FunctionStatsCmd)(nil) func NewFunctionStatsCmd(ctx context.Context, args ...interface{}) *FunctionStatsCmd { return &FunctionStatsCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeFunctionStats, }, } } @@ -4725,6 +6071,34 @@ func (cmd *FunctionStatsCmd) readRunningScripts(rd *proto.Reader) ([]RunningScri return runningScripts, len(runningScripts) > 0, nil } +func (cmd *FunctionStatsCmd) Clone() Cmder { + val := FunctionStats{ + isRunning: cmd.val.isRunning, + rs: cmd.val.rs, // RunningScript is a simple struct, can be copied directly + } + if cmd.val.Engines != nil { + val.Engines = make([]Engine, len(cmd.val.Engines)) + copy(val.Engines, cmd.val.Engines) + } + if cmd.val.allrs != nil { + val.allrs = make([]RunningScript, len(cmd.val.allrs)) + for i, rs := range cmd.val.allrs { + val.allrs[i] = RunningScript{ + Name: rs.Name, + Duration: rs.Duration, + } + if rs.Command != nil { + val.allrs[i].Command = make([]string, len(rs.Command)) + copy(val.allrs[i].Command, rs.Command) + } + } + } + return &FunctionStatsCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ // LCSQuery is a parameter used for the LCS command @@ -4788,8 +6162,9 @@ func NewLCSCmd(ctx context.Context, q *LCSQuery) *LCSCmd { } } cmd.baseCmd = baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeLCS, } return cmd @@ -4901,6 +6276,25 @@ func (cmd *LCSCmd) readPosition(rd *proto.Reader) (pos LCSPosition, err error) { return pos, nil } +func (cmd *LCSCmd) Clone() Cmder { + var val *LCSMatch + if cmd.val != nil { + val = &LCSMatch{ + MatchString: cmd.val.MatchString, + Len: cmd.val.Len, + } + if cmd.val.Matches != nil { + val.Matches = make([]LCSMatchedPosition, len(cmd.val.Matches)) + copy(val.Matches, cmd.val.Matches) + } + } + return &LCSCmd{ + baseCmd: cmd.cloneBaseCmd(), + readType: cmd.readType, + val: val, + } +} + // ------------------------------------------------------------------------ type KeyFlags struct { @@ -4919,8 +6313,9 @@ var _ Cmder = (*KeyFlagsCmd)(nil) func NewKeyFlagsCmd(ctx context.Context, args ...interface{}) *KeyFlagsCmd { return &KeyFlagsCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeKeyFlags, }, } } @@ -4979,6 +6374,26 @@ func (cmd *KeyFlagsCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *KeyFlagsCmd) Clone() Cmder { + var val []KeyFlags + if cmd.val != nil { + val = make([]KeyFlags, len(cmd.val)) + for i, kf := range cmd.val { + val[i] = KeyFlags{ + Key: kf.Key, + } + if kf.Flags != nil { + val[i].Flags = make([]string, len(kf.Flags)) + copy(val[i].Flags, kf.Flags) + } + } + } + return &KeyFlagsCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + // --------------------------------------------------------------------------------------------------- type ClusterLink struct { @@ -5001,8 +6416,9 @@ var _ Cmder = (*ClusterLinksCmd)(nil) func NewClusterLinksCmd(ctx context.Context, args ...interface{}) *ClusterLinksCmd { return &ClusterLinksCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeClusterLinks, }, } } @@ -5068,6 +6484,18 @@ func (cmd *ClusterLinksCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *ClusterLinksCmd) Clone() Cmder { + var val []ClusterLink + if cmd.val != nil { + val = make([]ClusterLink, len(cmd.val)) + copy(val, cmd.val) + } + return &ClusterLinksCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + // ------------------------------------------------------------------------------------------------------------------ type SlotRange struct { @@ -5103,8 +6531,9 @@ var _ Cmder = (*ClusterShardsCmd)(nil) func NewClusterShardsCmd(ctx context.Context, args ...interface{}) *ClusterShardsCmd { return &ClusterShardsCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeClusterShards, }, } } @@ -5218,6 +6647,28 @@ func (cmd *ClusterShardsCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *ClusterShardsCmd) Clone() Cmder { + var val []ClusterShard + if cmd.val != nil { + val = make([]ClusterShard, len(cmd.val)) + for i, shard := range cmd.val { + val[i] = ClusterShard{} + if shard.Slots != nil { + val[i].Slots = make([]SlotRange, len(shard.Slots)) + copy(val[i].Slots, shard.Slots) + } + if shard.Nodes != nil { + val[i].Nodes = make([]Node, len(shard.Nodes)) + copy(val[i].Nodes, shard.Nodes) + } + } + } + return &ClusterShardsCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + // ----------------------------------------- type RankScore struct { @@ -5236,8 +6687,9 @@ var _ Cmder = (*RankWithScoreCmd)(nil) func NewRankWithScoreCmd(ctx context.Context, args ...interface{}) *RankWithScoreCmd { return &RankWithScoreCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeRankWithScore, }, } } @@ -5278,6 +6730,13 @@ func (cmd *RankWithScoreCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *RankWithScoreCmd) Clone() Cmder { + return &RankWithScoreCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: cmd.val, // RankScore is a simple struct, can be copied directly + } +} + // -------------------------------------------------------------------------------------------------- // ClientFlags is redis-server client flags, copy from redis/src/server.h (redis 7.0) @@ -5387,8 +6846,9 @@ var _ Cmder = (*ClientInfoCmd)(nil) func NewClientInfoCmd(ctx context.Context, args ...interface{}) *ClientInfoCmd { return &ClientInfoCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeClientInfo, }, } } @@ -5565,6 +7025,50 @@ func parseClientInfo(txt string) (info *ClientInfo, err error) { return info, nil } +func (cmd *ClientInfoCmd) Clone() Cmder { + var val *ClientInfo + if cmd.val != nil { + val = &ClientInfo{ + ID: cmd.val.ID, + Addr: cmd.val.Addr, + LAddr: cmd.val.LAddr, + FD: cmd.val.FD, + Name: cmd.val.Name, + Age: cmd.val.Age, + Idle: cmd.val.Idle, + Flags: cmd.val.Flags, + DB: cmd.val.DB, + Sub: cmd.val.Sub, + PSub: cmd.val.PSub, + SSub: cmd.val.SSub, + Multi: cmd.val.Multi, + Watch: cmd.val.Watch, + QueryBuf: cmd.val.QueryBuf, + QueryBufFree: cmd.val.QueryBufFree, + ArgvMem: cmd.val.ArgvMem, + MultiMem: cmd.val.MultiMem, + BufferSize: cmd.val.BufferSize, + BufferPeak: cmd.val.BufferPeak, + OutputBufferLength: cmd.val.OutputBufferLength, + OutputListLength: cmd.val.OutputListLength, + OutputMemory: cmd.val.OutputMemory, + TotalMemory: cmd.val.TotalMemory, + IoThread: cmd.val.IoThread, + Events: cmd.val.Events, + LastCmd: cmd.val.LastCmd, + User: cmd.val.User, + Redir: cmd.val.Redir, + Resp: cmd.val.Resp, + LibName: cmd.val.LibName, + LibVer: cmd.val.LibVer, + } + } + return &ClientInfoCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + // ------------------------------------------- type ACLLogEntry struct { @@ -5591,8 +7095,9 @@ var _ Cmder = (*ACLLogCmd)(nil) func NewACLLogCmd(ctx context.Context, args ...interface{}) *ACLLogCmd { return &ACLLogCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeACLLog, }, } } @@ -5674,6 +7179,69 @@ func (cmd *ACLLogCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *ACLLogCmd) Clone() Cmder { + var val []*ACLLogEntry + if cmd.val != nil { + val = make([]*ACLLogEntry, len(cmd.val)) + for i, entry := range cmd.val { + if entry != nil { + val[i] = &ACLLogEntry{ + Count: entry.Count, + Reason: entry.Reason, + Context: entry.Context, + Object: entry.Object, + Username: entry.Username, + AgeSeconds: entry.AgeSeconds, + EntryID: entry.EntryID, + TimestampCreated: entry.TimestampCreated, + TimestampLastUpdated: entry.TimestampLastUpdated, + } + // Clone ClientInfo if present + if entry.ClientInfo != nil { + val[i].ClientInfo = &ClientInfo{ + ID: entry.ClientInfo.ID, + Addr: entry.ClientInfo.Addr, + LAddr: entry.ClientInfo.LAddr, + FD: entry.ClientInfo.FD, + Name: entry.ClientInfo.Name, + Age: entry.ClientInfo.Age, + Idle: entry.ClientInfo.Idle, + Flags: entry.ClientInfo.Flags, + DB: entry.ClientInfo.DB, + Sub: entry.ClientInfo.Sub, + PSub: entry.ClientInfo.PSub, + SSub: entry.ClientInfo.SSub, + Multi: entry.ClientInfo.Multi, + Watch: entry.ClientInfo.Watch, + QueryBuf: entry.ClientInfo.QueryBuf, + QueryBufFree: entry.ClientInfo.QueryBufFree, + ArgvMem: entry.ClientInfo.ArgvMem, + MultiMem: entry.ClientInfo.MultiMem, + BufferSize: entry.ClientInfo.BufferSize, + BufferPeak: entry.ClientInfo.BufferPeak, + OutputBufferLength: entry.ClientInfo.OutputBufferLength, + OutputListLength: entry.ClientInfo.OutputListLength, + OutputMemory: entry.ClientInfo.OutputMemory, + TotalMemory: entry.ClientInfo.TotalMemory, + IoThread: entry.ClientInfo.IoThread, + Events: entry.ClientInfo.Events, + LastCmd: entry.ClientInfo.LastCmd, + User: entry.ClientInfo.User, + Redir: entry.ClientInfo.Redir, + Resp: entry.ClientInfo.Resp, + LibName: entry.ClientInfo.LibName, + LibVer: entry.ClientInfo.LibVer, + } + } + } + } + } + return &ACLLogCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + // LibraryInfo holds the library info. type LibraryInfo struct { LibName *string @@ -5702,8 +7270,9 @@ var _ Cmder = (*InfoCmd)(nil) func NewInfoCmd(ctx context.Context, args ...interface{}) *InfoCmd { return &InfoCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeInfo, }, } } @@ -5769,6 +7338,25 @@ func (cmd *InfoCmd) Item(section, key string) string { } } +func (cmd *InfoCmd) Clone() Cmder { + var val map[string]map[string]string + if cmd.val != nil { + val = make(map[string]map[string]string, len(cmd.val)) + for section, sectionMap := range cmd.val { + if sectionMap != nil { + val[section] = make(map[string]string, len(sectionMap)) + for k, v := range sectionMap { + val[section][k] = v + } + } + } + } + return &InfoCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + type MonitorStatus int const ( @@ -5787,8 +7375,9 @@ type MonitorCmd struct { func newMonitorCmd(ctx context.Context, ch chan string) *MonitorCmd { return &MonitorCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: []interface{}{"monitor"}, + ctx: ctx, + args: []interface{}{"monitor"}, + cmdType: CmdTypeMonitor, }, ch: ch, status: monitorStatusIdle, @@ -5907,5 +7496,532 @@ func (cmd *VectorScoreSliceCmd) readReply(rd *proto.Reader) error { } cmd.val[i].Score = score } + return nil } + +func (cmd *VectorScoreSliceCmd) Clone() Cmder { + return &VectorScoreSliceCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: cmd.val, + } +} + +func (cmd *MonitorCmd) Clone() Cmder { + // MonitorCmd cannot be safely cloned due to channels and goroutines + // Return a new MonitorCmd with the same channel + return newMonitorCmd(cmd.ctx, cmd.ch) +} + +// ExtractCommandValue extracts the value from a command result using the fast enum-based approach +func ExtractCommandValue(cmd interface{}) (interface{}, error) { + // First try to get the command type using the interface + if cmdTypeGetter, ok := cmd.(CmdTypeGetter); ok { + cmdType := cmdTypeGetter.GetCmdType() + + // Use fast type-based extraction + switch cmdType { + case CmdTypeGeneric: + if genericCmd, ok := cmd.(interface { + Val() interface{} + Err() error + }); ok { + return genericCmd.Val(), genericCmd.Err() + } + case CmdTypeString: + if stringCmd, ok := cmd.(interface { + Val() string + Err() error + }); ok { + return stringCmd.Val(), stringCmd.Err() + } + case CmdTypeInt: + if intCmd, ok := cmd.(interface { + Val() int64 + Err() error + }); ok { + return intCmd.Val(), intCmd.Err() + } + case CmdTypeBool: + if boolCmd, ok := cmd.(interface { + Val() bool + Err() error + }); ok { + return boolCmd.Val(), boolCmd.Err() + } + case CmdTypeFloat: + if floatCmd, ok := cmd.(interface { + Val() float64 + Err() error + }); ok { + return floatCmd.Val(), floatCmd.Err() + } + case CmdTypeStatus: + if statusCmd, ok := cmd.(interface { + Val() string + Err() error + }); ok { + return statusCmd.Val(), statusCmd.Err() + } + case CmdTypeDuration: + if durationCmd, ok := cmd.(interface { + Val() time.Duration + Err() error + }); ok { + return durationCmd.Val(), durationCmd.Err() + } + case CmdTypeTime: + if timeCmd, ok := cmd.(interface { + Val() time.Time + Err() error + }); ok { + return timeCmd.Val(), timeCmd.Err() + } + case CmdTypeStringStructMap: + if structMapCmd, ok := cmd.(interface { + Val() map[string]struct{} + Err() error + }); ok { + return structMapCmd.Val(), structMapCmd.Err() + } + case CmdTypeXMessageSlice: + if xMessageSliceCmd, ok := cmd.(interface { + Val() []XMessage + Err() error + }); ok { + return xMessageSliceCmd.Val(), xMessageSliceCmd.Err() + } + case CmdTypeXStreamSlice: + if xStreamSliceCmd, ok := cmd.(interface { + Val() []XStream + Err() error + }); ok { + return xStreamSliceCmd.Val(), xStreamSliceCmd.Err() + } + case CmdTypeXPending: + if xPendingCmd, ok := cmd.(interface { + Val() *XPending + Err() error + }); ok { + return xPendingCmd.Val(), xPendingCmd.Err() + } + case CmdTypeXPendingExt: + if xPendingExtCmd, ok := cmd.(interface { + Val() []XPendingExt + Err() error + }); ok { + return xPendingExtCmd.Val(), xPendingExtCmd.Err() + } + case CmdTypeXAutoClaim: + if xAutoClaimCmd, ok := cmd.(interface { + Val() ([]XMessage, string) + Err() error + }); ok { + messages, start := xAutoClaimCmd.Val() + return CmdTypeXAutoClaimValue{messages: messages, start: start}, xAutoClaimCmd.Err() + } + case CmdTypeXAutoClaimJustID: + if xAutoClaimJustIDCmd, ok := cmd.(interface { + Val() ([]string, string) + Err() error + }); ok { + ids, start := xAutoClaimJustIDCmd.Val() + return CmdTypeXAutoClaimJustIDValue{ids: ids, start: start}, xAutoClaimJustIDCmd.Err() + } + case CmdTypeXInfoConsumers: + if xInfoConsumersCmd, ok := cmd.(interface { + Val() []XInfoConsumer + Err() error + }); ok { + return xInfoConsumersCmd.Val(), xInfoConsumersCmd.Err() + } + case CmdTypeXInfoGroups: + if xInfoGroupsCmd, ok := cmd.(interface { + Val() []XInfoGroup + Err() error + }); ok { + return xInfoGroupsCmd.Val(), xInfoGroupsCmd.Err() + } + case CmdTypeXInfoStream: + if xInfoStreamCmd, ok := cmd.(interface { + Val() *XInfoStream + Err() error + }); ok { + return xInfoStreamCmd.Val(), xInfoStreamCmd.Err() + } + case CmdTypeXInfoStreamFull: + if xInfoStreamFullCmd, ok := cmd.(interface { + Val() *XInfoStreamFull + Err() error + }); ok { + return xInfoStreamFullCmd.Val(), xInfoStreamFullCmd.Err() + } + case CmdTypeZSlice: + if zSliceCmd, ok := cmd.(interface { + Val() []Z + Err() error + }); ok { + return zSliceCmd.Val(), zSliceCmd.Err() + } + case CmdTypeZWithKey: + if zWithKeyCmd, ok := cmd.(interface { + Val() *ZWithKey + Err() error + }); ok { + return zWithKeyCmd.Val(), zWithKeyCmd.Err() + } + case CmdTypeScan: + if scanCmd, ok := cmd.(interface { + Val() ([]string, uint64) + Err() error + }); ok { + keys, cursor := scanCmd.Val() + return CmdTypeScanValue{keys: keys, cursor: cursor}, scanCmd.Err() + } + case CmdTypeClusterSlots: + if clusterSlotsCmd, ok := cmd.(interface { + Val() []ClusterSlot + Err() error + }); ok { + return clusterSlotsCmd.Val(), clusterSlotsCmd.Err() + } + case CmdTypeGeoLocation: + if geoLocationCmd, ok := cmd.(interface { + Val() []GeoLocation + Err() error + }); ok { + return geoLocationCmd.Val(), geoLocationCmd.Err() + } + case CmdTypeGeoSearchLocation: + if geoSearchLocationCmd, ok := cmd.(interface { + Val() []GeoLocation + Err() error + }); ok { + return geoSearchLocationCmd.Val(), geoSearchLocationCmd.Err() + } + case CmdTypeGeoPos: + if geoPosCmd, ok := cmd.(interface { + Val() []*GeoPos + Err() error + }); ok { + return geoPosCmd.Val(), geoPosCmd.Err() + } + case CmdTypeCommandsInfo: + if commandsInfoCmd, ok := cmd.(interface { + Val() map[string]*CommandInfo + Err() error + }); ok { + return commandsInfoCmd.Val(), commandsInfoCmd.Err() + } + case CmdTypeSlowLog: + if slowLogCmd, ok := cmd.(interface { + Val() []SlowLog + Err() error + }); ok { + return slowLogCmd.Val(), slowLogCmd.Err() + } + case CmdTypeHotKeys: + if hotKeysCmd, ok := cmd.(interface { + Val() *HotKeysResult + Err() error + }); ok { + return hotKeysCmd.Val(), hotKeysCmd.Err() + } + case CmdTypeKeyValues: + if keyValuesCmd, ok := cmd.(interface { + Val() (string, []string) + Err() error + }); ok { + key, values := keyValuesCmd.Val() + return CmdTypeKeyValuesValue{key: key, values: values}, keyValuesCmd.Err() + } + case CmdTypeZSliceWithKey: + if zSliceWithKeyCmd, ok := cmd.(interface { + Val() (string, []Z) + Err() error + }); ok { + key, zSlice := zSliceWithKeyCmd.Val() + return CmdTypeZSliceWithKeyValue{key: key, zSlice: zSlice}, zSliceWithKeyCmd.Err() + } + case CmdTypeFunctionList: + if functionListCmd, ok := cmd.(interface { + Val() []Library + Err() error + }); ok { + return functionListCmd.Val(), functionListCmd.Err() + } + case CmdTypeFunctionStats: + if functionStatsCmd, ok := cmd.(interface { + Val() FunctionStats + Err() error + }); ok { + return functionStatsCmd.Val(), functionStatsCmd.Err() + } + case CmdTypeLCS: + if lcsCmd, ok := cmd.(interface { + Val() *LCSMatch + Err() error + }); ok { + return lcsCmd.Val(), lcsCmd.Err() + } + case CmdTypeKeyFlags: + if keyFlagsCmd, ok := cmd.(interface { + Val() []KeyFlags + Err() error + }); ok { + return keyFlagsCmd.Val(), keyFlagsCmd.Err() + } + case CmdTypeClusterLinks: + if clusterLinksCmd, ok := cmd.(interface { + Val() []ClusterLink + Err() error + }); ok { + return clusterLinksCmd.Val(), clusterLinksCmd.Err() + } + case CmdTypeClusterShards: + if clusterShardsCmd, ok := cmd.(interface { + Val() []ClusterShard + Err() error + }); ok { + return clusterShardsCmd.Val(), clusterShardsCmd.Err() + } + case CmdTypeRankWithScore: + if rankWithScoreCmd, ok := cmd.(interface { + Val() RankScore + Err() error + }); ok { + return rankWithScoreCmd.Val(), rankWithScoreCmd.Err() + } + case CmdTypeClientInfo: + if clientInfoCmd, ok := cmd.(interface { + Val() *ClientInfo + Err() error + }); ok { + return clientInfoCmd.Val(), clientInfoCmd.Err() + } + case CmdTypeACLLog: + if aclLogCmd, ok := cmd.(interface { + Val() []*ACLLogEntry + Err() error + }); ok { + return aclLogCmd.Val(), aclLogCmd.Err() + } + case CmdTypeInfo: + if infoCmd, ok := cmd.(interface { + Val() string + Err() error + }); ok { + return infoCmd.Val(), infoCmd.Err() + } + case CmdTypeMonitor: + if monitorCmd, ok := cmd.(interface { + Val() string + Err() error + }); ok { + return monitorCmd.Val(), monitorCmd.Err() + } + case CmdTypeJSON: + if jsonCmd, ok := cmd.(interface { + Val() string + Err() error + }); ok { + return jsonCmd.Val(), jsonCmd.Err() + } + case CmdTypeJSONSlice: + if jsonSliceCmd, ok := cmd.(interface { + Val() []interface{} + Err() error + }); ok { + return jsonSliceCmd.Val(), jsonSliceCmd.Err() + } + case CmdTypeIntPointerSlice: + if intPointerSliceCmd, ok := cmd.(interface { + Val() []*int64 + Err() error + }); ok { + return intPointerSliceCmd.Val(), intPointerSliceCmd.Err() + } + case CmdTypeScanDump: + if scanDumpCmd, ok := cmd.(interface { + Val() ScanDump + Err() error + }); ok { + return scanDumpCmd.Val(), scanDumpCmd.Err() + } + case CmdTypeBFInfo: + if bfInfoCmd, ok := cmd.(interface { + Val() BFInfo + Err() error + }); ok { + return bfInfoCmd.Val(), bfInfoCmd.Err() + } + case CmdTypeCFInfo: + if cfInfoCmd, ok := cmd.(interface { + Val() CFInfo + Err() error + }); ok { + return cfInfoCmd.Val(), cfInfoCmd.Err() + } + case CmdTypeCMSInfo: + if cmsInfoCmd, ok := cmd.(interface { + Val() CMSInfo + Err() error + }); ok { + return cmsInfoCmd.Val(), cmsInfoCmd.Err() + } + case CmdTypeTopKInfo: + if topKInfoCmd, ok := cmd.(interface { + Val() TopKInfo + Err() error + }); ok { + return topKInfoCmd.Val(), topKInfoCmd.Err() + } + case CmdTypeTDigestInfo: + if tDigestInfoCmd, ok := cmd.(interface { + Val() TDigestInfo + Err() error + }); ok { + return tDigestInfoCmd.Val(), tDigestInfoCmd.Err() + } + case CmdTypeFTSearch: + if ftSearchCmd, ok := cmd.(interface { + Val() FTSearchResult + Err() error + }); ok { + return ftSearchCmd.Val(), ftSearchCmd.Err() + } + case CmdTypeFTInfo: + if ftInfoCmd, ok := cmd.(interface { + Val() FTInfoResult + Err() error + }); ok { + return ftInfoCmd.Val(), ftInfoCmd.Err() + } + case CmdTypeFTSpellCheck: + if ftSpellCheckCmd, ok := cmd.(interface { + Val() []SpellCheckResult + Err() error + }); ok { + return ftSpellCheckCmd.Val(), ftSpellCheckCmd.Err() + } + case CmdTypeFTSynDump: + if ftSynDumpCmd, ok := cmd.(interface { + Val() []FTSynDumpResult + Err() error + }); ok { + return ftSynDumpCmd.Val(), ftSynDumpCmd.Err() + } + case CmdTypeAggregate: + if aggregateCmd, ok := cmd.(interface { + Val() *FTAggregateResult + Err() error + }); ok { + return aggregateCmd.Val(), aggregateCmd.Err() + } + case CmdTypeTSTimestampValue: + if tsTimestampValueCmd, ok := cmd.(interface { + Val() TSTimestampValue + Err() error + }); ok { + return tsTimestampValueCmd.Val(), tsTimestampValueCmd.Err() + } + case CmdTypeTSTimestampValueSlice: + if tsTimestampValueSliceCmd, ok := cmd.(interface { + Val() []TSTimestampValue + Err() error + }); ok { + return tsTimestampValueSliceCmd.Val(), tsTimestampValueSliceCmd.Err() + } + case CmdTypeStringSlice: + if stringSliceCmd, ok := cmd.(interface { + Val() []string + Err() error + }); ok { + return stringSliceCmd.Val(), stringSliceCmd.Err() + } + case CmdTypeIntSlice: + if intSliceCmd, ok := cmd.(interface { + Val() []int64 + Err() error + }); ok { + return intSliceCmd.Val(), intSliceCmd.Err() + } + case CmdTypeBoolSlice: + if boolSliceCmd, ok := cmd.(interface { + Val() []bool + Err() error + }); ok { + return boolSliceCmd.Val(), boolSliceCmd.Err() + } + case CmdTypeFloatSlice: + if floatSliceCmd, ok := cmd.(interface { + Val() []float64 + Err() error + }); ok { + return floatSliceCmd.Val(), floatSliceCmd.Err() + } + case CmdTypeSlice: + if sliceCmd, ok := cmd.(interface { + Val() []interface{} + Err() error + }); ok { + return sliceCmd.Val(), sliceCmd.Err() + } + case CmdTypeKeyValueSlice: + if keyValueSliceCmd, ok := cmd.(interface { + Val() []KeyValue + Err() error + }); ok { + return keyValueSliceCmd.Val(), keyValueSliceCmd.Err() + } + case CmdTypeMapStringString: + if mapCmd, ok := cmd.(interface { + Val() map[string]string + Err() error + }); ok { + return mapCmd.Val(), mapCmd.Err() + } + case CmdTypeMapStringInt: + if mapCmd, ok := cmd.(interface { + Val() map[string]int64 + Err() error + }); ok { + return mapCmd.Val(), mapCmd.Err() + } + case CmdTypeMapStringInterfaceSlice: + if mapCmd, ok := cmd.(interface { + Val() []map[string]interface{} + Err() error + }); ok { + return mapCmd.Val(), mapCmd.Err() + } + case CmdTypeMapStringInterface: + if mapCmd, ok := cmd.(interface { + Val() map[string]interface{} + Err() error + }); ok { + return mapCmd.Val(), mapCmd.Err() + } + case CmdTypeMapStringStringSlice: + if mapCmd, ok := cmd.(interface { + Val() []map[string]string + Err() error + }); ok { + return mapCmd.Val(), mapCmd.Err() + } + case CmdTypeMapMapStringInterface: + if mapCmd, ok := cmd.(interface { + Val() map[string]interface{} + Err() error + }); ok { + return mapCmd.Val(), mapCmd.Err() + } + default: + // For unknown command types, return nil + return nil, nil + } + } + + // If we can't get the command type, return nil + return nil, nil +} diff --git a/vendor/github.com/redis/go-redis/v9/command_policy_resolver.go b/vendor/github.com/redis/go-redis/v9/command_policy_resolver.go new file mode 100644 index 00000000..da8c6d31 --- /dev/null +++ b/vendor/github.com/redis/go-redis/v9/command_policy_resolver.go @@ -0,0 +1,209 @@ +package redis + +import ( + "context" + "strings" + + "github.com/redis/go-redis/v9/internal/routing" +) + +type ( + module = string + commandName = string +) + +var defaultPolicies = map[module]map[commandName]*routing.CommandPolicy{ + "ft": { + "create": { + Request: routing.ReqDefault, + Response: routing.RespDefaultKeyless, + }, + "search": { + Request: routing.ReqDefault, + Response: routing.RespDefaultKeyless, + Tips: map[string]string{ + routing.ReadOnlyCMD: "", + }, + }, + "aggregate": { + Request: routing.ReqDefault, + Response: routing.RespDefaultKeyless, + Tips: map[string]string{ + routing.ReadOnlyCMD: "", + }, + }, + "dictadd": { + Request: routing.ReqDefault, + Response: routing.RespDefaultKeyless, + }, + "dictdump": { + Request: routing.ReqDefault, + Response: routing.RespDefaultKeyless, + Tips: map[string]string{ + routing.ReadOnlyCMD: "", + }, + }, + "dictdel": { + Request: routing.ReqDefault, + Response: routing.RespDefaultKeyless, + }, + "suglen": { + Request: routing.ReqDefault, + Response: routing.RespDefaultHashSlot, + Tips: map[string]string{ + routing.ReadOnlyCMD: "", + }, + }, + "cursor": { + Request: routing.ReqSpecial, + Response: routing.RespDefaultKeyless, + Tips: map[string]string{ + routing.ReadOnlyCMD: "", + }, + }, + "sugadd": { + Request: routing.ReqDefault, + Response: routing.RespDefaultHashSlot, + }, + "sugget": { + Request: routing.ReqDefault, + Response: routing.RespDefaultHashSlot, + Tips: map[string]string{ + routing.ReadOnlyCMD: "", + }, + }, + "sugdel": { + Request: routing.ReqDefault, + Response: routing.RespDefaultHashSlot, + }, + "spellcheck": { + Request: routing.ReqDefault, + Response: routing.RespDefaultKeyless, + Tips: map[string]string{ + routing.ReadOnlyCMD: "", + }, + }, + "explain": { + Request: routing.ReqDefault, + Response: routing.RespDefaultKeyless, + Tips: map[string]string{ + routing.ReadOnlyCMD: "", + }, + }, + "explaincli": { + Request: routing.ReqDefault, + Response: routing.RespDefaultKeyless, + Tips: map[string]string{ + routing.ReadOnlyCMD: "", + }, + }, + "aliasadd": { + Request: routing.ReqDefault, + Response: routing.RespDefaultKeyless, + }, + "aliasupdate": { + Request: routing.ReqDefault, + Response: routing.RespDefaultKeyless, + }, + "aliasdel": { + Request: routing.ReqDefault, + Response: routing.RespDefaultKeyless, + }, + "info": { + Request: routing.ReqDefault, + Response: routing.RespDefaultKeyless, + Tips: map[string]string{ + routing.ReadOnlyCMD: "", + }, + }, + "tagvals": { + Request: routing.ReqDefault, + Response: routing.RespDefaultKeyless, + Tips: map[string]string{ + routing.ReadOnlyCMD: "", + }, + }, + "syndump": { + Request: routing.ReqDefault, + Response: routing.RespDefaultKeyless, + Tips: map[string]string{ + routing.ReadOnlyCMD: "", + }, + }, + "synupdate": { + Request: routing.ReqDefault, + Response: routing.RespDefaultKeyless, + }, + "profile": { + Request: routing.ReqDefault, + Response: routing.RespDefaultKeyless, + Tips: map[string]string{ + routing.ReadOnlyCMD: "", + }, + }, + "alter": { + Request: routing.ReqDefault, + Response: routing.RespDefaultKeyless, + }, + "dropindex": { + Request: routing.ReqDefault, + Response: routing.RespDefaultKeyless, + }, + "drop": { + Request: routing.ReqDefault, + Response: routing.RespDefaultKeyless, + }, + }, +} + +type CommandInfoResolveFunc func(ctx context.Context, cmd Cmder) *routing.CommandPolicy + +type commandInfoResolver struct { + resolveFunc CommandInfoResolveFunc + fallBackResolver *commandInfoResolver +} + +func NewCommandInfoResolver(resolveFunc CommandInfoResolveFunc) *commandInfoResolver { + return &commandInfoResolver{ + resolveFunc: resolveFunc, + } +} + +func NewDefaultCommandPolicyResolver() *commandInfoResolver { + return NewCommandInfoResolver(func(ctx context.Context, cmd Cmder) *routing.CommandPolicy { + module := "core" + command := cmd.Name() + cmdParts := strings.Split(command, ".") + if len(cmdParts) == 2 { + module = cmdParts[0] + command = cmdParts[1] + } + + if policy, ok := defaultPolicies[module][command]; ok { + return policy + } + + return nil + }) +} + +func (r *commandInfoResolver) GetCommandPolicy(ctx context.Context, cmd Cmder) *routing.CommandPolicy { + if r.resolveFunc == nil { + return nil + } + + policy := r.resolveFunc(ctx, cmd) + if policy != nil { + return policy + } + + if r.fallBackResolver != nil { + return r.fallBackResolver.GetCommandPolicy(ctx, cmd) + } + + return nil +} + +func (r *commandInfoResolver) SetFallbackResolver(fallbackResolver *commandInfoResolver) { + r.fallBackResolver = fallbackResolver +} diff --git a/vendor/github.com/redis/go-redis/v9/commands.go b/vendor/github.com/redis/go-redis/v9/commands.go index daee5505..219fe464 100644 --- a/vendor/github.com/redis/go-redis/v9/commands.go +++ b/vendor/github.com/redis/go-redis/v9/commands.go @@ -55,6 +55,11 @@ func appendArgs(dst, src []interface{}) []interface{} { return appendArg(dst, src[0]) } + if cap(dst) < len(dst)+len(src) { + newDst := make([]interface{}, len(dst), len(dst)+len(src)) + copy(newDst, dst) + dst = newDst + } dst = append(dst, src...) return dst } @@ -443,6 +448,9 @@ func (c cmdable) Do(ctx context.Context, args ...interface{}) *Cmd { return cmd } +// Quit closes the connection. +// +// Deprecated: Just close the connection instead as of Redis 7.2.0. func (c cmdable) Quit(_ context.Context) *StatusCmd { panic("not implemented") } @@ -665,6 +673,9 @@ func (c cmdable) ShutdownNoSave(ctx context.Context) *StatusCmd { return c.shutdown(ctx, "nosave") } +// SlaveOf sets a Redis server as a replica of another, or promotes it to being a master. +// +// Deprecated: Use ReplicaOf instead as of Redis 5.0.0. func (c cmdable) SlaveOf(ctx context.Context, host, port string) *StatusCmd { cmd := NewStatusCmd(ctx, "slaveof", host, port) _ = c(ctx, cmd) diff --git a/vendor/github.com/redis/go-redis/v9/docker-compose.yml b/vendor/github.com/redis/go-redis/v9/docker-compose.yml index 5ffedb0a..8299fd9d 100644 --- a/vendor/github.com/redis/go-redis/v9/docker-compose.yml +++ b/vendor/github.com/redis/go-redis/v9/docker-compose.yml @@ -1,12 +1,16 @@ --- +x-default-image: &default-image ${CLIENT_LIBS_TEST_IMAGE:-redislabs/client-libs-test:8.6.0} + services: redis: - image: ${CLIENT_LIBS_TEST_IMAGE:-redislabs/client-libs-test:8.4.0} + image: *default-image platform: linux/amd64 container_name: redis-standalone environment: - TLS_ENABLED=yes + - TLS_CLIENT_CNS=testcertuser + - TLS_AUTH_CLIENTS_USER=CN - REDIS_CLUSTER=no - PORT=6379 - TLS_PORT=6666 @@ -21,9 +25,10 @@ services: - sentinel - all-stack - all + - e2e osscluster: - image: ${CLIENT_LIBS_TEST_IMAGE:-redislabs/client-libs-test:8.4.0} + image: *default-image platform: linux/amd64 container_name: redis-osscluster environment: @@ -39,14 +44,77 @@ services: - all-stack - all + cae-resp-proxy: + image: redislabs/client-resp-proxy:latest + container_name: cae-resp-proxy + environment: + - TARGET_HOST=redis + - TARGET_PORT=6379 + - LISTEN_PORT=17000,17001,17002,17003 # 4 proxy nodes: initially show 3, swap in 4th during SMIGRATED + - LISTEN_HOST=0.0.0.0 + - API_PORT=3000 + - DEFAULT_INTERCEPTORS=cluster,hitless + ports: + - "17000:17000" # Proxy node 1 (host:container) + - "17001:17001" # Proxy node 2 (host:container) + - "17002:17002" # Proxy node 3 (host:container) + - "17003:17003" # Proxy node 4 (host:container) - hidden initially, swapped in during SMIGRATED + - "18100:3000" # HTTP API port (host:container) + depends_on: + - redis + profiles: + - e2e + - all + + proxy-fault-injector: + build: + context: . + dockerfile: maintnotifications/e2e/cmd/proxy-fi-server/Dockerfile + container_name: proxy-fault-injector + ports: + - "15000:5000" # Fault injector API port (host:container) + depends_on: + - cae-resp-proxy + environment: + - PROXY_API_URL=http://cae-resp-proxy:3000 + profiles: + - e2e + - all + + osscluster-tls: + image: *default-image + platform: linux/amd64 + container_name: redis-osscluster-tls + environment: + - NODES=6 + - PORT=6430 + - TLS_PORT=5430 + - TLS_ENABLED=yes + - TLS_CLIENT_CNS=testcertuser + - TLS_AUTH_CLIENTS_USER=CN + - REDIS_CLUSTER=yes + - REPLICAS=1 + command: "--tls-auth-clients optional --cluster-announce-ip 127.0.0.1" + ports: + - "6430-6435:6430-6435" # Regular ports + - "5430-5435:5430-5435" # TLS ports (set via TLS_PORT env var) + - "16430-16435:16430-16435" # Cluster bus ports (PORT + 10000) + volumes: + - "./dockers/osscluster-tls:/redis/work" + profiles: + - cluster-tls + - all + sentinel-cluster: - image: ${CLIENT_LIBS_TEST_IMAGE:-redislabs/client-libs-test:8.4.0} + image: *default-image platform: linux/amd64 container_name: redis-sentinel-cluster network_mode: "host" environment: - NODES=3 - TLS_ENABLED=yes + - TLS_CLIENT_CNS=testcertuser + - TLS_AUTH_CLIENTS_USER=CN - REDIS_CLUSTER=no - PORT=9121 command: ${REDIS_EXTRA_ARGS:---enable-debug-command yes --enable-module-command yes --tls-auth-clients optional --save ""} @@ -60,7 +128,7 @@ services: - all sentinel: - image: ${CLIENT_LIBS_TEST_IMAGE:-redislabs/client-libs-test:8.4.0} + image: *default-image platform: linux/amd64 container_name: redis-sentinel depends_on: @@ -84,12 +152,14 @@ services: - all ring-cluster: - image: ${CLIENT_LIBS_TEST_IMAGE:-redislabs/client-libs-test:8.4.0} + image: *default-image platform: linux/amd64 container_name: redis-ring-cluster environment: - NODES=3 - TLS_ENABLED=yes + - TLS_CLIENT_CNS=testcertuser + - TLS_AUTH_CLIENTS_USER=CN - REDIS_CLUSTER=no - PORT=6390 command: ${REDIS_EXTRA_ARGS:---enable-debug-command yes --enable-module-command yes --tls-auth-clients optional --save ""} diff --git a/vendor/github.com/redis/go-redis/v9/error.go b/vendor/github.com/redis/go-redis/v9/error.go index 12b5604d..d2462a49 100644 --- a/vendor/github.com/redis/go-redis/v9/error.go +++ b/vendor/github.com/redis/go-redis/v9/error.go @@ -124,6 +124,9 @@ func shouldRetry(err error, retryTimeout bool) bool { if proto.IsTryAgainError(err) { return true } + if proto.IsNoReplicasError(err) { + return true + } // Fallback to string checking for backward compatibility with plain errors s := err.Error() @@ -145,6 +148,9 @@ func shouldRetry(err error, retryTimeout bool) bool { if strings.HasPrefix(s, "MASTERDOWN ") { return true } + if strings.HasPrefix(s, "NOREPLICAS ") { + return true + } return false } @@ -342,6 +348,14 @@ func IsOOMError(err error) bool { return proto.IsOOMError(err) } +// IsNoReplicasError checks if an error is a Redis NOREPLICAS error, even if wrapped. +// NOREPLICAS errors occur when not enough replicas acknowledge a write operation. +// This typically happens with WAIT/WAITAOF commands or CLUSTER SETSLOT with synchronous +// replication when the required number of replicas cannot confirm the write within the timeout. +func IsNoReplicasError(err error) bool { + return proto.IsNoReplicasError(err) +} + //------------------------------------------------------------------------------ type timeoutError interface { diff --git a/vendor/github.com/redis/go-redis/v9/geo_commands.go b/vendor/github.com/redis/go-redis/v9/geo_commands.go index f047b98a..0f274289 100644 --- a/vendor/github.com/redis/go-redis/v9/geo_commands.go +++ b/vendor/github.com/redis/go-redis/v9/geo_commands.go @@ -33,7 +33,10 @@ func (c cmdable) GeoAdd(ctx context.Context, key string, geoLocation ...*GeoLoca return cmd } -// GeoRadius is a read-only GEORADIUS_RO command. +// GeoRadius queries a geospatial index for members within a distance from a coordinate. +// This is a read-only variant that does not support Store or StoreDist options. +// +// Deprecated: Use GeoSearch with BYRADIUS argument instead as of Redis 6.2.0. func (c cmdable) GeoRadius( ctx context.Context, key string, longitude, latitude float64, query *GeoRadiusQuery, ) *GeoLocationCmd { @@ -60,7 +63,10 @@ func (c cmdable) GeoRadiusStore( return cmd } -// GeoRadiusByMember is a read-only GEORADIUSBYMEMBER_RO command. +// GeoRadiusByMember queries a geospatial index for members within a distance from a member. +// This is a read-only variant that does not support Store or StoreDist options. +// +// Deprecated: Use GeoSearch with BYRADIUS and FROMMEMBER arguments instead as of Redis 6.2.0. func (c cmdable) GeoRadiusByMember( ctx context.Context, key, member string, query *GeoRadiusQuery, ) *GeoLocationCmd { diff --git a/vendor/github.com/redis/go-redis/v9/hotkeys_commands.go b/vendor/github.com/redis/go-redis/v9/hotkeys_commands.go new file mode 100644 index 00000000..024db3ff --- /dev/null +++ b/vendor/github.com/redis/go-redis/v9/hotkeys_commands.go @@ -0,0 +1,122 @@ +package redis + +import ( + "context" + "errors" + "strings" +) + +// HOTKEYS commands are only available on standalone *Client instances. +// They are NOT available on ClusterClient, Ring, or UniversalClient because +// HOTKEYS is a stateful command requiring session affinity - all operations +// (START, GET, STOP, RESET) must be sent to the same Redis node. +// +// If you are using UniversalClient and need HOTKEYS functionality, you must +// type assert to *Client first: +// +// if client, ok := universalClient.(*redis.Client); ok { +// result, err := client.HotKeysStart(ctx, args) +// // ... +// } + +// HotKeysMetric represents the metrics that can be tracked by the HOTKEYS command. +type HotKeysMetric string + +const ( + // HotKeysMetricCPU tracks CPU time spent on the key (in microseconds). + HotKeysMetricCPU HotKeysMetric = "CPU" + // HotKeysMetricNET tracks network bytes used by the key (ingress + egress + replication). + HotKeysMetricNET HotKeysMetric = "NET" +) + +// HotKeysStartArgs contains the arguments for the HOTKEYS START command. +// This command is only available on standalone clients due to its stateful nature +// requiring session affinity. It must NOT be used on cluster or pooled clients. +type HotKeysStartArgs struct { + // Metrics to track. At least one must be specified. + Metrics []HotKeysMetric + // Count is the number of top keys to report. + // Default: 10, Min: 10, Max: 64 + Count uint8 + // Duration is the auto-stop tracking after this many seconds. + // Default: 0 (no auto-stop) + Duration int64 + // Sample is the sample ratio - track keys with probability 1/sample. + // Default: 1 (track every key), Min: 1 + Sample int64 + // Slots specifies specific hash slots to track (0-16383). + // All specified slots must be hosted by the receiving node. + // If not specified, all slots are tracked. + Slots []uint16 +} + +// ErrHotKeysNoMetrics is returned when HotKeysStart is called without any metrics specified. +var ErrHotKeysNoMetrics = errors.New("redis: at least one metric must be specified for HOTKEYS START") + +// HotKeysStart starts collecting hotkeys data. +// At least one metric must be specified in args.Metrics. +// This command is only available on standalone clients. +func (c *Client) HotKeysStart(ctx context.Context, args *HotKeysStartArgs) *StatusCmd { + cmdArgs := make([]interface{}, 0, 16) + cmdArgs = append(cmdArgs, "hotkeys", "start") + + // Validate that at least one metric is specified + if len(args.Metrics) == 0 { + cmd := NewStatusCmd(ctx, cmdArgs...) + cmd.SetErr(ErrHotKeysNoMetrics) + return cmd + } + + cmdArgs = append(cmdArgs, "metrics", len(args.Metrics)) + for _, metric := range args.Metrics { + cmdArgs = append(cmdArgs, strings.ToLower(string(metric))) + } + + if args.Count > 0 { + cmdArgs = append(cmdArgs, "count", args.Count) + } + + if args.Duration > 0 { + cmdArgs = append(cmdArgs, "duration", args.Duration) + } + + if args.Sample > 0 { + cmdArgs = append(cmdArgs, "sample", args.Sample) + } + + if len(args.Slots) > 0 { + cmdArgs = append(cmdArgs, "slots", len(args.Slots)) + for _, slot := range args.Slots { + cmdArgs = append(cmdArgs, slot) + } + } + + cmd := NewStatusCmd(ctx, cmdArgs...) + _ = c.Process(ctx, cmd) + return cmd +} + +// HotKeysStop stops the ongoing hotkeys collection session. +// This command is only available on standalone clients. +func (c *Client) HotKeysStop(ctx context.Context) *StatusCmd { + cmd := NewStatusCmd(ctx, "hotkeys", "stop") + _ = c.Process(ctx, cmd) + return cmd +} + +// HotKeysReset discards the last hotkeys collection session results. +// Returns an error if tracking is currently active. +// This command is only available on standalone clients. +func (c *Client) HotKeysReset(ctx context.Context) *StatusCmd { + cmd := NewStatusCmd(ctx, "hotkeys", "reset") + _ = c.Process(ctx, cmd) + return cmd +} + +// HotKeysGet retrieves the results of the ongoing or last hotkeys collection session. +// This command is only available on standalone clients. +func (c *Client) HotKeysGet(ctx context.Context) *HotKeysCmd { + cmd := NewHotKeysCmd(ctx, "hotkeys", "get") + _ = c.Process(ctx, cmd) + return cmd +} diff --git a/vendor/github.com/redis/go-redis/v9/internal/interfaces/interfaces.go b/vendor/github.com/redis/go-redis/v9/internal/interfaces/interfaces.go index 17e2a185..8f856971 100644 --- a/vendor/github.com/redis/go-redis/v9/internal/interfaces/interfaces.go +++ b/vendor/github.com/redis/go-redis/v9/internal/interfaces/interfaces.go @@ -40,6 +40,11 @@ type OptionsInterface interface { // GetAddr returns the connection address. GetAddr() string + // GetNodeAddress returns the address of the Redis node as reported by the server. + // For cluster clients, this is the endpoint from CLUSTER SLOTS before any transformation. + // For standalone clients, this defaults to Addr. + GetNodeAddress() string + // IsTLSEnabled returns true if TLS is enabled. IsTLSEnabled() bool diff --git a/vendor/github.com/redis/go-redis/v9/internal/maintnotifications/logs/log_messages.go b/vendor/github.com/redis/go-redis/v9/internal/maintnotifications/logs/log_messages.go index 34cb1692..93e5bded 100644 --- a/vendor/github.com/redis/go-redis/v9/internal/maintnotifications/logs/log_messages.go +++ b/vendor/github.com/redis/go-redis/v9/internal/maintnotifications/logs/log_messages.go @@ -121,6 +121,9 @@ const ( UnrelaxedTimeoutMessage = "clearing relaxed timeout" ManagerNotInitializedMessage = "manager not initialized" FailedToMarkForHandoffMessage = "failed to mark connection for handoff" + InvalidSeqIDInSMigratingNotificationMessage = "invalid SeqID in SMIGRATING notification" + InvalidSeqIDInSMigratedNotificationMessage = "invalid SeqID in SMIGRATED notification" + TriggeringClusterStateReloadMessage = "triggering cluster state reload" // ======================================== // used in pool/conn @@ -288,19 +291,29 @@ func OperationNotTracked(connID uint64, seqID int64) string { // Connection pool functions func RemovingConnectionFromPool(connID uint64, reason error) string { - message := fmt.Sprintf("conn[%d] %s due to: %v", connID, RemovingConnectionFromPoolMessage, reason) - return appendJSONIfDebug(message, map[string]interface{}{ + metadata := map[string]interface{}{ "connID": connID, - "reason": reason.Error(), - }) + "reason": "unknown", // this will be overwritten if reason is not nil + } + if reason != nil { + metadata["reason"] = reason.Error() + } + + message := fmt.Sprintf("conn[%d] %s due to: %v", connID, RemovingConnectionFromPoolMessage, reason) + return appendJSONIfDebug(message, metadata) } func NoPoolProvidedCannotRemove(connID uint64, reason error) string { - message := fmt.Sprintf("conn[%d] %s due to: %v", connID, NoPoolProvidedMessageCannotRemoveMessage, reason) - return appendJSONIfDebug(message, map[string]interface{}{ + metadata := map[string]interface{}{ "connID": connID, - "reason": reason.Error(), - }) + "reason": "unknown", // this will be overwritten if reason is not nil + } + if reason != nil { + metadata["reason"] = reason.Error() + } + + message := fmt.Sprintf("conn[%d] %s due to: %v", connID, NoPoolProvidedMessageCannotRemoveMessage, reason) + return appendJSONIfDebug(message, metadata) } // Circuit breaker functions @@ -623,3 +636,28 @@ func ExtractDataFromLogMessage(logMessage string) map[string]interface{} { // If JSON parsing fails, return empty map return result } + +// Cluster notification functions +func InvalidSeqIDInSMigratingNotification(seqID interface{}) string { + message := fmt.Sprintf("%s: %v", InvalidSeqIDInSMigratingNotificationMessage, seqID) + return appendJSONIfDebug(message, map[string]interface{}{ + "seqID": fmt.Sprintf("%v", seqID), + }) +} + +func InvalidSeqIDInSMigratedNotification(seqID interface{}) string { + message := fmt.Sprintf("%s: %v", InvalidSeqIDInSMigratedNotificationMessage, seqID) + return appendJSONIfDebug(message, map[string]interface{}{ + "seqID": fmt.Sprintf("%v", seqID), + }) +} + +// TriggeringClusterStateReload logs when cluster state reload is triggered (deduplicated, once per seqID) +func TriggeringClusterStateReload(seqID int64, hostPort string, slotRanges []string) string { + message := fmt.Sprintf("%s seqID=%d host:port=%s slots=%v", TriggeringClusterStateReloadMessage, seqID, hostPort, slotRanges) + return appendJSONIfDebug(message, map[string]interface{}{ + "seqID": seqID, + "hostPort": hostPort, + "slotRanges": slotRanges, + }) +} diff --git a/vendor/github.com/redis/go-redis/v9/internal/otel/metrics.go b/vendor/github.com/redis/go-redis/v9/internal/otel/metrics.go new file mode 100644 index 00000000..a4840825 --- /dev/null +++ b/vendor/github.com/redis/go-redis/v9/internal/otel/metrics.go @@ -0,0 +1,279 @@ +package otel + +import ( + "context" + "crypto/rand" + "encoding/hex" + "sync" + "time" + + "github.com/redis/go-redis/v9/internal/pool" +) + +// generateUniqueID generates a short unique identifier for pool names. +func generateUniqueID() string { + b := make([]byte, 4) + if _, err := rand.Read(b); err != nil { + return "" + } + return hex.EncodeToString(b) +} + +// Cmder is a minimal interface for command information needed for metrics. +// This avoids circular dependencies with the main redis package. +type Cmder interface { + Name() string + FullName() string + Args() []interface{} + Err() error +} + +// Recorder is the interface for recording metrics. +type Recorder interface { + // RecordOperationDuration records the total operation duration (including all retries) + // dbIndex is the Redis database index (0-15) + RecordOperationDuration(ctx context.Context, duration time.Duration, cmd Cmder, attempts int, err error, cn *pool.Conn, dbIndex int) + + // RecordPipelineOperationDuration records the total pipeline/transaction duration. + // operationName should be "PIPELINE" for regular pipelines or "MULTI" for transactions. + // cmdCount is the number of commands in the pipeline. + // err is the error from the pipeline execution (can be nil). + // dbIndex is the Redis database index (0-15) + RecordPipelineOperationDuration(ctx context.Context, duration time.Duration, operationName string, cmdCount int, attempts int, err error, cn *pool.Conn, dbIndex int) + + // RecordConnectionCreateTime records the time it took to create a new connection + RecordConnectionCreateTime(ctx context.Context, duration time.Duration, cn *pool.Conn) + + // RecordConnectionRelaxedTimeout records when connection timeout is relaxed/unrelaxed + // delta: +1 for relaxed, -1 for unrelaxed + // poolName: name of the connection pool (e.g., "main", "pubsub") + // notificationType: the notification type that triggered the timeout relaxation (e.g., "MOVING") + RecordConnectionRelaxedTimeout(ctx context.Context, delta int, cn *pool.Conn, poolName, notificationType string) + + // RecordConnectionHandoff records when a connection is handed off to another node + // poolName: name of the connection pool (e.g., "main", "pubsub") + RecordConnectionHandoff(ctx context.Context, cn *pool.Conn, poolName string) + + // RecordError records client errors (ASK, MOVED, handshake failures, etc.) + // errorType: type of error (e.g., "ASK", "MOVED", "HANDSHAKE_FAILED") + // statusCode: Redis response status code if available (e.g., "MOVED", "ASK") + // isInternal: whether this is an internal error + // retryAttempts: number of retry attempts made + RecordError(ctx context.Context, errorType string, cn *pool.Conn, statusCode string, isInternal bool, retryAttempts int) + + // RecordMaintenanceNotification records when a maintenance notification is received + // notificationType: the type of notification (e.g., "MOVING", "MIGRATING", etc.) + RecordMaintenanceNotification(ctx context.Context, cn *pool.Conn, notificationType string) + + // RecordConnectionWaitTime records the time spent waiting for a connection from the pool + RecordConnectionWaitTime(ctx context.Context, duration time.Duration, cn *pool.Conn) + + // RecordConnectionClosed records when a connection is closed + // reason: reason for closing (e.g., "idle", "max_lifetime", "error", "pool_closed") + // err: the error that caused the close (nil for non-error closures) + RecordConnectionClosed(ctx context.Context, cn *pool.Conn, reason string, err error) + + // RecordPubSubMessage records a Pub/Sub message + // direction: "sent" or "received" + // channel: channel name (may be hidden for cardinality reduction) + // sharded: true for sharded pub/sub (SPUBLISH/SSUBSCRIBE) + RecordPubSubMessage(ctx context.Context, cn *pool.Conn, direction, channel string, sharded bool) + + // RecordStreamLag records the lag for stream consumer group processing + // lag: time difference between message creation and consumption + // streamName: name of the stream (may be hidden for cardinality reduction) + // consumerGroup: name of the consumer group + // consumerName: name of the consumer + RecordStreamLag(ctx context.Context, lag time.Duration, cn *pool.Conn, streamName, consumerGroup, consumerName string) +} + +type PubSubPooler interface { + Stats() *pool.PubSubStats +} + +type PoolRegistrar interface { + // RegisterPool is called when a new client is created with its connection pools. + // poolName: identifier for the pool (e.g., "main_abc123") + // pool: the connection pool + RegisterPool(poolName string, pool pool.Pooler) + // UnregisterPool is called when a client is closed to remove its pool from the registry. + // pool: the connection pool to unregister + UnregisterPool(pool pool.Pooler) + // RegisterPubSubPool is called when a new client is created with a PubSub pool. + // poolName: identifier for the pool (e.g., "main_abc123_pubsub") + // pool: the PubSub connection pool + RegisterPubSubPool(poolName string, pool PubSubPooler) + // UnregisterPubSubPool is called when a PubSub client is closed to remove its pool. + // pool: the PubSub connection pool to unregister + UnregisterPubSubPool(pool PubSubPooler) +} + +var ( + // recorderMu protects globalRecorder and operation duration callbacks + recorderMu sync.RWMutex + + // Global recorder instance (initialized by extra/redisotel-native) + globalRecorder Recorder = noopRecorder{} + + // Callbacks for operation duration metrics + operationDurationCallback func(ctx context.Context, duration time.Duration, cmd Cmder, attempts int, err error, cn *pool.Conn, dbIndex int) + pipelineOperationDurationCallback func(ctx context.Context, duration time.Duration, operationName string, cmdCount int, attempts int, err error, cn *pool.Conn, dbIndex int) +) + +// GetOperationDurationCallback returns the callback for operation duration. +func GetOperationDurationCallback() func(ctx context.Context, duration time.Duration, cmd Cmder, attempts int, err error, cn *pool.Conn, dbIndex int) { + recorderMu.RLock() + cb := operationDurationCallback + recorderMu.RUnlock() + return cb +} + +// GetPipelineOperationDurationCallback returns the callback for pipeline operation duration. +func GetPipelineOperationDurationCallback() func(ctx context.Context, duration time.Duration, operationName string, cmdCount int, attempts int, err error, cn *pool.Conn, dbIndex int) { + recorderMu.RLock() + cb := pipelineOperationDurationCallback + recorderMu.RUnlock() + return cb +} + +// getRecorder returns the current global recorder under a read lock. +func getRecorder() Recorder { + recorderMu.RLock() + r := globalRecorder + recorderMu.RUnlock() + return r +} + +// SetGlobalRecorder sets the global recorder (called by Init() in extra/redisotel-native) +func SetGlobalRecorder(r Recorder) { + recorderMu.Lock() + if r == nil { + globalRecorder = noopRecorder{} + operationDurationCallback = nil + pipelineOperationDurationCallback = nil + recorderMu.Unlock() + // Unregister all pool metric callbacks atomically + pool.SetAllMetricCallbacks(nil) + return + } + globalRecorder = r + + // Register operation duration callbacks + // These capture r directly since we want them to use the specific recorder + // that was set at this point in time + operationDurationCallback = func(ctx context.Context, duration time.Duration, cmd Cmder, attempts int, err error, cn *pool.Conn, dbIndex int) { + getRecorder().RecordOperationDuration(ctx, duration, cmd, attempts, err, cn, dbIndex) + } + pipelineOperationDurationCallback = func(ctx context.Context, duration time.Duration, operationName string, cmdCount int, attempts int, err error, cn *pool.Conn, dbIndex int) { + getRecorder().RecordPipelineOperationDuration(ctx, duration, operationName, cmdCount, attempts, err, cn, dbIndex) + } + recorderMu.Unlock() + + // Register all pool metric callbacks atomically + // These use getRecorder() to safely access the current recorder + pool.SetAllMetricCallbacks(&pool.MetricCallbacks{ + ConnectionCreateTime: func(ctx context.Context, duration time.Duration, cn *pool.Conn) { + getRecorder().RecordConnectionCreateTime(ctx, duration, cn) + }, + ConnectionRelaxedTimeout: func(ctx context.Context, delta int, cn *pool.Conn, poolName, notificationType string) { + getRecorder().RecordConnectionRelaxedTimeout(ctx, delta, cn, poolName, notificationType) + }, + ConnectionHandoff: func(ctx context.Context, cn *pool.Conn, poolName string) { + getRecorder().RecordConnectionHandoff(ctx, cn, poolName) + }, + Error: func(ctx context.Context, errorType string, cn *pool.Conn, statusCode string, isInternal bool, retryAttempts int) { + getRecorder().RecordError(ctx, errorType, cn, statusCode, isInternal, retryAttempts) + }, + MaintenanceNotification: func(ctx context.Context, cn *pool.Conn, notificationType string) { + getRecorder().RecordMaintenanceNotification(ctx, cn, notificationType) + }, + ConnectionWaitTime: func(ctx context.Context, duration time.Duration, cn *pool.Conn) { + getRecorder().RecordConnectionWaitTime(ctx, duration, cn) + }, + ConnectionClosed: func(ctx context.Context, cn *pool.Conn, reason string, err error) { + getRecorder().RecordConnectionClosed(ctx, cn, reason, err) + }, + }) +} + +// RecordOperationDuration records the total operation duration. +// dbIndex is the Redis database index (0-15). +func RecordOperationDuration(ctx context.Context, duration time.Duration, cmd Cmder, attempts int, err error, cn *pool.Conn, dbIndex int) { + getRecorder().RecordOperationDuration(ctx, duration, cmd, attempts, err, cn, dbIndex) +} + +// RecordPipelineOperationDuration records the total pipeline/transaction duration. +// This is called from redis.go after pipeline/transaction execution completes. +// operationName should be "PIPELINE" for regular pipelines or "MULTI" for transactions. +// err is the error from the pipeline execution (can be nil). +// dbIndex is the Redis database index (0-15). +func RecordPipelineOperationDuration(ctx context.Context, duration time.Duration, operationName string, cmdCount int, attempts int, err error, cn *pool.Conn, dbIndex int) { + getRecorder().RecordPipelineOperationDuration(ctx, duration, operationName, cmdCount, attempts, err, cn, dbIndex) +} + +// RecordConnectionCreateTime records the time it took to create a new connection. +func RecordConnectionCreateTime(ctx context.Context, duration time.Duration, cn *pool.Conn) { + getRecorder().RecordConnectionCreateTime(ctx, duration, cn) +} + +// RecordPubSubMessage records a Pub/Sub message sent or received. +func RecordPubSubMessage(ctx context.Context, cn *pool.Conn, direction, channel string, sharded bool) { + getRecorder().RecordPubSubMessage(ctx, cn, direction, channel, sharded) +} + +// RecordStreamLag records the lag between message creation and consumption in a stream. +func RecordStreamLag(ctx context.Context, lag time.Duration, cn *pool.Conn, streamName, consumerGroup, consumerName string) { + getRecorder().RecordStreamLag(ctx, lag, cn, streamName, consumerGroup, consumerName) +} + +type noopRecorder struct{} + +func (noopRecorder) RecordOperationDuration(context.Context, time.Duration, Cmder, int, error, *pool.Conn, int) { +} +func (noopRecorder) RecordPipelineOperationDuration(context.Context, time.Duration, string, int, int, error, *pool.Conn, int) { +} +func (noopRecorder) RecordConnectionCreateTime(context.Context, time.Duration, *pool.Conn) {} +func (noopRecorder) RecordConnectionRelaxedTimeout(context.Context, int, *pool.Conn, string, string) { +} +func (noopRecorder) RecordConnectionHandoff(context.Context, *pool.Conn, string) {} +func (noopRecorder) RecordError(context.Context, string, *pool.Conn, string, bool, int) {} +func (noopRecorder) RecordMaintenanceNotification(context.Context, *pool.Conn, string) {} + +func (noopRecorder) RecordConnectionWaitTime(context.Context, time.Duration, *pool.Conn) {} +func (noopRecorder) RecordConnectionClosed(context.Context, *pool.Conn, string, error) {} + +func (noopRecorder) RecordPubSubMessage(context.Context, *pool.Conn, string, string, bool) {} + +func (noopRecorder) RecordStreamLag(context.Context, time.Duration, *pool.Conn, string, string, string) { +} + +// RegisterPools registers connection pools with the global recorder. +func RegisterPools(connPool pool.Pooler, pubSubPool PubSubPooler, addr string) { + // Check if the global recorder implements PoolRegistrar + if registrar, ok := globalRecorder.(PoolRegistrar); ok { + // Generate a unique ID for this client's pools + uniqueID := generateUniqueID() + + if connPool != nil { + poolName := addr + "_" + uniqueID + registrar.RegisterPool(poolName, connPool) + } + if pubSubPool != nil { + poolName := addr + "_" + uniqueID + "_pubsub" + registrar.RegisterPubSubPool(poolName, pubSubPool) + } + } +} + +// UnregisterPools removes connection pools from the global recorder +func UnregisterPools(connPool pool.Pooler, pubSubPool PubSubPooler) { + // Check if the global recorder implements PoolRegistrar + if registrar, ok := globalRecorder.(PoolRegistrar); ok { + if connPool != nil { + registrar.UnregisterPool(connPool) + } + if pubSubPool != nil { + registrar.UnregisterPubSubPool(pubSubPool) + } + } +} diff --git a/vendor/github.com/redis/go-redis/v9/internal/pool/conn.go b/vendor/github.com/redis/go-redis/v9/internal/pool/conn.go index 95d83bfd..f0af63c6 100644 --- a/vendor/github.com/redis/go-redis/v9/internal/pool/conn.go +++ b/vendor/github.com/redis/go-redis/v9/internal/pool/conn.go @@ -69,8 +69,9 @@ type Conn struct { // Connection identifier for unique tracking id uint64 - usedAt atomic.Int64 - lastPutAt atomic.Int64 + usedAt atomic.Int64 + lastPutAt atomic.Int64 + dialStartNs atomic.Int64 // Time when dial started (for connection create time metric) // Lock-free netConn access using atomic.Value // Contains *atomicNetConn wrapper, accessed atomically for better performance @@ -104,6 +105,7 @@ type Conn struct { closed atomic.Bool createdAt time.Time expiresAt time.Time + poolName string // Name of the pool this connection belongs to (for metrics) // maintenanceNotifications upgrade support: relaxed timeouts during migrations/failovers @@ -184,6 +186,24 @@ func (cn *Conn) SetLastPutAtNs(ns int64) { cn.lastPutAt.Store(ns) } +// GetDialStartNs returns the time when the dial started (in nanoseconds since epoch). +// This is used to calculate the full connection creation time (TCP + handshake). +func (cn *Conn) GetDialStartNs() int64 { + return cn.dialStartNs.Load() +} + +// PoolName returns the name of the pool this connection belongs to. +// This is used for metrics to identify which pool a connection is from. +func (cn *Conn) PoolName() string { + return cn.poolName +} + +// SetPoolName sets the name of the pool this connection belongs to. +// This should be called when the connection is added to a pool. +func (cn *Conn) SetPoolName(name string) { + cn.poolName = name +} + // Backward-compatible wrapper methods for state machine // These maintain the existing API while using the new state machine internally @@ -418,6 +438,8 @@ func (cn *Conn) IsPubSub() bool { // SetRelaxedTimeout sets relaxed timeouts for this connection during maintenanceNotifications upgrades. // These timeouts will be used for all subsequent commands until the deadline expires. // Uses atomic operations for lock-free access. +// Note: Metrics should be recorded by the caller (notification handler) which has context about +// the notification type and pool name. func (cn *Conn) SetRelaxedTimeout(readTimeout, writeTimeout time.Duration) { cn.relaxedCounter.Add(1) cn.relaxedReadTimeoutNs.Store(int64(readTimeout)) @@ -452,6 +474,11 @@ func (cn *Conn) clearRelaxedTimeout() { cn.relaxedWriteTimeoutNs.Store(0) cn.relaxedDeadlineNs.Store(0) cn.relaxedCounter.Store(0) + + // Note: Metrics for timeout unrelaxing are not recorded here because we don't have + // context about which notification type or pool triggered the relaxation. + // In practice, relaxed timeouts expire automatically via deadline, so explicit + // unrelaxing metrics are less critical than the initial relaxation metrics. } // HasRelaxedTimeout returns true if relaxed timeouts are currently active on this connection. diff --git a/vendor/github.com/redis/go-redis/v9/internal/pool/conn_state.go b/vendor/github.com/redis/go-redis/v9/internal/pool/conn_state.go index 2050a742..afdc631c 100644 --- a/vendor/github.com/redis/go-redis/v9/internal/pool/conn_state.go +++ b/vendor/github.com/redis/go-redis/v9/internal/pool/conn_state.go @@ -13,11 +13,12 @@ import ( // States are designed to be lightweight and fast to check. // // State Transitions: -// CREATED โ†’ INITIALIZING โ†’ IDLE โ‡„ IN_USE -// โ†“ -// UNUSABLE (handoff/reauth) -// โ†“ -// IDLE/CLOSED +// +// CREATED โ†’ INITIALIZING โ†’ IDLE โ‡„ IN_USE +// โ†“ +// UNUSABLE (handoff/reauth) +// โ†“ +// IDLE/CLOSED type ConnState uint32 const ( @@ -120,7 +121,7 @@ type ConnStateMachine struct { // FIFO queue for waiters - only locked during waiter add/remove/notify mu sync.Mutex - waiters *list.List // List of *waiter + waiters *list.List // List of *waiter waiterCount atomic.Int32 // Fast lock-free check for waiters (avoids mutex in hot path) } @@ -340,4 +341,3 @@ func (sm *ConnStateMachine) notifyWaiters() { } } } - diff --git a/vendor/github.com/redis/go-redis/v9/internal/pool/pool.go b/vendor/github.com/redis/go-redis/v9/internal/pool/pool.go index 4c99b828..aaca530c 100644 --- a/vendor/github.com/redis/go-redis/v9/internal/pool/pool.go +++ b/vendor/github.com/redis/go-redis/v9/internal/pool/pool.go @@ -11,7 +11,6 @@ import ( "github.com/redis/go-redis/v9/internal" "github.com/redis/go-redis/v9/internal/proto" "github.com/redis/go-redis/v9/internal/rand" - "github.com/redis/go-redis/v9/internal/util" ) var ( @@ -33,6 +32,42 @@ var ( // errConnNotPooled is returned when trying to return a non-pooled connection to the pool. errConnNotPooled = errors.New("connection not pooled") + // metricCallbackMu protects all global metric callback functions for thread-safe access. + metricCallbackMu sync.RWMutex + + // Global metric callbacks for connection state changes + metricConnectionStateChangeCallback func(ctx context.Context, cn *Conn, fromState, toState string) + + // Global metric callback for connection creation time + metricConnectionCreateTimeCallback func(ctx context.Context, duration time.Duration, cn *Conn) + + // Global metric callback for connection relaxed timeout changes + // Parameters: ctx, delta (+1/-1), cn, poolName, notificationType + metricConnectionRelaxedTimeoutCallback func(ctx context.Context, delta int, cn *Conn, poolName, notificationType string) + + // Global metric callback for connection handoff + // Parameters: ctx, cn, poolName + metricConnectionHandoffCallback func(ctx context.Context, cn *Conn, poolName string) + + // Global metric callback for error tracking + // Parameters: ctx, errorType, cn, statusCode, isInternal, retryAttempts + metricErrorCallback func(ctx context.Context, errorType string, cn *Conn, statusCode string, isInternal bool, retryAttempts int) + + // Global metric callback for maintenance notifications + // Parameters: ctx, cn, notificationType + metricMaintenanceNotificationCallback func(ctx context.Context, cn *Conn, notificationType string) + + // Global metric callback for connection wait time + // Parameters: ctx, duration, cn + metricConnectionWaitTimeCallback func(ctx context.Context, duration time.Duration, cn *Conn) + + // Global metric callback for connection timeouts + // Parameters: ctx, cn, timeoutType + metricConnectionTimeoutCallback func(ctx context.Context, cn *Conn, timeoutType string) + + // Global metric callback for connection closed + // Parameters: ctx, cn, reason, err + metricConnectionClosedCallback func(ctx context.Context, cn *Conn, reason string, err error) // errPanicInDial is returned when a panic occurs in the dial function. errPanicInQueuedNewConn = errors.New("panic in queuedNewConn") @@ -55,6 +90,139 @@ var ( noExpiration = maxTime ) +// MetricCallbacks holds all metric callback functions. +// Use SetAllMetricCallbacks to register all callbacks atomically. +type MetricCallbacks struct { + // ConnectionCreateTime is called when a new connection is created + ConnectionCreateTime func(ctx context.Context, duration time.Duration, cn *Conn) + + // ConnectionRelaxedTimeout is called when connection timeout is relaxed/unrelaxed + // delta: +1 for relaxed, -1 for unrelaxed + ConnectionRelaxedTimeout func(ctx context.Context, delta int, cn *Conn, poolName, notificationType string) + + // ConnectionHandoff is called when a connection is handed off to another node + ConnectionHandoff func(ctx context.Context, cn *Conn, poolName string) + + // Error is called when an error occurs + Error func(ctx context.Context, errorType string, cn *Conn, statusCode string, isInternal bool, retryAttempts int) + + // MaintenanceNotification is called when a maintenance notification is received + MaintenanceNotification func(ctx context.Context, cn *Conn, notificationType string) + + // ConnectionWaitTime is called to record time spent waiting for a connection + ConnectionWaitTime func(ctx context.Context, duration time.Duration, cn *Conn) + + // ConnectionClosed is called when a connection is closed + ConnectionClosed func(ctx context.Context, cn *Conn, reason string, err error) +} + +// SetAllMetricCallbacks sets all metric callbacks atomically. +// Pass nil to clear all callbacks (disable metrics). +// This ensures all callbacks are set together under a single lock, +// preventing inconsistent state during registration. +// +// Note on thread safety: After returning, there is a small window where +// concurrent getMetric* calls may return the old callback value. This is +// acceptable for metrics - at most one event may go to the old recorder +// or be missed during the transition. The callbacks themselves are immutable +// function pointers, so calling an "old" callback is safe. +func SetAllMetricCallbacks(callbacks *MetricCallbacks) { + metricCallbackMu.Lock() + defer metricCallbackMu.Unlock() + + if callbacks == nil { + metricConnectionCreateTimeCallback = nil + metricConnectionRelaxedTimeoutCallback = nil + metricConnectionHandoffCallback = nil + metricErrorCallback = nil + metricMaintenanceNotificationCallback = nil + metricConnectionWaitTimeCallback = nil + metricConnectionClosedCallback = nil + return + } + + metricConnectionCreateTimeCallback = callbacks.ConnectionCreateTime + metricConnectionRelaxedTimeoutCallback = callbacks.ConnectionRelaxedTimeout + metricConnectionHandoffCallback = callbacks.ConnectionHandoff + metricErrorCallback = callbacks.Error + metricMaintenanceNotificationCallback = callbacks.MaintenanceNotification + metricConnectionWaitTimeCallback = callbacks.ConnectionWaitTime + metricConnectionClosedCallback = callbacks.ConnectionClosed +} + +// getMetricConnectionStateChangeCallback returns the metric callback for connection state changes. +func getMetricConnectionStateChangeCallback() func(ctx context.Context, cn *Conn, fromState, toState string) { + metricCallbackMu.RLock() + cb := metricConnectionStateChangeCallback + metricCallbackMu.RUnlock() + return cb +} + +// GetMetricConnectionCreateTimeCallback returns the metric callback for connection creation time. +func GetMetricConnectionCreateTimeCallback() func(ctx context.Context, duration time.Duration, cn *Conn) { + metricCallbackMu.RLock() + cb := metricConnectionCreateTimeCallback + metricCallbackMu.RUnlock() + return cb +} + +// GetMetricConnectionRelaxedTimeoutCallback returns the metric callback for connection relaxed timeout changes. +// This is used by maintnotifications to record relaxed timeout metrics. +func GetMetricConnectionRelaxedTimeoutCallback() func(ctx context.Context, delta int, cn *Conn, poolName, notificationType string) { + metricCallbackMu.RLock() + cb := metricConnectionRelaxedTimeoutCallback + metricCallbackMu.RUnlock() + return cb +} + +// GetMetricConnectionHandoffCallback returns the metric callback for connection handoffs. +// This is used by maintnotifications to record handoff metrics. +func GetMetricConnectionHandoffCallback() func(ctx context.Context, cn *Conn, poolName string) { + metricCallbackMu.RLock() + cb := metricConnectionHandoffCallback + metricCallbackMu.RUnlock() + return cb +} + +// GetMetricErrorCallback returns the metric callback for error tracking. +// This is used by cluster and client code to record error metrics. +func GetMetricErrorCallback() func(ctx context.Context, errorType string, cn *Conn, statusCode string, isInternal bool, retryAttempts int) { + metricCallbackMu.RLock() + cb := metricErrorCallback + metricCallbackMu.RUnlock() + return cb +} + +// GetMetricMaintenanceNotificationCallback returns the metric callback for maintenance notifications. +// This is used by maintnotifications to record notification metrics. +func GetMetricMaintenanceNotificationCallback() func(ctx context.Context, cn *Conn, notificationType string) { + metricCallbackMu.RLock() + cb := metricMaintenanceNotificationCallback + metricCallbackMu.RUnlock() + return cb +} + +func getMetricConnectionWaitTimeCallback() func(ctx context.Context, duration time.Duration, cn *Conn) { + metricCallbackMu.RLock() + cb := metricConnectionWaitTimeCallback + metricCallbackMu.RUnlock() + return cb +} + +func getMetricConnectionTimeoutCallback() func(ctx context.Context, cn *Conn, timeoutType string) { + metricCallbackMu.RLock() + cb := metricConnectionTimeoutCallback + metricCallbackMu.RUnlock() + return cb +} + +func getMetricConnectionClosedCallback() func(ctx context.Context, cn *Conn, reason string, err error) { + metricCallbackMu.RLock() + cb := metricConnectionClosedCallback + metricCallbackMu.RUnlock() + return cb +} + // Stats contains pool state information and accumulated stats. type Stats struct { Hits uint32 // number of times free connection was found in the pool @@ -64,9 +232,10 @@ type Stats struct { Unusable uint32 // number of times a connection was found to be unusable WaitDurationNs int64 // total time spent for waiting a connection in nanoseconds - TotalConns uint32 // number of total connections in the pool - IdleConns uint32 // number of idle connections in the pool - StaleConns uint32 // number of stale connections removed from the pool + TotalConns uint32 // number of total connections in the pool + IdleConns uint32 // number of idle connections in the pool + StaleConns uint32 // number of stale connections removed from the pool + PendingRequests uint32 // number of pending requests waiting for a connection PubSubStats PubSubStats } @@ -124,6 +293,10 @@ type Options struct { // DialerRetryTimeout is the backoff duration between retry attempts. // Default: 100ms DialerRetryTimeout time.Duration + + // Name is a unique identifier for this pool, used in metrics. + // Format: addr_uniqueID (e.g., "localhost:6379_a1b2c3d4") + Name string } type lastDialErrorWrap struct { @@ -245,9 +418,9 @@ func (p *ConnPool) checkMinIdleConns() { for p.poolSize.Load() < p.cfg.PoolSize && p.idleConnsLen.Load() < p.cfg.MinIdleConns { // Try to acquire a semaphore token if !p.semaphore.TryAcquire() { - // Semaphore is full, can't create more connections - p.idleCheckInProgress.Store(false) - return + // Semaphore is full, can't create more connections right now + // Break out of inner loop to check if we need to retry + break } p.poolSize.Add(1) @@ -370,6 +543,11 @@ func (p *ConnPool) newConn(ctx context.Context, pooled bool) (*Conn, error) { } } + // Notify metrics: new connection created and idle + if cb := getMetricConnectionStateChangeCallback(); cb != nil { + cb(ctx, cn, "", "idle") + } + return cn, nil } @@ -382,6 +560,14 @@ func (p *ConnPool) dialConn(ctx context.Context, pooled bool) (*Conn, error) { return nil, p.getLastDialError() } + // Record dial start time for connection creation metric + // This will be used after handshake completes in redis.go _getConn() + // Only call time.Now() if callback is registered to avoid overhead + var dialStartNs int64 + if GetMetricConnectionCreateTimeCallback() != nil { + dialStartNs = time.Now().UnixNano() + } + // Retry dialing with backoff // the context timeout is already handled by the context passed in // so we may never reach the max retries, higher values don't hurt @@ -415,10 +601,15 @@ func (p *ConnPool) dialConn(ctx context.Context, pooled bool) (*Conn, error) { continue } - // Success - create connection cn := NewConnWithBufferSize(netConn, p.cfg.ReadBufferSize, p.cfg.WriteBufferSize) cn.pooled = pooled + // Store dial start time only if we recorded it + if dialStartNs > 0 { + cn.dialStartNs.Store(dialStartNs) + } cn.expiresAt = p.calcConnExpiresAt() + // Set pool name for metrics + cn.SetPoolName(p.cfg.Name) return cn, nil } @@ -492,17 +683,44 @@ func (p *ConnPool) Get(ctx context.Context) (*Conn, error) { } // getConn returns a connection from the pool. -func (p *ConnPool) getConn(ctx context.Context) (*Conn, error) { - var cn *Conn - var err error - +func (p *ConnPool) getConn(ctx context.Context) (cn *Conn, err error) { if p.closed() { return nil, ErrClosed } - if err := p.waitTurn(ctx); err != nil { + // Track pending requests in pool stats + // NOTE: We only track in stats, not via callback. The AsyncGauge reads stats directly. + atomic.AddUint32(&p.stats.PendingRequests, 1) + defer func() { + if err != nil { + // Failed to get connection, decrement pending requests + atomic.AddUint32(&p.stats.PendingRequests, ^uint32(0)) // -1 + } + }() + + // Track wait time - only call time.Now() if callback is registered + var waitStart time.Time + waitTimeCallback := getMetricConnectionWaitTimeCallback() + if waitTimeCallback != nil { + waitStart = time.Now() + } + if err = p.waitTurn(ctx); err != nil { + // Record timeout if applicable + if err == ErrPoolTimeout { + if cb := getMetricConnectionTimeoutCallback(); cb != nil { + cb(ctx, nil, "pool") + } + // Record general error metric for pool timeout + if cb := GetMetricErrorCallback(); cb != nil { + cb(ctx, "POOL_TIMEOUT", nil, "POOL_TIMEOUT", true, 0) + } + } return nil, err } + var waitDuration time.Duration + if waitTimeCallback != nil { + waitDuration = time.Since(waitStart) + } // Use cached time for health checks (max 50ms staleness is acceptable) nowNs := getCachedTimeNs() @@ -533,10 +751,10 @@ func (p *ConnPool) getConn(ctx context.Context) (*Conn, error) { // Process connection using the hooks system // Combine error and rejection checks to reduce branches if hookManager != nil { - acceptConn, err := hookManager.ProcessOnGet(ctx, cn, false) - if err != nil || !acceptConn { - if err != nil { - internal.Logger.Printf(ctx, "redis: connection pool: failed to process idle connection by hook: %v", err) + acceptConn, hookErr := hookManager.ProcessOnGet(ctx, cn, false) + if hookErr != nil || !acceptConn { + if hookErr != nil { + internal.Logger.Printf(ctx, "redis: connection pool: failed to process idle connection by hook: %v", hookErr) _ = p.CloseConn(cn) } else { internal.Logger.Printf(ctx, "redis: connection pool: conn[%d] rejected by hook, returning to pool", cn.GetID()) @@ -550,19 +768,37 @@ func (p *ConnPool) getConn(ctx context.Context) (*Conn, error) { } atomic.AddUint32(&p.stats.Hits, 1) + + // Notify metrics: connection moved from idle to used + if cb := getMetricConnectionStateChangeCallback(); cb != nil { + cb(ctx, cn, "idle", "used") + } + + // Record wait time (use cached callback from above) + if waitTimeCallback != nil { + waitTimeCallback(ctx, waitDuration, cn) + } + + // Decrement pending requests (connection acquired successfully) + // NOTE: We only track in stats, not via callback. The AsyncGauge reads stats directly. + atomic.AddUint32(&p.stats.PendingRequests, ^uint32(0)) // -1 + return cn, nil } atomic.AddUint32(&p.stats.Misses, 1) - newcn, err := p.queuedNewConn(ctx) + var newcn *Conn + newcn, err = p.queuedNewConn(ctx) if err != nil { return nil, err } // Process connection using the hooks system + // This includes the handshake (HELLO/AUTH) via initConn hook if hookManager != nil { - acceptConn, err := hookManager.ProcessOnGet(ctx, newcn, true) + var acceptConn bool + acceptConn, err = hookManager.ProcessOnGet(ctx, newcn, true) // both errors and accept=false mean a hook rejected the connection // this should not happen with a new connection, but we handle it gracefully if err != nil || !acceptConn { @@ -572,6 +808,21 @@ func (p *ConnPool) getConn(ctx context.Context) (*Conn, error) { return nil, err } } + + // Notify metrics: new connection is created and used + if cb := getMetricConnectionStateChangeCallback(); cb != nil { + cb(ctx, newcn, "", "used") + } + + // Record wait time (use cached callback from above) + if waitTimeCallback != nil { + waitTimeCallback(ctx, waitDuration, newcn) + } + + // Decrement pending requests (connection acquired successfully) + // NOTE: We only track in stats, not via callback. The AsyncGauge reads stats directly. + atomic.AddUint32(&p.stats.PendingRequests, ^uint32(0)) // -1 + return newcn, nil } @@ -726,7 +977,7 @@ func (p *ConnPool) popIdle() (*Conn, error) { var cn *Conn attempts := 0 - maxAttempts := util.Min(popAttempts, n) + maxAttempts := min(popAttempts, n) for attempts < maxAttempts { if len(p.idleConns) == 0 { return nil, nil @@ -787,6 +1038,15 @@ func (p *ConnPool) putConnWithoutTurn(ctx context.Context, cn *Conn) { // putConn is the internal implementation of Put that optionally frees a turn. func (p *ConnPool) putConn(ctx context.Context, cn *Conn, freeTurn bool) { + // Guard against nil connection + if cn == nil { + internal.Logger.Printf(ctx, "putConn called with nil connection") + if freeTurn { + p.freeTurn() + } + return + } + // Process connection using the hooks system shouldPool := true shouldRemove := false @@ -837,7 +1097,14 @@ func (p *ConnPool) putConn(ctx context.Context, cn *Conn, freeTurn bool) { if !transitionedToIdle { // Fast path failed - hook might have changed state (e.g., to UNUSABLE for handoff) // Keep the state set by the hook and pool the connection anyway - currentState := cn.GetStateMachine().GetState() + sm := cn.GetStateMachine() + if sm == nil { + // State machine is nil - connection is in an invalid state, remove it + internal.Logger.Printf(ctx, "conn[%d] has nil state machine, removing it", cn.GetID()) + p.removeConnInternal(ctx, cn, errConnNotPooled, freeTurn) + return + } + currentState := sm.GetState() switch currentState { case StateUnusable: // expected state, don't log it @@ -871,9 +1138,19 @@ func (p *ConnPool) putConn(ctx context.Context, cn *Conn, freeTurn bool) { p.connsMu.Unlock() p.idleConnsLen.Add(1) } + + // Notify metrics: connection moved from used to idle + if cb := getMetricConnectionStateChangeCallback(); cb != nil { + cb(ctx, cn, "used", "idle") + } } else { shouldCloseConn = true p.removeConnWithLock(cn) + + // Notify metrics: connection removed (used -> nothing) + if cb := getMetricConnectionStateChangeCallback(); cb != nil { + cb(ctx, cn, "used", "") + } } if freeTurn { @@ -914,6 +1191,20 @@ func (p *ConnPool) removeConnInternal(ctx context.Context, cn *Conn, reason erro p.freeTurn() } + // Notify metrics: connection removed (assume from used state) + if cb := getMetricConnectionStateChangeCallback(); cb != nil { + cb(ctx, cn, "used", "") + } + + // Record connection closed + if cb := getMetricConnectionClosedCallback(); cb != nil { + reasonStr := "unknown" + if reason != nil { + reasonStr = reason.Error() + } + cb(ctx, cn, reasonStr, reason) + } + _ = p.closeConn(cn) // Check if we need to create new idle connections to maintain MinIdleConns @@ -980,12 +1271,13 @@ func (p *ConnPool) Size() int { func (p *ConnPool) Stats() *Stats { return &Stats{ - Hits: atomic.LoadUint32(&p.stats.Hits), - Misses: atomic.LoadUint32(&p.stats.Misses), - Timeouts: atomic.LoadUint32(&p.stats.Timeouts), - WaitCount: atomic.LoadUint32(&p.stats.WaitCount), - Unusable: atomic.LoadUint32(&p.stats.Unusable), - WaitDurationNs: p.waitDurationNs.Load(), + Hits: atomic.LoadUint32(&p.stats.Hits), + Misses: atomic.LoadUint32(&p.stats.Misses), + Timeouts: atomic.LoadUint32(&p.stats.Timeouts), + WaitCount: atomic.LoadUint32(&p.stats.WaitCount), + Unusable: atomic.LoadUint32(&p.stats.Unusable), + WaitDurationNs: p.waitDurationNs.Load(), + PendingRequests: atomic.LoadUint32(&p.stats.PendingRequests), TotalConns: uint32(p.Len()), IdleConns: uint32(p.IdleLen()), diff --git a/vendor/github.com/redis/go-redis/v9/internal/pool/pubsub.go b/vendor/github.com/redis/go-redis/v9/internal/pool/pubsub.go index 5b29659e..e566d42b 100644 --- a/vendor/github.com/redis/go-redis/v9/internal/pool/pubsub.go +++ b/vendor/github.com/redis/go-redis/v9/internal/pool/pubsub.go @@ -44,9 +44,10 @@ func (p *PubSubPool) NewConn(ctx context.Context, network string, addr string, c } cn := NewConnWithBufferSize(netConn, p.opt.ReadBufferSize, p.opt.WriteBufferSize) cn.pubsub = true + // Set pool name for metrics + cn.SetPoolName(p.opt.Name) atomic.AddUint32(&p.stats.Created, 1) return cn, nil - } func (p *PubSubPool) TrackConn(cn *Conn) { diff --git a/vendor/github.com/redis/go-redis/v9/internal/proto/redis_errors.go b/vendor/github.com/redis/go-redis/v9/internal/proto/redis_errors.go index f553e2f9..a28240f5 100644 --- a/vendor/github.com/redis/go-redis/v9/internal/proto/redis_errors.go +++ b/vendor/github.com/redis/go-redis/v9/internal/proto/redis_errors.go @@ -212,6 +212,25 @@ func NewOOMError(msg string) *OOMError { return &OOMError{msg: msg} } +// NoReplicasError is returned when not enough replicas acknowledge a write. +// This error occurs when using WAIT/WAITAOF commands or CLUSTER SETSLOT with +// synchronous replication, and the required number of replicas cannot confirm +// the write within the timeout period. +type NoReplicasError struct { + msg string +} + +func (e *NoReplicasError) Error() string { + return e.msg +} + +func (e *NoReplicasError) RedisError() {} + +// NewNoReplicasError creates a new NoReplicasError with the given message. +func NewNoReplicasError(msg string) *NoReplicasError { + return &NoReplicasError{msg: msg} +} + // parseTypedRedisError parses a Redis error message and returns a typed error if applicable. // This function maintains backward compatibility by keeping the same error messages. func parseTypedRedisError(msg string) error { @@ -235,6 +254,8 @@ func parseTypedRedisError(msg string) error { return NewTryAgainError(msg) case strings.HasPrefix(msg, "MASTERDOWN "): return NewMasterDownError(msg) + case strings.HasPrefix(msg, "NOREPLICAS "): + return NewNoReplicasError(msg) case msg == "ERR max number of clients reached": return NewMaxClientsError(msg) case strings.HasPrefix(msg, "NOAUTH "), strings.HasPrefix(msg, "WRONGPASS "), strings.Contains(msg, "unauthenticated"): @@ -486,3 +507,21 @@ func IsOOMError(err error) bool { // Fallback to string checking for backward compatibility return strings.HasPrefix(err.Error(), "OOM ") } + +// IsNoReplicasError checks if an error is a NoReplicasError, even if wrapped. +func IsNoReplicasError(err error) bool { + if err == nil { + return false + } + var noReplicasErr *NoReplicasError + if errors.As(err, &noReplicasErr) { + return true + } + // Check if wrapped error is a RedisError with NOREPLICAS prefix + var redisErr RedisError + if errors.As(err, &redisErr) && strings.HasPrefix(redisErr.Error(), "NOREPLICAS ") { + return true + } + // Fallback to string checking for backward compatibility + return strings.HasPrefix(err.Error(), "NOREPLICAS ") +} diff --git a/vendor/github.com/redis/go-redis/v9/internal/routing/aggregator.go b/vendor/github.com/redis/go-redis/v9/internal/routing/aggregator.go new file mode 100644 index 00000000..0d6321ec --- /dev/null +++ b/vendor/github.com/redis/go-redis/v9/internal/routing/aggregator.go @@ -0,0 +1,1000 @@ +package routing + +import ( + "errors" + "fmt" + "math" + "sync" + + "sync/atomic" + + "github.com/redis/go-redis/v9/internal/util" + uberAtomic "go.uber.org/atomic" +) + +var ( + ErrMaxAggregation = errors.New("redis: no valid results to aggregate for max operation") + ErrMinAggregation = errors.New("redis: no valid results to aggregate for min operation") + ErrAndAggregation = errors.New("redis: no valid results to aggregate for logical AND operation") + ErrOrAggregation = errors.New("redis: no valid results to aggregate for logical OR operation") +) + +// ResponseAggregator defines the interface for aggregating responses from multiple shards. +type ResponseAggregator interface { + // Add processes a single shard response. + Add(result interface{}, err error) error + + // AddWithKey processes a single shard response for a specific key (used by keyed aggregators). + AddWithKey(key string, result interface{}, err error) error + + BatchAdd(map[string]AggregatorResErr) error + + BatchSlice([]AggregatorResErr) error + + // Result returns the final aggregated result and any error. + Result() (interface{}, error) +} + +type AggregatorResErr struct { + Result interface{} + Err error +} + +// NewResponseAggregator creates an aggregator based on the response policy. +func NewResponseAggregator(policy ResponsePolicy, cmdName string) ResponseAggregator { + switch policy { + case RespDefaultKeyless: + return &DefaultKeylessAggregator{results: make([]interface{}, 0)} + case RespDefaultHashSlot: + return &DefaultKeyedAggregator{results: make(map[string]interface{})} + case RespAllSucceeded: + return &AllSucceededAggregator{} + case RespOneSucceeded: + return &OneSucceededAggregator{} + case RespAggSum: + return &AggSumAggregator{ + // res: + } + case RespAggMin: + return &AggMinAggregator{ + res: util.NewAtomicMin(), + } + case RespAggMax: + return &AggMaxAggregator{ + res: util.NewAtomicMax(), + } + case RespAggLogicalAnd: + andAgg := &AggLogicalAndAggregator{} + andAgg.res.Store(true) + + return andAgg + case RespAggLogicalOr: + return &AggLogicalOrAggregator{} + case RespSpecial: + return NewSpecialAggregator(cmdName) + default: + return &AllSucceededAggregator{} + } +} + +func NewDefaultAggregator(isKeyed bool) ResponseAggregator { + if isKeyed { + return &DefaultKeyedAggregator{ + results: make(map[string]interface{}), + } + } + return &DefaultKeylessAggregator{} +} + +// AllSucceededAggregator returns one non-error reply if every shard succeeded, +// propagates the first error otherwise. +type AllSucceededAggregator struct { + err atomic.Value + res atomic.Value +} + +func (a *AllSucceededAggregator) Add(result interface{}, err error) error { + if err != nil { + a.err.CompareAndSwap(nil, err) + return nil + } + + if result != nil { + a.res.CompareAndSwap(nil, result) + } + + return nil +} + +func (a *AllSucceededAggregator) BatchAdd(results map[string]AggregatorResErr) error { + for _, res := range results { + err := a.Add(res.Result, res.Err) + if err != nil { + return err + } + + if res.Err != nil { + return nil + } + } + + return nil +} + +func (a *AllSucceededAggregator) BatchSlice(results []AggregatorResErr) error { + for _, res := range results { + err := a.Add(res.Result, res.Err) + if err != nil { + return err + } + + if res.Err != nil { + return nil + } + } + + return nil +} + +func (a *AllSucceededAggregator) Result() (interface{}, error) { + var err error + res, e := a.res.Load(), a.err.Load() + if e != nil { + err = e.(error) + } + + return res, err +} + +func (a *AllSucceededAggregator) AddWithKey(key string, result interface{}, err error) error { + return a.Add(result, err) +} + +// OneSucceededAggregator returns the first non-error reply, +// if all shards errored, returns any one of those errors. +type OneSucceededAggregator struct { + err atomic.Value + res atomic.Value +} + +func (a *OneSucceededAggregator) Add(result interface{}, err error) error { + if err != nil { + a.err.CompareAndSwap(nil, err) + return nil + } + + if result != nil { + a.res.CompareAndSwap(nil, result) + } + + return nil +} + +func (a *OneSucceededAggregator) BatchAdd(results map[string]AggregatorResErr) error { + for _, res := range results { + err := a.Add(res.Result, res.Err) + if err != nil { + return err + } + + if res.Err == nil { + return nil + } + } + + return nil +} + +func (a *OneSucceededAggregator) AddWithKey(key string, result interface{}, err error) error { + return a.Add(result, err) +} + +func (a *OneSucceededAggregator) BatchSlice(results []AggregatorResErr) error { + for _, res := range results { + err := a.Add(res.Result, res.Err) + if err != nil { + return err + } + + if res.Err == nil { + return nil + } + } + + return nil +} + +func (a *OneSucceededAggregator) Result() (interface{}, error) { + res, e := a.res.Load(), a.err.Load() + if res == nil { + return nil, e.(error) + } + + return res, nil +} + +// AggSumAggregator sums numeric replies from all shards. +type AggSumAggregator struct { + err atomic.Value + res uberAtomic.Float64 +} + +func (a *AggSumAggregator) Add(result interface{}, err error) error { + if err != nil { + a.err.CompareAndSwap(nil, err) + } + + if result != nil { + val, err := toFloat64(result) + if err != nil { + a.err.CompareAndSwap(nil, err) + return err + } + a.res.Add(val) + } + + return nil +} + +func (a *AggSumAggregator) BatchAdd(results map[string]AggregatorResErr) error { + var sum int64 + + for _, res := range results { + if res.Err != nil { + return a.Add(res.Result, res.Err) + } + + intRes, err := toInt64(res.Result) + if err != nil { + return a.Add(nil, err) + } + + sum += intRes + } + + return a.Add(sum, nil) +} + +func (a *AggSumAggregator) AddWithKey(key string, result interface{}, err error) error { + return a.Add(result, err) +} + +func (a *AggSumAggregator) BatchSlice(results []AggregatorResErr) error { + var sum int64 + + for _, res := range results { + if res.Err != nil { + return a.Add(res.Result, res.Err) + } + + intRes, err := toInt64(res.Result) + if err != nil { + return a.Add(nil, err) + } + + sum += intRes + } + + return a.Add(sum, nil) +} + +func (a *AggSumAggregator) Result() (interface{}, error) { + res, err := a.res.Load(), a.err.Load() + if err != nil { + return nil, err.(error) + } + + return res, nil +} + +// AggMinAggregator returns the minimum numeric value from all shards. +type AggMinAggregator struct { + err atomic.Value + res *util.AtomicMin +} + +func (a *AggMinAggregator) Add(result interface{}, err error) error { + if err != nil { + a.err.CompareAndSwap(nil, err) + return nil + } + + floatVal, e := toFloat64(result) + if e != nil { + a.err.CompareAndSwap(nil, err) + return nil + } + + a.res.Value(floatVal) + + return nil +} + +func (a *AggMinAggregator) BatchAdd(results map[string]AggregatorResErr) error { + min := int64(math.MaxInt64) + + for _, res := range results { + if res.Err != nil { + _ = a.Add(nil, res.Err) + return nil + } + + resInt, err := toInt64(res.Result) + if err != nil { + _ = a.Add(nil, res.Err) + return nil + } + + if resInt < min { + min = resInt + } + + } + + return a.Add(min, nil) +} + +func (a *AggMinAggregator) AddWithKey(key string, result interface{}, err error) error { + return a.Add(result, err) +} + +func (a *AggMinAggregator) BatchSlice(results []AggregatorResErr) error { + min := float64(math.MaxFloat64) + + for _, res := range results { + if res.Err != nil { + _ = a.Add(nil, res.Err) + return nil + } + + floatVal, err := toFloat64(res.Result) + if err != nil { + _ = a.Add(nil, res.Err) + return nil + } + + if floatVal < min { + min = floatVal + } + + } + + return a.Add(min, nil) +} + +func (a *AggMinAggregator) Result() (interface{}, error) { + err := a.err.Load() + if err != nil { + return nil, err.(error) + } + + val, hasVal := a.res.Min() + if !hasVal { + return nil, ErrMinAggregation + } + return val, nil +} + +// AggMaxAggregator returns the maximum numeric value from all shards. +type AggMaxAggregator struct { + err atomic.Value + res *util.AtomicMax +} + +func (a *AggMaxAggregator) Add(result interface{}, err error) error { + if err != nil { + a.err.CompareAndSwap(nil, err) + return nil + } + + floatVal, e := toFloat64(result) + if e != nil { + a.err.CompareAndSwap(nil, err) + return nil + } + + a.res.Value(floatVal) + + return nil +} + +func (a *AggMaxAggregator) BatchAdd(results map[string]AggregatorResErr) error { + max := int64(math.MinInt64) + + for _, res := range results { + if res.Err != nil { + _ = a.Add(nil, res.Err) + return nil + } + + resInt, err := toInt64(res.Result) + if err != nil { + _ = a.Add(nil, res.Err) + return nil + } + + if resInt > max { + max = resInt + } + + } + + return a.Add(max, nil) +} + +func (a *AggMaxAggregator) AddWithKey(key string, result interface{}, err error) error { + return a.Add(result, err) +} + +func (a *AggMaxAggregator) BatchSlice(results []AggregatorResErr) error { + max := int64(math.MinInt64) + + for _, res := range results { + if res.Err != nil { + _ = a.Add(nil, res.Err) + return nil + } + + resInt, err := toInt64(res.Result) + if err != nil { + _ = a.Add(nil, res.Err) + return nil + } + + if resInt > max { + max = resInt + } + + } + + return a.Add(max, nil) +} + +func (a *AggMaxAggregator) Result() (interface{}, error) { + err := a.err.Load() + if err != nil { + return nil, err.(error) + } + + val, hasVal := a.res.Max() + if !hasVal { + return nil, ErrMaxAggregation + } + return val, nil +} + +// AggLogicalAndAggregator performs logical AND on boolean values. +type AggLogicalAndAggregator struct { + err atomic.Value + res atomic.Bool + hasResult atomic.Bool +} + +func (a *AggLogicalAndAggregator) Add(result interface{}, err error) error { + if err != nil { + a.err.CompareAndSwap(nil, err) + return nil + } + + val, e := toBool(result) + if e != nil { + a.err.CompareAndSwap(nil, e) + return e + } + + // Atomic AND operation: if val is false, result is always false + if !val { + a.res.Store(false) + } + + a.hasResult.Store(true) + + return nil +} + +func (a *AggLogicalAndAggregator) BatchAdd(results map[string]AggregatorResErr) error { + result := true + + for _, res := range results { + if res.Err != nil { + return a.Add(nil, res.Err) + } + + boolRes, err := toBool(res.Result) + if err != nil { + return a.Add(nil, err) + } + + result = result && boolRes + } + + return a.Add(result, nil) +} + +func (a *AggLogicalAndAggregator) AddWithKey(key string, result interface{}, err error) error { + return a.Add(result, err) +} + +func (a *AggLogicalAndAggregator) BatchSlice(results []AggregatorResErr) error { + result := true + + for _, res := range results { + if res.Err != nil { + return a.Add(nil, res.Err) + } + + boolRes, err := toBool(res.Result) + if err != nil { + return a.Add(nil, err) + } + + result = result && boolRes + } + + return a.Add(result, nil) +} + +func (a *AggLogicalAndAggregator) Result() (interface{}, error) { + err := a.err.Load() + if err != nil { + return nil, err.(error) + } + + if !a.hasResult.Load() { + return nil, ErrAndAggregation + } + return a.res.Load(), nil +} + +// AggLogicalOrAggregator performs logical OR on boolean values. +type AggLogicalOrAggregator struct { + err atomic.Value + res atomic.Bool + hasResult atomic.Bool +} + +func (a *AggLogicalOrAggregator) Add(result interface{}, err error) error { + if err != nil { + a.err.CompareAndSwap(nil, err) + return nil + } + + val, e := toBool(result) + if e != nil { + a.err.CompareAndSwap(nil, e) + return e + } + + // Atomic OR operation: if val is true, result is always true + if val { + a.res.Store(true) + } + + a.hasResult.Store(true) + + return nil +} + +func (a *AggLogicalOrAggregator) BatchAdd(results map[string]AggregatorResErr) error { + result := false + + for _, res := range results { + if res.Err != nil { + return a.Add(nil, res.Err) + } + + boolRes, err := toBool(res.Result) + if err != nil { + return a.Add(nil, err) + } + + result = result || boolRes + } + + return a.Add(result, nil) +} + +func (a *AggLogicalOrAggregator) AddWithKey(key string, result interface{}, err error) error { + return a.Add(result, err) +} + +func (a *AggLogicalOrAggregator) BatchSlice(results []AggregatorResErr) error { + result := false + + for _, res := range results { + if res.Err != nil { + return a.Add(nil, res.Err) + } + + boolRes, err := toBool(res.Result) + if err != nil { + return a.Add(nil, err) + } + + result = result || boolRes + } + + return a.Add(result, nil) +} + +func (a *AggLogicalOrAggregator) Result() (interface{}, error) { + err := a.err.Load() + if err != nil { + return nil, err.(error) + } + + if !a.hasResult.Load() { + return nil, ErrOrAggregation + } + return a.res.Load(), nil +} + +func toInt64(val interface{}) (int64, error) { + if val == nil { + return 0, nil + } + switch v := val.(type) { + case int64: + return v, nil + case int: + return int64(v), nil + case int32: + return int64(v), nil + case float64: + if v != math.Trunc(v) { + return 0, fmt.Errorf("cannot convert float %f to int64", v) + } + return int64(v), nil + default: + return 0, fmt.Errorf("cannot convert %T to int64", val) + } +} + +func toFloat64(val interface{}) (float64, error) { + if val == nil { + return 0, nil + } + + switch v := val.(type) { + case float64: + return v, nil + case int: + return float64(v), nil + case int32: + return float64(v), nil + case int64: + return float64(v), nil + case float32: + return float64(v), nil + default: + return 0, fmt.Errorf("cannot convert %T to float64", val) + } +} + +func toBool(val interface{}) (bool, error) { + if val == nil { + return false, nil + } + switch v := val.(type) { + case bool: + return v, nil + case int64: + return v != 0, nil + case int: + return v != 0, nil + default: + return false, fmt.Errorf("cannot convert %T to bool", val) + } +} + +// DefaultKeylessAggregator collects all results in an array, order doesn't matter. +type DefaultKeylessAggregator struct { + mu sync.Mutex + results []interface{} + firstErr error +} + +func (a *DefaultKeylessAggregator) add(result interface{}, err error) error { + if err != nil && a.firstErr == nil { + a.firstErr = err + return nil + } + if err == nil { + a.results = append(a.results, result) + } + return nil +} + +func (a *DefaultKeylessAggregator) Add(result interface{}, err error) error { + a.mu.Lock() + defer a.mu.Unlock() + + return a.add(result, err) +} + +func (a *DefaultKeylessAggregator) BatchAdd(results map[string]AggregatorResErr) error { + a.mu.Lock() + defer a.mu.Unlock() + + for _, res := range results { + err := a.add(res.Result, res.Err) + if err != nil { + return err + } + + if res.Err != nil { + return nil + } + } + + return nil +} + +func (a *DefaultKeylessAggregator) AddWithKey(key string, result interface{}, err error) error { + return a.Add(result, err) +} + +func (a *DefaultKeylessAggregator) BatchSlice(results []AggregatorResErr) error { + a.mu.Lock() + defer a.mu.Unlock() + + for _, res := range results { + err := a.add(res.Result, res.Err) + if err != nil { + return err + } + + if res.Err != nil { + return nil + } + } + + return nil +} + +func (a *DefaultKeylessAggregator) Result() (interface{}, error) { + a.mu.Lock() + defer a.mu.Unlock() + + if a.firstErr != nil { + return nil, a.firstErr + } + return a.results, nil +} + +// DefaultKeyedAggregator reassembles replies in the exact key order of the original request. +type DefaultKeyedAggregator struct { + mu sync.Mutex + results map[string]interface{} + keyOrder []string + firstErr error +} + +func NewDefaultKeyedAggregator(keyOrder []string) *DefaultKeyedAggregator { + return &DefaultKeyedAggregator{ + results: make(map[string]interface{}), + keyOrder: keyOrder, + } +} + +func (a *DefaultKeyedAggregator) add(result interface{}, err error) error { + if err != nil && a.firstErr == nil { + a.firstErr = err + return nil + } + // For non-keyed Add, just collect the result without ordering + if err == nil { + a.results["__default__"] = result + } + return nil +} + +func (a *DefaultKeyedAggregator) Add(result interface{}, err error) error { + a.mu.Lock() + defer a.mu.Unlock() + + return a.add(result, err) +} + +func (a *DefaultKeyedAggregator) BatchAdd(results map[string]AggregatorResErr) error { + a.mu.Lock() + defer a.mu.Unlock() + + for _, res := range results { + err := a.add(res.Result, res.Err) + if err != nil { + return err + } + + if res.Err != nil { + return nil + } + } + + return nil +} + +func (a *DefaultKeyedAggregator) addWithKey(key string, result interface{}, err error) error { + if err != nil && a.firstErr == nil { + a.firstErr = err + return nil + } + if err == nil { + a.results[key] = result + } + return nil +} + +func (a *DefaultKeyedAggregator) AddWithKey(key string, result interface{}, err error) error { + a.mu.Lock() + defer a.mu.Unlock() + + return a.addWithKey(key, result, err) +} + +func (a *DefaultKeyedAggregator) BatchAddWithKeyOrder(results map[string]AggregatorResErr, keyOrder []string) error { + a.mu.Lock() + defer a.mu.Unlock() + + a.keyOrder = keyOrder + for key, res := range results { + err := a.addWithKey(key, res.Result, res.Err) + if err != nil { + return nil + } + + if res.Err != nil { + return nil + } + } + + return nil +} + +func (a *DefaultKeyedAggregator) SetKeyOrder(keyOrder []string) { + a.mu.Lock() + defer a.mu.Unlock() + a.keyOrder = keyOrder +} + +func (a *DefaultKeyedAggregator) BatchSlice(results []AggregatorResErr) error { + a.mu.Lock() + defer a.mu.Unlock() + + for _, res := range results { + err := a.add(res.Result, res.Err) + if err != nil { + return err + } + + if res.Err != nil { + return nil + } + } + + return nil +} + +func (a *DefaultKeyedAggregator) Result() (interface{}, error) { + a.mu.Lock() + defer a.mu.Unlock() + + if a.firstErr != nil { + return nil, a.firstErr + } + + // If no explicit key order is set, return results in any order + if len(a.keyOrder) == 0 { + orderedResults := make([]interface{}, 0, len(a.results)) + for _, result := range a.results { + orderedResults = append(orderedResults, result) + } + return orderedResults, nil + } + + // Return results in the exact key order + orderedResults := make([]interface{}, len(a.keyOrder)) + for i, key := range a.keyOrder { + if result, exists := a.results[key]; exists { + orderedResults[i] = result + } + } + return orderedResults, nil +} + +// SpecialAggregator provides a registry for command-specific aggregation logic. +type SpecialAggregator struct { + mu sync.Mutex + aggregatorFunc func([]interface{}, []error) (interface{}, error) + results []interface{} + errors []error +} + +func (a *SpecialAggregator) add(result interface{}, err error) error { + a.results = append(a.results, result) + a.errors = append(a.errors, err) + return nil +} + +func (a *SpecialAggregator) Add(result interface{}, err error) error { + a.mu.Lock() + defer a.mu.Unlock() + + return a.add(result, err) +} + +func (a *SpecialAggregator) BatchAdd(results map[string]AggregatorResErr) error { + a.mu.Lock() + defer a.mu.Unlock() + + for _, res := range results { + err := a.add(res.Result, res.Err) + if err != nil { + return err + } + + if res.Err != nil { + return nil + } + } + + return nil +} + +func (a *SpecialAggregator) AddWithKey(key string, result interface{}, err error) error { + return a.Add(result, err) +} + +func (a *SpecialAggregator) BatchSlice(results []AggregatorResErr) error { + a.mu.Lock() + defer a.mu.Unlock() + + for _, res := range results { + err := a.add(res.Result, res.Err) + if err != nil { + return err + } + + if res.Err != nil { + return nil + } + } + + return nil +} + +func (a *SpecialAggregator) Result() (interface{}, error) { + a.mu.Lock() + defer a.mu.Unlock() + + if a.aggregatorFunc != nil { + return a.aggregatorFunc(a.results, a.errors) + } + // Default behavior: return first non-error result or first error + for i, err := range a.errors { + if err == nil { + return a.results[i], nil + } + } + if len(a.errors) > 0 { + return nil, a.errors[0] + } + return nil, nil +} + +// SpecialAggregatorRegistry holds custom aggregation functions for specific commands. +var SpecialAggregatorRegistry = make(map[string]func([]interface{}, []error) (interface{}, error)) + +// RegisterSpecialAggregator registers a custom aggregation function for a command. +func RegisterSpecialAggregator(cmdName string, fn func([]interface{}, []error) (interface{}, error)) { + SpecialAggregatorRegistry[cmdName] = fn +} + +// NewSpecialAggregator creates a special aggregator with command-specific logic if available. +func NewSpecialAggregator(cmdName string) *SpecialAggregator { + agg := &SpecialAggregator{} + if fn, exists := SpecialAggregatorRegistry[cmdName]; exists { + agg.aggregatorFunc = fn + } + return agg +} diff --git a/vendor/github.com/redis/go-redis/v9/internal/routing/policy.go b/vendor/github.com/redis/go-redis/v9/internal/routing/policy.go new file mode 100644 index 00000000..7f784b50 --- /dev/null +++ b/vendor/github.com/redis/go-redis/v9/internal/routing/policy.go @@ -0,0 +1,144 @@ +package routing + +import ( + "fmt" + "strings" +) + +type RequestPolicy uint8 + +const ( + ReqDefault RequestPolicy = iota + + ReqAllNodes + + ReqAllShards + + ReqMultiShard + + ReqSpecial +) + +const ( + ReadOnlyCMD string = "readonly" +) + +func (p RequestPolicy) String() string { + switch p { + case ReqDefault: + return "default" + case ReqAllNodes: + return "all_nodes" + case ReqAllShards: + return "all_shards" + case ReqMultiShard: + return "multi_shard" + case ReqSpecial: + return "special" + default: + return fmt.Sprintf("unknown_request_policy(%d)", p) + } +} + +func ParseRequestPolicy(raw string) (RequestPolicy, error) { + switch strings.ToLower(raw) { + case "", "default", "none": + return ReqDefault, nil + case "all_nodes": + return ReqAllNodes, nil + case "all_shards": + return ReqAllShards, nil + case "multi_shard": + return ReqMultiShard, nil + case "special": + return ReqSpecial, nil + default: + return ReqDefault, fmt.Errorf("routing: unknown request_policy %q", raw) + } +} + +type ResponsePolicy uint8 + +const ( + RespDefaultKeyless ResponsePolicy = iota + RespDefaultHashSlot + RespAllSucceeded + RespOneSucceeded + RespAggSum + RespAggMin + RespAggMax + RespAggLogicalAnd + RespAggLogicalOr + RespSpecial +) + +func (p ResponsePolicy) String() string { + switch p { + case RespDefaultKeyless: + return "default(keyless)" + case RespDefaultHashSlot: + return "default(hashslot)" + case RespAllSucceeded: + return "all_succeeded" + case RespOneSucceeded: + return "one_succeeded" + case RespAggSum: + return "agg_sum" + case RespAggMin: + return "agg_min" + case RespAggMax: + return "agg_max" + case RespAggLogicalAnd: + return "agg_logical_and" + case RespAggLogicalOr: + return "agg_logical_or" + case RespSpecial: + return "special" + default: + return "all_succeeded" + } +} + +func ParseResponsePolicy(raw string) (ResponsePolicy, error) { + switch strings.ToLower(raw) { + case "default(keyless)": + return RespDefaultKeyless, nil + case "default(hashslot)": + return RespDefaultHashSlot, nil + case "all_succeeded": + return RespAllSucceeded, nil + case "one_succeeded": + return RespOneSucceeded, nil + case "agg_sum": + return RespAggSum, nil + case "agg_min": + return RespAggMin, nil + case "agg_max": + return RespAggMax, nil + case "agg_logical_and": + return RespAggLogicalAnd, nil + case "agg_logical_or": + return RespAggLogicalOr, nil + case "special": + return RespSpecial, nil + default: + return RespDefaultKeyless, fmt.Errorf("routing: unknown response_policy %q", raw) + } +} + +type CommandPolicy struct { + Request RequestPolicy + Response ResponsePolicy + // Tips that are not request_policy or response_policy + // e.g nondeterministic_output, nondeterministic_output_order. + Tips map[string]string +} + +func (p *CommandPolicy) CanBeUsedInPipeline() bool { + return p.Request != ReqAllNodes && p.Request != ReqAllShards && p.Request != ReqMultiShard +} + +func (p *CommandPolicy) IsReadOnly() bool { + _, readOnly := p.Tips[ReadOnlyCMD] + return readOnly +} diff --git a/vendor/github.com/redis/go-redis/v9/internal/routing/shard_picker.go b/vendor/github.com/redis/go-redis/v9/internal/routing/shard_picker.go new file mode 100644 index 00000000..8e6228dd --- /dev/null +++ b/vendor/github.com/redis/go-redis/v9/internal/routing/shard_picker.go @@ -0,0 +1,57 @@ +package routing + +import ( + "math/rand" + "sync/atomic" +) + +// ShardPicker chooses โ€œone arbitrary shardโ€ when the request_policy is +// ReqDefault and the command has no keys. +type ShardPicker interface { + Next(total int) int // returns an index in [0,total) +} + +// StaticShardPicker always returns the same shard index. +type StaticShardPicker struct { + index int +} + +func NewStaticShardPicker(index int) *StaticShardPicker { + return &StaticShardPicker{index: index} +} + +func (p *StaticShardPicker) Next(total int) int { + if total == 0 || p.index >= total { + return 0 + } + return p.index +} + +/*โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + Round-robin (default) +โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€*/ + +type RoundRobinPicker struct { + cnt atomic.Uint32 +} + +func (p *RoundRobinPicker) Next(total int) int { + if total == 0 { + return 0 + } + i := p.cnt.Add(1) + return int(i-1) % total +} + +/*โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ + Random +โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€*/ + +type RandomPicker struct{} + +func (RandomPicker) Next(total int) int { + if total == 0 { + return 0 + } + return rand.Intn(total) +} diff --git a/vendor/github.com/redis/go-redis/v9/internal/semaphore.go b/vendor/github.com/redis/go-redis/v9/internal/semaphore.go index a1dfca5f..a7f40466 100644 --- a/vendor/github.com/redis/go-redis/v9/internal/semaphore.go +++ b/vendor/github.com/redis/go-redis/v9/internal/semaphore.go @@ -190,4 +190,4 @@ func (s *FIFOSemaphore) Close() { // Len returns the current number of acquired tokens. func (s *FIFOSemaphore) Len() int32 { return s.max - int32(len(s.tokens)) -} \ No newline at end of file +} diff --git a/vendor/github.com/redis/go-redis/v9/internal/util/atomic_max.go b/vendor/github.com/redis/go-redis/v9/internal/util/atomic_max.go new file mode 100644 index 00000000..6c621ba8 --- /dev/null +++ b/vendor/github.com/redis/go-redis/v9/internal/util/atomic_max.go @@ -0,0 +1,97 @@ +/* +ยฉ 2023โ€“present Harald Rudell (https://haraldrudell.github.io/haraldrudell/) +ISC License + +Modified by htemelski-redis +Removed the treshold, adapted it to work with float64 +*/ + +package util + +import ( + "math" + + "go.uber.org/atomic" +) + +// AtomicMax is a thread-safe max container +// - hasValue indicator true if a value was equal to or greater than threshold +// - optional threshold for minimum accepted max value +// - if threshold is not used, initialization-free +// - โ€” +// - wait-free CompareAndSwap mechanic +type AtomicMax struct { + + // value is current max + value atomic.Float64 + // whether [AtomicMax.Value] has been invoked + // with value equal or greater to threshold + hasValue atomic.Bool +} + +// NewAtomicMax returns a thread-safe max container +// - if threshold is not used, AtomicMax is initialization-free +func NewAtomicMax() (atomicMax *AtomicMax) { + m := AtomicMax{} + m.value.Store((-math.MaxFloat64)) + return &m +} + +// Value updates the container with a possible max value +// - isNewMax is true if: +// - โ€” value is equal to or greater than any threshold and +// - โ€” invocation recorded the first 0 or +// - โ€” a new max +// - upon return, Max and Max1 are guaranteed to reflect the invocation +// - the return order of concurrent Value invocations is not guaranteed +// - Thread-safe +func (m *AtomicMax) Value(value float64) (isNewMax bool) { + // -math.MaxFloat64 as max case + var hasValue0 = m.hasValue.Load() + if value == (-math.MaxFloat64) { + if !hasValue0 { + isNewMax = m.hasValue.CompareAndSwap(false, true) + } + return // -math.MaxFloat64 as max: isNewMax true for first 0 writer + } + + // check against present value + var current = m.value.Load() + if isNewMax = value > current; !isNewMax { + return // not a new max return: isNewMax false + } + + // store the new max + for { + + // try to write value to *max + if isNewMax = m.value.CompareAndSwap(current, value); isNewMax { + if !hasValue0 { + // may be rarely written multiple times + // still faster than CompareAndSwap + m.hasValue.Store(true) + } + return // new max written return: isNewMax true + } + if current = m.value.Load(); current >= value { + return // no longer a need to write return: isNewMax false + } + } +} + +// Max returns current max and value-present flag +// - hasValue true indicates that value reflects a Value invocation +// - hasValue false: value is zero-value +// - Thread-safe +func (m *AtomicMax) Max() (value float64, hasValue bool) { + if hasValue = m.hasValue.Load(); !hasValue { + return + } + value = m.value.Load() + return +} + +// Max1 returns current maximum whether zero-value or set by Value +// - threshold is ignored +// - Thread-safe +func (m *AtomicMax) Max1() (value float64) { return m.value.Load() } diff --git a/vendor/github.com/redis/go-redis/v9/internal/util/atomic_min.go b/vendor/github.com/redis/go-redis/v9/internal/util/atomic_min.go new file mode 100644 index 00000000..e33d29cc --- /dev/null +++ b/vendor/github.com/redis/go-redis/v9/internal/util/atomic_min.go @@ -0,0 +1,96 @@ +package util + +/* +ยฉ 2023โ€“present Harald Rudell (https://haraldrudell.github.io/haraldrudell/) +ISC License + +Modified by htemelski-redis +Adapted from the modified atomic_max, but with inverted logic +*/ + +import ( + "math" + + "go.uber.org/atomic" +) + +// AtomicMin is a thread-safe Min container +// - hasValue indicator true if a value was equal to or greater than threshold +// - optional threshold for minimum accepted Min value +// - โ€” +// - wait-free CompareAndSwap mechanic +type AtomicMin struct { + + // value is current Min + value atomic.Float64 + // whether [AtomicMin.Value] has been invoked + // with value equal or greater to threshold + hasValue atomic.Bool +} + +// NewAtomicMin returns a thread-safe Min container +// - if threshold is not used, AtomicMin is initialization-free +func NewAtomicMin() (atomicMin *AtomicMin) { + m := AtomicMin{} + m.value.Store(math.MaxFloat64) + return &m +} + +// Value updates the container with a possible Min value +// - isNewMin is true if: +// - โ€” value is equal to or greater than any threshold and +// - โ€” invocation recorded the first 0 or +// - โ€” a new Min +// - upon return, Min and Min1 are guaranteed to reflect the invocation +// - the return order of concurrent Value invocations is not guaranteed +// - Thread-safe +func (m *AtomicMin) Value(value float64) (isNewMin bool) { + // math.MaxFloat64 as Min case + var hasValue0 = m.hasValue.Load() + if value == math.MaxFloat64 { + if !hasValue0 { + isNewMin = m.hasValue.CompareAndSwap(false, true) + } + return // math.MaxFloat64 as Min: isNewMin true for first 0 writer + } + + // check against present value + var current = m.value.Load() + if isNewMin = value < current; !isNewMin { + return // not a new Min return: isNewMin false + } + + // store the new Min + for { + + // try to write value to *Min + if isNewMin = m.value.CompareAndSwap(current, value); isNewMin { + if !hasValue0 { + // may be rarely written multiple times + // still faster than CompareAndSwap + m.hasValue.Store(true) + } + return // new Min written return: isNewMin true + } + if current = m.value.Load(); current <= value { + return // no longer a need to write return: isNewMin false + } + } +} + +// Min returns current min and value-present flag +// - hasValue true indicates that value reflects a Value invocation +// - hasValue false: value is zero-value +// - Thread-safe +func (m *AtomicMin) Min() (value float64, hasValue bool) { + if hasValue = m.hasValue.Load(); !hasValue { + return + } + value = m.value.Load() + return +} + +// Min1 returns current Minimum whether zero-value or set by Value +// - threshold is ignored +// - Thread-safe +func (m *AtomicMin) Min1() (value float64) { return m.value.Load() } diff --git a/vendor/github.com/redis/go-redis/v9/internal/util/math.go b/vendor/github.com/redis/go-redis/v9/internal/util/math.go deleted file mode 100644 index 47027d9f..00000000 --- a/vendor/github.com/redis/go-redis/v9/internal/util/math.go +++ /dev/null @@ -1,27 +0,0 @@ -package util - -import "time" - -// Max returns the maximum of two integers -func Max(a, b int) int { - if a > b { - return a - } - return b -} - -// Min returns the minimum of two integers -func Min(a, b int) int { - if a < b { - return a - } - return b -} - -// MinDuration returns the minimum of two time.Duration values -func MinDuration(a, b time.Duration) time.Duration { - if a < b { - return a - } - return b -} diff --git a/vendor/github.com/redis/go-redis/v9/internal/util/unsafe.go b/vendor/github.com/redis/go-redis/v9/internal/util/unsafe.go index cbcd2cc0..f4c3c3f3 100644 --- a/vendor/github.com/redis/go-redis/v9/internal/util/unsafe.go +++ b/vendor/github.com/redis/go-redis/v9/internal/util/unsafe.go @@ -8,15 +8,10 @@ import ( // BytesToString converts byte slice to string. func BytesToString(b []byte) string { - return *(*string)(unsafe.Pointer(&b)) + return unsafe.String(unsafe.SliceData(b), len(b)) } // StringToBytes converts string to byte slice. func StringToBytes(s string) []byte { - return *(*[]byte)(unsafe.Pointer( - &struct { - string - Cap int - }{s, len(s)}, - )) + return unsafe.Slice(unsafe.StringData(s), len(s)) } diff --git a/vendor/github.com/redis/go-redis/v9/json.go b/vendor/github.com/redis/go-redis/v9/json.go index 2b9fa527..781cc468 100644 --- a/vendor/github.com/redis/go-redis/v9/json.go +++ b/vendor/github.com/redis/go-redis/v9/json.go @@ -68,8 +68,9 @@ var _ Cmder = (*JSONCmd)(nil) func newJSONCmd(ctx context.Context, args ...interface{}) *JSONCmd { return &JSONCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeJSON, }, } } @@ -165,6 +166,14 @@ func (cmd *JSONCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *JSONCmd) Clone() Cmder { + return &JSONCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: cmd.val, + expanded: cmd.expanded, // interface{} can be shared as it should be immutable after parsing + } +} + // ------------------------------------------- type JSONSliceCmd struct { @@ -175,8 +184,9 @@ type JSONSliceCmd struct { func NewJSONSliceCmd(ctx context.Context, args ...interface{}) *JSONSliceCmd { return &JSONSliceCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeJSONSlice, }, } } @@ -233,6 +243,18 @@ func (cmd *JSONSliceCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *JSONSliceCmd) Clone() Cmder { + var val []interface{} + if cmd.val != nil { + val = make([]interface{}, len(cmd.val)) + copy(val, cmd.val) + } + return &JSONSliceCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + /******************************************************************************* * * IntPointerSliceCmd @@ -249,8 +271,9 @@ type IntPointerSliceCmd struct { func NewIntPointerSliceCmd(ctx context.Context, args ...interface{}) *IntPointerSliceCmd { return &IntPointerSliceCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeIntPointerSlice, }, } } @@ -290,6 +313,18 @@ func (cmd *IntPointerSliceCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *IntPointerSliceCmd) Clone() Cmder { + var val []*int64 + if cmd.val != nil { + val = make([]*int64, len(cmd.val)) + copy(val, cmd.val) + } + return &IntPointerSliceCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + //------------------------------------------------------------------------------ // JSONArrAppend adds the provided JSON values to the end of the array at the given path. diff --git a/vendor/github.com/redis/go-redis/v9/list_commands.go b/vendor/github.com/redis/go-redis/v9/list_commands.go index 24a0de08..9d9e16c6 100644 --- a/vendor/github.com/redis/go-redis/v9/list_commands.go +++ b/vendor/github.com/redis/go-redis/v9/list_commands.go @@ -77,6 +77,10 @@ func (c cmdable) BRPop(ctx context.Context, timeout time.Duration, keys ...strin return cmd } +// BRPopLPush pops an element from a list, pushes it to another list and returns it. +// Blocks until an element is available or timeout is reached. +// +// Deprecated: Use BLMove with RIGHT and LEFT arguments instead as of Redis 6.2.0. func (c cmdable) BRPopLPush(ctx context.Context, source, destination string, timeout time.Duration) *StringCmd { cmd := NewStringCmd( ctx, @@ -247,6 +251,10 @@ func (c cmdable) RPopCount(ctx context.Context, key string, count int) *StringSl return cmd } +// RPopLPush atomically returns and removes the last element of the source list, +// and pushes the element as the first element of the destination list. +// +// Deprecated: Use LMove with RIGHT and LEFT arguments instead as of Redis 6.2.0. func (c cmdable) RPopLPush(ctx context.Context, source, destination string) *StringCmd { cmd := NewStringCmd(ctx, "rpoplpush", source, destination) _ = c(ctx, cmd) diff --git a/vendor/github.com/redis/go-redis/v9/maintnotifications/FEATURES.md b/vendor/github.com/redis/go-redis/v9/maintnotifications/FEATURES.md index caa4f705..03bbd391 100644 --- a/vendor/github.com/redis/go-redis/v9/maintnotifications/FEATURES.md +++ b/vendor/github.com/redis/go-redis/v9/maintnotifications/FEATURES.md @@ -156,18 +156,16 @@ Capped by: min(MaxActiveConns + 1, 5 ร— PoolSize) ### Client Support #### Currently Supported -- **Standalone Client** (`redis.NewClient`) +- **Standalone Client** (`redis.NewClient`) - Full support for MOVING, MIGRATING, MIGRATED, FAILING_OVER, FAILED_OVER notifications +- **Cluster Client** (`redis.NewClusterClient`) - Support for SMIGRATING and SMIGRATED notifications for hitless slot migrations -#### Planned Support -- **Cluster Client** (not yet supported) - #### Will Not Support - **Failover Client** (no planned support) - **Ring Client** (no planned support) ## Migration Guide -### Enabling Maintenance Notifications +### Enabling Maintenance Notifications (Standalone Client) **Before:** ```go @@ -188,6 +186,26 @@ client := redis.NewClient(&redis.Options{ }) ``` +### Enabling Hitless Upgrades (Cluster Client) + +For Redis Cluster with hitless slot migration support: + +```go +client := redis.NewClusterClient(&redis.ClusterOptions{ + Addrs: []string{"localhost:7000", "localhost:7001", "localhost:7002"}, + Protocol: 3, // RESP3 required for push notifications + MaintNotificationsConfig: &maintnotifications.Config{ + Mode: maintnotifications.ModeAuto, + RelaxedTimeout: 10 * time.Second, // Extended timeout during slot migrations + }, +}) +``` + +The cluster client automatically handles: +- **SMIGRATING**: Relaxes timeouts when slots are being migrated +- **SMIGRATED**: Triggers lazy cluster state reload when migration completes +- **SeqID Deduplication**: Same notification from multiple nodes triggers only one reload + ### Adding Monitoring ```go @@ -206,13 +224,12 @@ if manager != nil { ## Known Limitations -1. **Standalone Only**: Currently only supported in standalone Redis clients -2. **RESP3 Required**: Push notifications require RESP3 protocol -3. **Server Support**: Requires Redis Enterprise or compatible Redis with maintenance notifications -4. **Single Connection Commands**: Some commands (MULTI/EXEC, WATCH) may need special handling -5. **No Failover/Ring Client Support**: Failover and Ring clients are not supported and there are no plans to add support +1. **RESP3 Required**: Push notifications require RESP3 protocol +2. **Server Support**: Requires Redis Enterprise or compatible Redis with maintenance notifications +3. **Single Connection Commands**: Some commands (MULTI/EXEC, WATCH) may need special handling +4. **No Failover/Ring Client Support**: Failover and Ring clients are not supported and there are no plans to add support ## Future Enhancements -- Cluster client support -- Enhanced metrics and observability \ No newline at end of file +- Enhanced metrics and observability +- TTL-based cleanup for SeqID deduplication map \ No newline at end of file diff --git a/vendor/github.com/redis/go-redis/v9/maintnotifications/README.md b/vendor/github.com/redis/go-redis/v9/maintnotifications/README.md index 2ac6b9cb..2f354ef6 100644 --- a/vendor/github.com/redis/go-redis/v9/maintnotifications/README.md +++ b/vendor/github.com/redis/go-redis/v9/maintnotifications/README.md @@ -2,8 +2,14 @@ Seamless Redis connection handoffs during cluster maintenance operations without dropping connections. -## โš ๏ธ **Important Note** -**Maintenance notifications are currently supported only in standalone Redis clients.** Cluster clients (ClusterClient, FailoverClient, etc.) do not yet support this functionality. +## Cluster Support + +**Cluster notifications are now supported for ClusterClient!** + +- **SMIGRATING**: `["SMIGRATING", SeqID, slot/range, ...]` - Relaxes timeouts when slots are being migrated +- **SMIGRATED**: `["SMIGRATED", SeqID, src host:port, dst host:port, slot/range, ...]` - Reloads cluster state when slot migration completes + +**Note:** Other maintenance notifications (MOVING, MIGRATING, MIGRATED, FAILING_OVER, FAILED_OVER) are supported only in standalone Redis clients. Cluster clients support SMIGRATING and SMIGRATED for cluster-specific slot migration handling. ## Quick Start diff --git a/vendor/github.com/redis/go-redis/v9/maintnotifications/config.go b/vendor/github.com/redis/go-redis/v9/maintnotifications/config.go index cbf4f6b2..db666f3a 100644 --- a/vendor/github.com/redis/go-redis/v9/maintnotifications/config.go +++ b/vendor/github.com/redis/go-redis/v9/maintnotifications/config.go @@ -9,7 +9,6 @@ import ( "github.com/redis/go-redis/v9/internal" "github.com/redis/go-redis/v9/internal/maintnotifications/logs" - "github.com/redis/go-redis/v9/internal/util" ) // Mode represents the maintenance notifications mode @@ -261,10 +260,10 @@ func (c *Config) ApplyDefaultsWithPoolConfig(poolSize int, maxActiveConns int) * // Default: max(20x workers, PoolSize), capped by maxActiveConns or 5x pool size workerBasedSize := result.MaxWorkers * 20 poolBasedSize := poolSize - result.HandoffQueueSize = util.Max(workerBasedSize, poolBasedSize) + result.HandoffQueueSize = max(workerBasedSize, poolBasedSize) if c.HandoffQueueSize > 0 { // When explicitly set: enforce minimum of 200 - result.HandoffQueueSize = util.Max(200, c.HandoffQueueSize) + result.HandoffQueueSize = max(200, c.HandoffQueueSize) } // Cap queue size: use maxActiveConns+1 if set, otherwise 5x pool size @@ -278,7 +277,7 @@ func (c *Config) ApplyDefaultsWithPoolConfig(poolSize int, maxActiveConns int) * } else { queueCap = poolSize * 5 } - result.HandoffQueueSize = util.Min(result.HandoffQueueSize, queueCap) + result.HandoffQueueSize = min(result.HandoffQueueSize, queueCap) // Ensure minimum queue size of 2 (fallback for very small pools) if result.HandoffQueueSize < 2 { @@ -353,10 +352,10 @@ func (c *Config) applyWorkerDefaults(poolSize int) { // When not set: min(poolSize/2, max(10, poolSize/3)) - balanced scaling approach originalMaxWorkers := c.MaxWorkers - c.MaxWorkers = util.Min(poolSize/2, util.Max(10, poolSize/3)) + c.MaxWorkers = min(poolSize/2, max(10, poolSize/3)) if originalMaxWorkers != 0 { // When explicitly set: max(poolSize/2, set_value) - ensure at least poolSize/2 workers - c.MaxWorkers = util.Max(poolSize/2, originalMaxWorkers) + c.MaxWorkers = max(poolSize/2, originalMaxWorkers) } // Ensure minimum of 1 worker (fallback for very small pools) diff --git a/vendor/github.com/redis/go-redis/v9/maintnotifications/handoff_worker.go b/vendor/github.com/redis/go-redis/v9/maintnotifications/handoff_worker.go index 5b60e39b..d66542ff 100644 --- a/vendor/github.com/redis/go-redis/v9/maintnotifications/handoff_worker.go +++ b/vendor/github.com/redis/go-redis/v9/maintnotifications/handoff_worker.go @@ -13,6 +13,9 @@ import ( "github.com/redis/go-redis/v9/internal/pool" ) +// PoolNameMain is the name used for the main connection pool in metrics. +const PoolNameMain = "main" + // handoffWorkerManager manages background workers and queue for connection handoffs type handoffWorkerManager struct { // Event-driven handoff support @@ -434,6 +437,11 @@ func (hwm *handoffWorkerManager) performHandoffInternal( deadline := time.Now().Add(hwm.config.PostHandoffRelaxedDuration) conn.SetRelaxedTimeoutWithDeadline(relaxedTimeout, relaxedTimeout, deadline) + // Record relaxed timeout metric (post-handoff) + if relaxedTimeoutCallback := pool.GetMetricConnectionRelaxedTimeoutCallback(); relaxedTimeoutCallback != nil { + relaxedTimeoutCallback(ctx, 1, conn, PoolNameMain, "HANDOFF") + } + if internal.LogLevel.InfoOrAbove() { internal.Logger.Printf(context.Background(), logs.ApplyingRelaxedTimeoutDueToPostHandoff(connID, relaxedTimeout, deadline.Format("15:04:05.000"))) } @@ -462,6 +470,11 @@ func (hwm *handoffWorkerManager) performHandoffInternal( internal.Logger.Printf(ctx, logs.HandoffSucceeded(connID, newEndpoint)) // successfully completed the handoff, no retry needed and no error + // Notify metrics: connection handoff succeeded + if handoffCallback := pool.GetMetricConnectionHandoffCallback(); handoffCallback != nil { + handoffCallback(ctx, conn, PoolNameMain) + } + return false, nil } @@ -501,9 +514,9 @@ func (hwm *handoffWorkerManager) closeConnFromRequest(ctx context.Context, reque internal.Logger.Printf(ctx, logs.RemovingConnectionFromPool(conn.GetID(), err)) } } else { - err := conn.Close() // Close the connection if no pool provided - if err != nil { - internal.Logger.Printf(ctx, "redis: failed to close connection: %v", err) + errClose := conn.Close() // Close the connection if no pool provided + if errClose != nil { + internal.Logger.Printf(ctx, "redis: failed to close connection: %v", errClose) } if internal.LogLevel.WarnOrAbove() { internal.Logger.Printf(ctx, logs.NoPoolProvidedCannotRemove(conn.GetID(), err)) diff --git a/vendor/github.com/redis/go-redis/v9/maintnotifications/manager.go b/vendor/github.com/redis/go-redis/v9/maintnotifications/manager.go index 775c163e..3f9478e1 100644 --- a/vendor/github.com/redis/go-redis/v9/maintnotifications/manager.go +++ b/vendor/github.com/redis/go-redis/v9/maintnotifications/manager.go @@ -18,11 +18,13 @@ import ( // Push notification type constants for maintenance const ( - NotificationMoving = "MOVING" - NotificationMigrating = "MIGRATING" - NotificationMigrated = "MIGRATED" - NotificationFailingOver = "FAILING_OVER" - NotificationFailedOver = "FAILED_OVER" + NotificationMoving = "MOVING" // Per-connection handoff notification + NotificationMigrating = "MIGRATING" // Per-connection migration start notification - relaxes timeouts + NotificationMigrated = "MIGRATED" // Per-connection migration complete notification - clears relaxed timeouts + NotificationFailingOver = "FAILING_OVER" // Per-connection failover start notification - relaxes timeouts + NotificationFailedOver = "FAILED_OVER" // Per-connection failover complete notification - clears relaxed timeouts + NotificationSMigrating = "SMIGRATING" // Cluster slot migrating notification - relaxes timeouts + NotificationSMigrated = "SMIGRATED" // Cluster slot migrated notification - unrelaxes timeouts and triggers cluster state reload ) // maintenanceNotificationTypes contains all notification types that maintenance handles @@ -32,6 +34,8 @@ var maintenanceNotificationTypes = []string{ NotificationMigrated, NotificationFailingOver, NotificationFailedOver, + NotificationSMigrating, + NotificationSMigrated, } // NotificationHook is called before and after notification processing @@ -65,6 +69,10 @@ type Manager struct { // MOVING operation tracking - using sync.Map for better concurrent performance activeMovingOps sync.Map // map[MovingOperationKey]*MovingOperation + // SMIGRATED notification deduplication - tracks processed SeqIDs + // Multiple connections may receive the same SMIGRATED notification + processedSMigratedSeqIDs sync.Map // map[int64]bool + // Atomic state tracking - no locks needed for state queries activeOperationCount atomic.Int64 // Number of active operations closed atomic.Bool // Manager closed state @@ -73,6 +81,9 @@ type Manager struct { hooks []NotificationHook hooksMu sync.RWMutex // Protects hooks slice poolHooksRef *PoolHook + + // Cluster state reload callback for SMIGRATED notifications + clusterStateReloadCallback ClusterStateReloadCallback } // MovingOperation tracks an active MOVING operation. @@ -83,6 +94,14 @@ type MovingOperation struct { Deadline time.Time } +// ClusterStateReloadCallback is a callback function that triggers cluster state reload. +// This is used by node clients to notify their parent ClusterClient about SMIGRATED notifications. +// The hostPort parameter indicates the destination node (e.g., "127.0.0.1:6379"). +// The slotRanges parameter contains the migrated slots (e.g., ["1234", "5000-6000"]). +// Currently, implementations typically reload the entire cluster state, but in the future +// this could be optimized to reload only the specific slots. +type ClusterStateReloadCallback func(ctx context.Context, hostPort string, slotRanges []string) + // NewManager creates a new simplified manager. func NewManager(client interfaces.ClientInterface, pool pool.Pooler, config *Config) (*Manager, error) { if client == nil { @@ -223,6 +242,15 @@ func (hm *Manager) GetActiveOperationCount() int64 { return hm.activeOperationCount.Load() } +// MarkSMigratedSeqIDProcessed attempts to mark a SMIGRATED SeqID as processed. +// Returns true if this is the first time processing this SeqID (should process), +// false if it was already processed (should skip). +// This prevents duplicate processing when multiple connections receive the same notification. +func (hm *Manager) MarkSMigratedSeqIDProcessed(seqID int64) bool { + _, alreadyProcessed := hm.processedSMigratedSeqIDs.LoadOrStore(seqID, true) + return !alreadyProcessed // Return true if NOT already processed +} + // Close closes the manager. func (hm *Manager) Close() error { // Use atomic operation for thread-safe close check @@ -318,3 +346,17 @@ func (hm *Manager) AddNotificationHook(notificationHook NotificationHook) { defer hm.hooksMu.Unlock() hm.hooks = append(hm.hooks, notificationHook) } + +// SetClusterStateReloadCallback sets the callback function that will be called when a SMIGRATED notification is received. +// This allows node clients to notify their parent ClusterClient to reload cluster state. +func (hm *Manager) SetClusterStateReloadCallback(callback ClusterStateReloadCallback) { + hm.clusterStateReloadCallback = callback +} + +// TriggerClusterStateReload calls the cluster state reload callback if it's set. +// This is called when a SMIGRATED notification is received. +func (hm *Manager) TriggerClusterStateReload(ctx context.Context, hostPort string, slotRanges []string) { + if hm.clusterStateReloadCallback != nil { + hm.clusterStateReloadCallback(ctx, hostPort, slotRanges) + } +} diff --git a/vendor/github.com/redis/go-redis/v9/maintnotifications/push_notification_handler.go b/vendor/github.com/redis/go-redis/v9/maintnotifications/push_notification_handler.go index 937b4ae8..7108265b 100644 --- a/vendor/github.com/redis/go-redis/v9/maintnotifications/push_notification_handler.go +++ b/vendor/github.com/redis/go-redis/v9/maintnotifications/push_notification_handler.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "strings" "time" "github.com/redis/go-redis/v9/internal" @@ -49,11 +50,22 @@ func (snh *NotificationHandler) HandlePushNotification(ctx context.Context, hand err = snh.handleFailingOver(ctx, handlerCtx, modifiedNotification) case NotificationFailedOver: err = snh.handleFailedOver(ctx, handlerCtx, modifiedNotification) + case NotificationSMigrating: + err = snh.handleSMigrating(ctx, handlerCtx, modifiedNotification) + case NotificationSMigrated: + err = snh.handleSMigrated(ctx, handlerCtx, modifiedNotification) default: // Ignore other notification types (e.g., pub/sub messages) err = nil } + // Record maintenance notification metric + if maintenanceCallback := pool.GetMetricMaintenanceNotificationCallback(); maintenanceCallback != nil { + if conn, ok := handlerCtx.Conn.(*pool.Conn); ok { + maintenanceCallback(ctx, conn, notificationType) + } + } + // Process post-hooks with the result snh.manager.processPostHooks(ctx, handlerCtx, notificationType, modifiedNotification, err) @@ -61,7 +73,9 @@ func (snh *NotificationHandler) HandlePushNotification(ctx context.Context, hand } // handleMoving processes MOVING notifications. -// ["MOVING", seqNum, timeS, endpoint] - per-connection handoff +// MOVING indicates that a connection should be handed off to a new endpoint. +// This is a per-connection notification that triggers connection handoff. +// Expected format: ["MOVING", seqNum, timeS, endpoint] func (snh *NotificationHandler) handleMoving(ctx context.Context, handlerCtx push.NotificationHandlerContext, notification []interface{}) error { if len(notification) < 3 { internal.Logger.Printf(ctx, logs.InvalidNotification("MOVING", notification)) @@ -140,7 +154,28 @@ func (snh *NotificationHandler) handleMoving(ctx context.Context, handlerCtx pus if err := snh.markConnForHandoff(poolConn, newEndpoint, seqID, deadline); err != nil { // Log error but don't fail the goroutine - use background context since original may be cancelled internal.Logger.Printf(context.Background(), logs.FailedToMarkForHandoff(poolConn.GetID(), err)) + return + } + + // Queue the handoff immediately if the connection is idle in the pool. + // If the connection is in use (StateInUse), it will be queued when returned to the pool via OnPut. + // This handles the case where the connection is idle and might never be retrieved again. + if poolConn.GetStateMachine().GetState() == pool.StateIdle { + if snh.manager.poolHooksRef != nil && snh.manager.poolHooksRef.workerManager != nil { + if err := snh.manager.poolHooksRef.workerManager.queueHandoff(poolConn); err != nil { + internal.Logger.Printf(context.Background(), logs.FailedToQueueHandoff(poolConn.GetID(), err)) + } else { + // Mark the connection as queued for handoff to prevent it from being retrieved + // This transitions the connection to StateUnusable + if err := poolConn.MarkQueuedForHandoff(); err != nil { + internal.Logger.Printf(context.Background(), logs.FailedToMarkForHandoff(poolConn.GetID(), err)) + } else { + internal.Logger.Printf(context.Background(), logs.MarkedForHandoff(poolConn.GetID())) + } + } + } } + // If connection is StateInUse, the handoff will be queued when it's returned to the pool }) return nil } @@ -167,9 +202,10 @@ func (snh *NotificationHandler) markConnForHandoff(conn *pool.Conn, newEndpoint } // handleMigrating processes MIGRATING notifications. +// MIGRATING indicates that a connection migration is starting. +// This is a per-connection notification that applies relaxed timeouts. +// Expected format: ["MIGRATING", ...] func (snh *NotificationHandler) handleMigrating(ctx context.Context, handlerCtx push.NotificationHandlerContext, notification []interface{}) error { - // MIGRATING notifications indicate that a connection is about to be migrated - // Apply relaxed timeouts to the specific connection that received this notification if len(notification) < 2 { internal.Logger.Printf(ctx, logs.InvalidNotification("MIGRATING", notification)) return ErrInvalidNotification @@ -191,13 +227,20 @@ func (snh *NotificationHandler) handleMigrating(ctx context.Context, handlerCtx internal.Logger.Printf(ctx, logs.RelaxedTimeoutDueToNotification(conn.GetID(), "MIGRATING", snh.manager.config.RelaxedTimeout)) } conn.SetRelaxedTimeout(snh.manager.config.RelaxedTimeout, snh.manager.config.RelaxedTimeout) + + // Record relaxed timeout metric + if relaxedTimeoutCallback := pool.GetMetricConnectionRelaxedTimeoutCallback(); relaxedTimeoutCallback != nil { + relaxedTimeoutCallback(ctx, 1, conn, PoolNameMain, "MIGRATING") + } + return nil } // handleMigrated processes MIGRATED notifications. +// MIGRATED indicates that a connection migration has completed. +// This is a per-connection notification that clears relaxed timeouts. +// Expected format: ["MIGRATED", ...] func (snh *NotificationHandler) handleMigrated(ctx context.Context, handlerCtx push.NotificationHandlerContext, notification []interface{}) error { - // MIGRATED notifications indicate that a connection migration has completed - // Restore normal timeouts for the specific connection that received this notification if len(notification) < 2 { internal.Logger.Printf(ctx, logs.InvalidNotification("MIGRATED", notification)) return ErrInvalidNotification @@ -224,9 +267,10 @@ func (snh *NotificationHandler) handleMigrated(ctx context.Context, handlerCtx p } // handleFailingOver processes FAILING_OVER notifications. +// FAILING_OVER indicates that a failover is starting. +// This is a per-connection notification that applies relaxed timeouts. +// Expected format: ["FAILING_OVER", ...] func (snh *NotificationHandler) handleFailingOver(ctx context.Context, handlerCtx push.NotificationHandlerContext, notification []interface{}) error { - // FAILING_OVER notifications indicate that a connection is about to failover - // Apply relaxed timeouts to the specific connection that received this notification if len(notification) < 2 { internal.Logger.Printf(ctx, logs.InvalidNotification("FAILING_OVER", notification)) return ErrInvalidNotification @@ -249,13 +293,20 @@ func (snh *NotificationHandler) handleFailingOver(ctx context.Context, handlerCt internal.Logger.Printf(ctx, logs.RelaxedTimeoutDueToNotification(connID, "FAILING_OVER", snh.manager.config.RelaxedTimeout)) } conn.SetRelaxedTimeout(snh.manager.config.RelaxedTimeout, snh.manager.config.RelaxedTimeout) + + // Record relaxed timeout metric + if relaxedTimeoutCallback := pool.GetMetricConnectionRelaxedTimeoutCallback(); relaxedTimeoutCallback != nil { + relaxedTimeoutCallback(ctx, 1, conn, PoolNameMain, "FAILING_OVER") + } + return nil } // handleFailedOver processes FAILED_OVER notifications. +// FAILED_OVER indicates that a failover has completed. +// This is a per-connection notification that clears relaxed timeouts. +// Expected format: ["FAILED_OVER", ...] func (snh *NotificationHandler) handleFailedOver(ctx context.Context, handlerCtx push.NotificationHandlerContext, notification []interface{}) error { - // FAILED_OVER notifications indicate that a connection failover has completed - // Restore normal timeouts for the specific connection that received this notification if len(notification) < 2 { internal.Logger.Printf(ctx, logs.InvalidNotification("FAILED_OVER", notification)) return ErrInvalidNotification @@ -280,3 +331,194 @@ func (snh *NotificationHandler) handleFailedOver(ctx context.Context, handlerCtx conn.ClearRelaxedTimeout() return nil } + +// handleSMigrating processes SMIGRATING notifications. +// SMIGRATING indicates that a cluster slot is in the process of migrating to a different node. +// This is a per-connection notification that applies relaxed timeouts during slot migration. +// Expected format: ["SMIGRATING", SeqID, slot/range1-range2, ...] +func (snh *NotificationHandler) handleSMigrating(ctx context.Context, handlerCtx push.NotificationHandlerContext, notification []interface{}) error { + if len(notification) < 3 { + internal.Logger.Printf(ctx, logs.InvalidNotification("SMIGRATING", notification)) + return ErrInvalidNotification + } + + // Validate SeqID (position 1) + if _, ok := notification[1].(int64); !ok { + internal.Logger.Printf(ctx, logs.InvalidSeqIDInSMigratingNotification(notification[1])) + return ErrInvalidNotification + } + + if handlerCtx.Conn == nil { + internal.Logger.Printf(ctx, logs.NoConnectionInHandlerContext("SMIGRATING")) + return ErrInvalidNotification + } + + conn, ok := handlerCtx.Conn.(*pool.Conn) + if !ok { + internal.Logger.Printf(ctx, logs.InvalidConnectionTypeInHandlerContext("SMIGRATING", handlerCtx.Conn, handlerCtx)) + return ErrInvalidNotification + } + + // Apply relaxed timeout to this specific connection + if internal.LogLevel.InfoOrAbove() { + internal.Logger.Printf(ctx, logs.RelaxedTimeoutDueToNotification(conn.GetID(), "SMIGRATING", snh.manager.config.RelaxedTimeout)) + } + conn.SetRelaxedTimeout(snh.manager.config.RelaxedTimeout, snh.manager.config.RelaxedTimeout) + return nil +} + +// handleSMigrated processes SMIGRATED notifications. +// SMIGRATED indicates that a cluster slot has finished migrating to a different node. +// This is a cluster-level notification that triggers cluster state reload. +// +// Expected RESP3 format: +// +// >3 +// +SMIGRATED +// :SeqID +// * <- array of triplet arrays +// *3 <- each triplet is a 3-element array +// + <- node from which slots are migrating FROM +// + <- node to which slots are migrating TO +// + <- comma-separated slots and/or ranges (e.g., "123,789-1000") +// +// A source and target endpoint may appear in multiple triplets. +// The notification is only processed if the connection's NodeAddress matches one of the source endpoints. +// +// Note: Multiple connections may receive the same notification, so we deduplicate by SeqID before triggering reload. +// but we still process the notification on each connection to clear the relaxed timeout. +// In the case when the connection is from MOVED/ASK, the connection's original endpoint is not set, +// so we will not be able to match the source endpoint. In such case, we will trigger the reload callback with the first target endpoint. +func (snh *NotificationHandler) handleSMigrated(ctx context.Context, handlerCtx push.NotificationHandlerContext, notification []interface{}) error { + // Expected: ["SMIGRATED", SeqID, [[source, target, slots], ...]] + // Minimum 3 elements: SMIGRATED, SeqID, and the array of triplets + if len(notification) < 3 { + internal.Logger.Printf(ctx, logs.InvalidNotification("SMIGRATED", notification)) + return ErrInvalidNotification + } + + // Extract SeqID (position 1) + seqID, ok := notification[1].(int64) + if !ok { + internal.Logger.Printf(ctx, logs.InvalidSeqIDInSMigratedNotification(notification[1])) + return ErrInvalidNotification + } + + // Extract the array of triplets (position 2) + triplets, ok := notification[2].([]interface{}) + if !ok { + internal.Logger.Printf(ctx, logs.InvalidNotification("SMIGRATED (triplets array)", notification[2])) + return ErrInvalidNotification + } + + if len(triplets) == 0 { + internal.Logger.Printf(ctx, logs.InvalidNotification("SMIGRATED (empty triplets)", notification)) + return ErrInvalidNotification + } + + // Get the connection's endpoints to check if this notification is relevant + // We check against both nodeAddress (from CLUSTER SLOTS) and addr (after resolution) + // since we cannot be certain which format the notification source will use + var connectionNodeAddress string + var connectionAddr string + if snh.manager.options != nil { + connectionNodeAddress = snh.manager.options.GetNodeAddress() + connectionAddr = snh.manager.options.GetAddr() + } + + // Helper function to check if source matches either of our endpoints + // notification source can be either the node address or the addr after resolution + sourceMatchesConnection := func(source string) bool { + if source == connectionNodeAddress { + return true + } + if source == connectionAddr { + return true + } + return false + } + + // Parse triplets and check if any source matches our connection's endpoints + var matchingTriplets []struct { + source string + target string + slots string + } + var allSlotRanges []string + + for _, tripletInterface := range triplets { + // Each triplet should be a 3-element array: [source, target, slots] + triplet, ok := tripletInterface.([]interface{}) + if !ok || len(triplet) != 3 { + internal.Logger.Printf(ctx, logs.InvalidNotification("SMIGRATED (triplet format)", tripletInterface)) + continue + } + + // Extract source endpoint + source, ok := triplet[0].(string) + if !ok { + internal.Logger.Printf(ctx, logs.InvalidNotification("SMIGRATED (source)", triplet[0])) + continue + } + + // Extract target endpoint + target, ok := triplet[1].(string) + if !ok { + internal.Logger.Printf(ctx, logs.InvalidNotification("SMIGRATED (target)", triplet[1])) + continue + } + + // Extract slots + slots, ok := triplet[2].(string) + if !ok { + internal.Logger.Printf(ctx, logs.InvalidNotification("SMIGRATED (slots)", triplet[2])) + continue + } + + // Check if this triplet's source matches our connection's endpoints + if sourceMatchesConnection(source) { + matchingTriplets = append(matchingTriplets, struct { + source string + target string + slots string + }{source, target, slots}) + slotRanges := strings.Split(slots, ",") + allSlotRanges = append(allSlotRanges, slotRanges...) + } + } + + var connID uint64 + // Reset relaxed timeout for this specific connection + if handlerCtx.Conn != nil { + conn, ok := handlerCtx.Conn.(*pool.Conn) + if ok { + if internal.LogLevel.InfoOrAbove() { + connID = conn.GetID() + internal.Logger.Printf(ctx, logs.UnrelaxedTimeout(connID)) + } + conn.ClearRelaxedTimeout() + } + } + + // If no matching triplets, this notification is not relevant to this connection + if len(matchingTriplets) == 0 { + return nil + } + + // Deduplicate by SeqID - multiple connections may receive the same notification + // Only trigger cluster state reload once per seqID + if snh.manager.MarkSMigratedSeqIDProcessed(seqID) { + // Use the first matching triplet + target := matchingTriplets[0].target + slotsForLog := allSlotRanges + + if internal.LogLevel.InfoOrAbove() { + internal.Logger.Printf(ctx, logs.TriggeringClusterStateReload(seqID, target, slotsForLog)) + } + + // Trigger cluster state reload via callback + snh.manager.TriggerClusterStateReload(ctx, target, slotsForLog) + } + + return nil +} diff --git a/vendor/github.com/redis/go-redis/v9/options.go b/vendor/github.com/redis/go-redis/v9/options.go index 22862e6d..5db27102 100644 --- a/vendor/github.com/redis/go-redis/v9/options.go +++ b/vendor/github.com/redis/go-redis/v9/options.go @@ -11,6 +11,7 @@ import ( "sort" "strconv" "strings" + "sync/atomic" "time" "github.com/redis/go-redis/v9/auth" @@ -21,6 +22,16 @@ import ( "github.com/redis/go-redis/v9/push" ) +// poolIDCounter is a global auto-increment counter for generating unique pool IDs. +var poolIDCounter atomic.Uint64 + +// generateUniqueID generates a short unique identifier for pool names using auto-increment. +// This makes it easier to identify and track pools in order of creation. +func generateUniqueID() string { + id := poolIDCounter.Add(1) + return strconv.FormatUint(id, 10) +} + // Limiter is the interface of a rate limiter or a circuit breaker. type Limiter interface { // Allow returns nil if operation is allowed or an error otherwise. @@ -42,6 +53,17 @@ type Options struct { // Addr is the address formated as host:port Addr string + // NodeAddress is the address of the Redis node as reported by the server. + // For cluster clients, this is the exact endpoint string returned by CLUSTER SLOTS + // before any resolution or transformation (e.g., loopback replacement). + // For standalone clients, this defaults to Addr. + // + // This is used to match the source endpoint in maintenance notifications + // (e.g. SMIGRATED). + // + // Use Client.NodeAddress() to access this value. + NodeAddress string + // ClientName will execute the `CLIENT SETNAME ClientName` command for each conn. ClientName string @@ -200,6 +222,8 @@ type Options struct { // MaxActiveConns is the maximum number of connections allocated by the pool at a given time. // When zero, there is no limit on the number of connections in the pool. // If the pool is full, the next call to Get() will block until a connection is released. + // + // default: 0 MaxActiveConns int // ConnMaxIdleTime is the maximum amount of time a connection may be idle. @@ -293,6 +317,12 @@ func (opt *Options) init() { opt.Network = "tcp" } } + // For standalone clients, default NodeAddress to Addr if not set. + // This ensures maintenance notifications (SMIGRATED, etc.) can match + // the connection's endpoint even for non-cluster clients. + if opt.NodeAddress == "" { + opt.NodeAddress = opt.Addr + } if opt.Protocol < 2 { opt.Protocol = 3 } @@ -349,8 +379,8 @@ func (opt *Options) init() { opt.ConnMaxIdleTime = 30 * time.Minute } - opt.ConnMaxLifetimeJitter = util.MinDuration(opt.ConnMaxLifetimeJitter, opt.ConnMaxLifetime) - + opt.ConnMaxLifetimeJitter = min(opt.ConnMaxLifetimeJitter, opt.ConnMaxLifetime) + switch opt.MaxRetries { case -1: opt.MaxRetries = 0 @@ -661,7 +691,7 @@ func setupConnParams(u *url.URL, o *Options) (*Options, error) { o.ConnMaxLifetime = q.duration("max_conn_age") } if q.has("conn_max_lifetime_jitter") { - o.ConnMaxLifetimeJitter = util.MinDuration(q.duration("conn_max_lifetime_jitter"), o.ConnMaxLifetime) + o.ConnMaxLifetimeJitter = min(q.duration("conn_max_lifetime_jitter"), o.ConnMaxLifetime) } if q.err != nil { return nil, q.err @@ -692,6 +722,7 @@ func getUserPassword(u *url.URL) (string, string) { func newConnPool( opt *Options, dialer func(ctx context.Context, network, addr string) (net.Conn, error), + poolName string, ) (*pool.ConnPool, error) { poolSize, err := util.SafeIntToInt32(opt.PoolSize, "PoolSize") if err != nil { @@ -733,10 +764,14 @@ func newConnPool( ReadBufferSize: opt.ReadBufferSize, WriteBufferSize: opt.WriteBufferSize, PushNotificationsEnabled: opt.Protocol == 3, + Name: poolName, }), nil } -func newPubSubPool(opt *Options, dialer func(ctx context.Context, network, addr string) (net.Conn, error), +func newPubSubPool( + opt *Options, + dialer func(ctx context.Context, network, addr string) (net.Conn, error), + poolName string, ) (*pool.PubSubPool, error) { poolSize, err := util.SafeIntToInt32(opt.PoolSize, "PoolSize") if err != nil { @@ -775,5 +810,6 @@ func newPubSubPool(opt *Options, dialer func(ctx context.Context, network, addr ReadBufferSize: 32 * 1024, WriteBufferSize: 32 * 1024, PushNotificationsEnabled: opt.Protocol == 3, + Name: poolName, }, dialer), nil } diff --git a/vendor/github.com/redis/go-redis/v9/osscluster.go b/vendor/github.com/redis/go-redis/v9/osscluster.go index 79087b0a..6fb51dc2 100644 --- a/vendor/github.com/redis/go-redis/v9/osscluster.go +++ b/vendor/github.com/redis/go-redis/v9/osscluster.go @@ -3,6 +3,7 @@ package redis import ( "context" "crypto/tls" + "errors" "fmt" "math" "net" @@ -17,10 +18,11 @@ import ( "github.com/redis/go-redis/v9/auth" "github.com/redis/go-redis/v9/internal" "github.com/redis/go-redis/v9/internal/hashtag" + "github.com/redis/go-redis/v9/internal/otel" "github.com/redis/go-redis/v9/internal/pool" "github.com/redis/go-redis/v9/internal/proto" "github.com/redis/go-redis/v9/internal/rand" - "github.com/redis/go-redis/v9/internal/util" + "github.com/redis/go-redis/v9/internal/routing" "github.com/redis/go-redis/v9/maintnotifications" "github.com/redis/go-redis/v9/push" ) @@ -29,7 +31,11 @@ const ( minLatencyMeasurementInterval = 10 * time.Second ) -var errClusterNoNodes = fmt.Errorf("redis: cluster has no nodes") +var ( + errClusterNoNodes = errors.New("redis: cluster has no nodes") + errNoWatchKeys = errors.New("redis: Watch requires at least one key") + errWatchCrosslot = errors.New("redis: Watch requires all keys to be in the same slot") +) // ClusterOptions are used to configure a cluster client and should be // passed to NewClusterClient. @@ -102,12 +108,16 @@ type ClusterOptions struct { WriteTimeout time.Duration ContextTimeoutEnabled bool - PoolFIFO bool - PoolSize int // applies per cluster node and not for the whole cluster - PoolTimeout time.Duration - MinIdleConns int - MaxIdleConns int - MaxActiveConns int // applies per cluster node and not for the whole cluster + // MaxConcurrentDials is the maximum number of concurrent connection creation goroutines. + // If <= 0, defaults to PoolSize. If > PoolSize, it will be capped at PoolSize. + MaxConcurrentDials int + + PoolFIFO bool + PoolSize int // applies per cluster node and not for the whole cluster + PoolTimeout time.Duration + MinIdleConns int + MaxIdleConns int + MaxActiveConns int // applies per cluster node and not for the whole cluster ConnMaxIdleTime time.Duration ConnMaxLifetime time.Duration ConnMaxLifetimeJitter time.Duration @@ -128,6 +138,11 @@ type ClusterOptions struct { TLSConfig *tls.Config + // DisableRoutingPolicies disables the request/response policy routing system. + // When disabled, all commands use the legacy routing behavior. + // Experimental. Will be removed when shard picker is fully implemented. + DisableRoutingPolicies bool + // DisableIndentity - Disable set-lib on connect. // // default: false @@ -159,8 +174,16 @@ type ClusterOptions struct { // cluster upgrade notifications gracefully and manage connection/pool state // transitions seamlessly. Requires Protocol: 3 (RESP3) for push notifications. // If nil, maintnotifications upgrades are in "auto" mode and will be enabled if the server supports it. - // The ClusterClient does not directly work with maintnotifications, it is up to the clients in the Nodes map to work with maintnotifications. + // The ClusterClient supports SMIGRATING and SMIGRATED notifications for cluster state management. + // Individual node clients handle other maintenance notifications (MOVING, MIGRATING, etc.). MaintNotificationsConfig *maintnotifications.Config + // ShardPicker is used to pick a shard when the request_policy is + // ReqDefault and the command has no keys. + ShardPicker routing.ShardPicker + + // ClusterStateReloadInterval is the interval for reloading the cluster state. + // Default is 10 seconds. + ClusterStateReloadInterval time.Duration } func (opt *ClusterOptions) init() { @@ -175,9 +198,24 @@ func (opt *ClusterOptions) init() { opt.ReadOnly = true } + if opt.DialTimeout == 0 { + opt.DialTimeout = 5 * time.Second + } + if opt.DialerRetries == 0 { + opt.DialerRetries = 5 + } + if opt.DialerRetryTimeout == 0 { + opt.DialerRetryTimeout = 100 * time.Millisecond + } + if opt.PoolSize == 0 { opt.PoolSize = 5 * runtime.GOMAXPROCS(0) } + if opt.MaxConcurrentDials <= 0 { + opt.MaxConcurrentDials = opt.PoolSize + } else if opt.MaxConcurrentDials > opt.PoolSize { + opt.MaxConcurrentDials = opt.PoolSize + } if opt.ReadBufferSize == 0 { opt.ReadBufferSize = proto.DefaultBufferSize } @@ -221,6 +259,14 @@ func (opt *ClusterOptions) init() { if opt.FailingTimeoutSeconds == 0 { opt.FailingTimeoutSeconds = 15 } + + if opt.ShardPicker == nil { + opt.ShardPicker = &routing.RoundRobinPicker{} + } + + if opt.ClusterStateReloadInterval == 0 { + opt.ClusterStateReloadInterval = 10 * time.Second + } } // ParseClusterURL parses a URL into ClusterOptions that can be used to connect to Redis. @@ -315,17 +361,20 @@ func setupClusterQueryParams(u *url.URL, o *ClusterOptions) (*ClusterOptions, er o.MinRetryBackoff = q.duration("min_retry_backoff") o.MaxRetryBackoff = q.duration("max_retry_backoff") o.DialTimeout = q.duration("dial_timeout") + o.DialerRetries = q.int("dialer_retries") + o.DialerRetryTimeout = q.duration("dialer_retry_timeout") o.ReadTimeout = q.duration("read_timeout") o.WriteTimeout = q.duration("write_timeout") o.PoolFIFO = q.bool("pool_fifo") o.PoolSize = q.int("pool_size") + o.MaxConcurrentDials = q.int("max_concurrent_dials") o.MinIdleConns = q.int("min_idle_conns") o.MaxIdleConns = q.int("max_idle_conns") o.MaxActiveConns = q.int("max_active_conns") o.PoolTimeout = q.duration("pool_timeout") o.ConnMaxLifetime = q.duration("conn_max_lifetime") if q.has("conn_max_lifetime_jitter") { - o.ConnMaxLifetimeJitter = util.MinDuration(q.duration("conn_max_lifetime_jitter"), o.ConnMaxLifetime) + o.ConnMaxLifetimeJitter = min(q.duration("conn_max_lifetime_jitter"), o.ConnMaxLifetime) } o.ConnMaxIdleTime = q.duration("conn_max_idle_time") o.FailingTimeoutSeconds = q.int("failing_timeout_seconds") @@ -377,15 +426,17 @@ func (opt *ClusterOptions) clientOptions() *Options { MinRetryBackoff: opt.MinRetryBackoff, MaxRetryBackoff: opt.MaxRetryBackoff, - DialTimeout: opt.DialTimeout, - DialerRetries: opt.DialerRetries, - DialerRetryTimeout: opt.DialerRetryTimeout, - ReadTimeout: opt.ReadTimeout, - WriteTimeout: opt.WriteTimeout, + DialTimeout: opt.DialTimeout, + DialerRetries: opt.DialerRetries, + DialerRetryTimeout: opt.DialerRetryTimeout, + ReadTimeout: opt.ReadTimeout, + WriteTimeout: opt.WriteTimeout, + ContextTimeoutEnabled: opt.ContextTimeoutEnabled, PoolFIFO: opt.PoolFIFO, PoolSize: opt.PoolSize, + MaxConcurrentDials: opt.MaxConcurrentDials, PoolTimeout: opt.PoolTimeout, MinIdleConns: opt.MinIdleConns, MaxIdleConns: opt.MaxIdleConns, @@ -426,9 +477,10 @@ type clusterNode struct { lastLatencyMeasurement int64 // atomic } -func newClusterNode(clOpt *ClusterOptions, addr string) *clusterNode { +func newClusterNodeWithNodeAddress(clOpt *ClusterOptions, addr, nodeAddress string) *clusterNode { opt := clOpt.clientOptions() opt.Addr = addr + opt.NodeAddress = nodeAddress node := clusterNode{ Client: clOpt.NewClient(opt), } @@ -656,6 +708,10 @@ func (c *clusterNodes) GC(generation uint32) { } func (c *clusterNodes) GetOrCreate(addr string) (*clusterNode, error) { + return c.GetOrCreateWithNodeAddress(addr, "") +} + +func (c *clusterNodes) GetOrCreateWithNodeAddress(addr, nodeAddress string) (*clusterNode, error) { node, err := c.get(addr) if err != nil { return nil, err @@ -676,7 +732,7 @@ func (c *clusterNodes) GetOrCreate(addr string) (*clusterNode, error) { return node, nil } - node = newClusterNode(c.opt, addr) + node = newClusterNodeWithNodeAddress(c.opt, addr, nodeAddress) for _, fn := range c.onNewNode { fn(node.Client) } @@ -773,12 +829,14 @@ func newClusterState( for _, slot := range slots { var nodes []*clusterNode for i, slotNode := range slot.Nodes { - addr := slotNode.Addr + // slotNode.Addr is the node address from CLUSTER SLOTS + nodeAddress := slotNode.Addr + addr := nodeAddress if !isLoopbackOrigin { addr = replaceLoopbackHost(addr, originHost) } - node, err := c.nodes.GetOrCreate(addr) + node, err := c.nodes.GetOrCreateWithNodeAddress(addr, nodeAddress) if err != nil { return nil, err } @@ -945,6 +1003,29 @@ func (c *clusterState) slotRandomNode(slot int) (*clusterNode, error) { return nodes[randomNodes[0]], nil } +func (c *clusterState) slotShardPickerSlaveNode(slot int, shardPicker routing.ShardPicker) (*clusterNode, error) { + nodes := c.slotNodes(slot) + if len(nodes) == 0 { + return c.nodes.Random() + } + + // nodes[0] is master, nodes[1:] are slaves + // First, try all slave nodes for this slot using ShardPicker order + slaves := nodes[1:] + if len(slaves) > 0 { + for i := 0; i < len(slaves); i++ { + idx := shardPicker.Next(len(slaves)) + slave := slaves[idx] + if !slave.Failing() && !slave.Loading() { + return slave, nil + } + } + } + + // All slaves are failing or loading - return master + return nodes[0], nil +} + func (c *clusterState) slotNodes(slot int) []*clusterNode { i := sort.Search(len(c.slots), func(i int) bool { return c.slots[i].end >= slot @@ -964,13 +1045,16 @@ func (c *clusterState) slotNodes(slot int) []*clusterNode { type clusterStateHolder struct { load func(ctx context.Context) (*clusterState, error) - state atomic.Value - reloading uint32 // atomic + reloadInterval time.Duration + state atomic.Value + reloading uint32 // atomic + reloadPending uint32 // atomic - set to 1 when reload is requested during active reload } -func newClusterStateHolder(fn func(ctx context.Context) (*clusterState, error)) *clusterStateHolder { +func newClusterStateHolder(load func(ctx context.Context) (*clusterState, error), reloadInterval time.Duration) *clusterStateHolder { return &clusterStateHolder{ - load: fn, + load: load, + reloadInterval: reloadInterval, } } @@ -984,17 +1068,37 @@ func (c *clusterStateHolder) Reload(ctx context.Context) (*clusterState, error) } func (c *clusterStateHolder) LazyReload() { + // If already reloading, mark that another reload is pending if !atomic.CompareAndSwapUint32(&c.reloading, 0, 1) { + atomic.StoreUint32(&c.reloadPending, 1) return } + go func() { - defer atomic.StoreUint32(&c.reloading, 0) + for { + _, err := c.Reload(context.Background()) + if err != nil { + atomic.StoreUint32(&c.reloadPending, 0) + atomic.StoreUint32(&c.reloading, 0) + return + } - _, err := c.Reload(context.Background()) - if err != nil { - return + // Clear pending flag after reload completes, before cooldown + // This captures notifications that arrived during the reload + atomic.StoreUint32(&c.reloadPending, 0) + + // Wait cooldown period + time.Sleep(200 * time.Millisecond) + + // Check if another reload was requested during cooldown + if atomic.LoadUint32(&c.reloadPending) == 0 { + // No pending reload, we're done + atomic.StoreUint32(&c.reloading, 0) + return + } + + // Pending reload requested, loop to reload again } - time.Sleep(200 * time.Millisecond) }() } @@ -1005,7 +1109,7 @@ func (c *clusterStateHolder) Get(ctx context.Context) (*clusterState, error) { } state := v.(*clusterState) - if time.Since(state.createdAt) > 10*time.Second { + if time.Since(state.createdAt) > c.reloadInterval { c.LazyReload() } return state, nil @@ -1025,10 +1129,11 @@ func (c *clusterStateHolder) ReloadOrGet(ctx context.Context) (*clusterState, er // or more underlying connections. It's safe for concurrent use by // multiple goroutines. type ClusterClient struct { - opt *ClusterOptions - nodes *clusterNodes - state *clusterStateHolder - cmdsInfoCache *cmdsInfoCache + opt *ClusterOptions + nodes *clusterNodes + state *clusterStateHolder + cmdsInfoCache *cmdsInfoCache + cmdInfoResolver *commandInfoResolver cmdable hooksMixin } @@ -1036,9 +1141,6 @@ type ClusterClient struct { // NewClusterClient returns a Redis Cluster client as described in // http://redis.io/topics/cluster-spec. func NewClusterClient(opt *ClusterOptions) *ClusterClient { - if opt == nil { - panic("redis: NewClusterClient nil options") - } opt.init() c := &ClusterClient{ @@ -1046,10 +1148,13 @@ func NewClusterClient(opt *ClusterOptions) *ClusterClient { nodes: newClusterNodes(opt), } - c.state = newClusterStateHolder(c.loadState) c.cmdsInfoCache = newCmdsInfoCache(c.cmdsInfo) - c.cmdable = c.Process + c.state = newClusterStateHolder(c.loadState, opt.ClusterStateReloadInterval) + + c.SetCommandInfoResolver(NewDefaultCommandPolicyResolver()) + + c.cmdable = c.Process c.initHooks(hooks{ dial: nil, process: c.process, @@ -1057,6 +1162,26 @@ func NewClusterClient(opt *ClusterOptions) *ClusterClient { txPipeline: c.processTxPipeline, }) + // Set up SMIGRATED notification handling for cluster state reload + // When a node client receives a SMIGRATED notification, it should trigger + // cluster state reload on the parent ClusterClient + if opt.MaintNotificationsConfig != nil { + c.nodes.OnNewNode(func(nodeClient *Client) { + manager := nodeClient.GetMaintNotificationsManager() + if manager != nil { + manager.SetClusterStateReloadCallback(func(ctx context.Context, hostPort string, slotRanges []string) { + // Log the migration details for now + if internal.LogLevel.InfoOrAbove() { + internal.Logger.Printf(ctx, "cluster: slots %v migrated to %s, reloading cluster state", slotRanges, hostPort) + } + // Currently we reload the entire cluster state + // In the future, this could be optimized to reload only the specific slots + c.state.LazyReload() + }) + } + }) + } + return c } @@ -1102,7 +1227,11 @@ func (c *ClusterClient) process(ctx context.Context, cmd Cmder) error { if node == nil { var err error - node, err = c.cmdNode(ctx, cmd.Name(), slot) + if !c.opt.DisableRoutingPolicies && c.opt.ShardPicker != nil { + node, err = c.cmdNodeWithShardPicker(ctx, cmd.Name(), slot, c.opt.ShardPicker) + } else { + node, err = c.cmdNode(ctx, cmd.Name(), slot) + } if err != nil { return err } @@ -1110,13 +1239,16 @@ func (c *ClusterClient) process(ctx context.Context, cmd Cmder) error { if ask { ask = false - pipe := node.Client.Pipeline() _ = pipe.Process(ctx, NewCmd(ctx, "asking")) _ = pipe.Process(ctx, cmd) _, lastErr = pipe.Exec(ctx) } else { - lastErr = node.Client.Process(ctx, cmd) + if !c.opt.DisableRoutingPolicies { + lastErr = c.routeAndRun(ctx, cmd, node) + } else { + lastErr = node.Client.Process(ctx, cmd) + } } // If there is no error - we are done. @@ -1143,6 +1275,18 @@ func (c *ClusterClient) process(ctx context.Context, cmd Cmder) error { if moved || ask { c.state.LazyReload() + // Record error metrics + if errorCallback := pool.GetMetricErrorCallback(); errorCallback != nil { + errorType := "MOVED" + statusCode := "MOVED" + if ask { + errorType = "ASK" + statusCode = "ASK" + } + // MOVED/ASK are not internal errors, and this is the first attempt (retry count = 0) + errorCallback(ctx, errorType, nil, statusCode, false, 0) + } + var err error node, err = c.nodes.GetOrCreate(addr) if err != nil { @@ -1390,17 +1534,35 @@ func (c *ClusterClient) Pipelined(ctx context.Context, fn func(Pipeliner) error) } func (c *ClusterClient) processPipeline(ctx context.Context, cmds []Cmder) error { + // Only call time.Now() if pipeline operation duration callback is set to avoid overhead + var operationStart time.Time + pipelineOpDurationCallback := otel.GetPipelineOperationDurationCallback() + if pipelineOpDurationCallback != nil { + operationStart = time.Now() + } + totalAttempts := 0 + cmdsMap := newCmdsMap() if err := c.mapCmdsByNode(ctx, cmdsMap, cmds); err != nil { setCmdsErr(cmds, err) + if pipelineOpDurationCallback != nil { + operationDuration := time.Since(operationStart) + pipelineOpDurationCallback(ctx, operationDuration, "PIPELINE", len(cmds), 1, err, nil, 0) + } return err } + var lastErr error for attempt := 0; attempt <= c.opt.MaxRedirects; attempt++ { + totalAttempts++ if attempt > 0 { if err := internal.Sleep(ctx, c.retryBackoff(attempt)); err != nil { setCmdsErr(cmds, err) + if pipelineOpDurationCallback != nil { + operationDuration := time.Since(operationStart) + pipelineOpDurationCallback(ctx, operationDuration, "PIPELINE", len(cmds), totalAttempts, err, nil, 0) + } return err } } @@ -1421,6 +1583,17 @@ func (c *ClusterClient) processPipeline(ctx context.Context, cmds []Cmder) error break } cmdsMap = failedCmds + lastErr = cmdsFirstErr(cmds) + } + + // Record pipeline operation duration + if pipelineOpDurationCallback != nil { + operationDuration := time.Since(operationStart) + finalErr := cmdsFirstErr(cmds) + if finalErr == nil { + finalErr = lastErr + } + pipelineOpDurationCallback(ctx, operationDuration, "PIPELINE", len(cmds), totalAttempts, finalErr, nil, 0) } return cmdsFirstErr(cmds) @@ -1432,16 +1605,33 @@ func (c *ClusterClient) mapCmdsByNode(ctx context.Context, cmdsMap *cmdsMap, cmd return err } - preferredRandomSlot := -1 if c.opt.ReadOnly && c.cmdsAreReadOnly(ctx, cmds) { for _, cmd := range cmds { - slot := c.cmdSlot(cmd, preferredRandomSlot) - if preferredRandomSlot == -1 { - preferredRandomSlot = slot + var policy *routing.CommandPolicy + if c.cmdInfoResolver != nil { + policy = c.cmdInfoResolver.GetCommandPolicy(ctx, cmd) } - node, err := c.slotReadOnlyNode(state, slot) - if err != nil { - return err + if policy != nil && !policy.CanBeUsedInPipeline() { + return fmt.Errorf( + "redis: cannot pipeline command %q with request policy ReqAllNodes/ReqAllShards/ReqMultiShard; Note: This behavior is subject to change in the future", cmd.Name(), + ) + } + slot := c.cmdSlot(cmd, -1) + var node *clusterNode + // For keyless commands (slot == -1), use ShardPicker if routing policies are enabled + if slot == -1 && !c.opt.DisableRoutingPolicies && c.opt.ShardPicker != nil { + if len(state.Masters) == 0 { + return errClusterNoNodes + } + // For read-only keyless commands, pick from all nodes (masters + slaves) + allNodes := append(state.Masters, state.Slaves...) + idx := c.opt.ShardPicker.Next(len(allNodes)) + node = allNodes[idx] + } else { + node, err = c.slotReadOnlyNode(state, slot) + if err != nil { + return err + } } cmdsMap.Add(node, cmd) } @@ -1449,13 +1639,29 @@ func (c *ClusterClient) mapCmdsByNode(ctx context.Context, cmdsMap *cmdsMap, cmd } for _, cmd := range cmds { - slot := c.cmdSlot(cmd, preferredRandomSlot) - if preferredRandomSlot == -1 { - preferredRandomSlot = slot - } - node, err := state.slotMasterNode(slot) - if err != nil { - return err + var policy *routing.CommandPolicy + if c.cmdInfoResolver != nil { + policy = c.cmdInfoResolver.GetCommandPolicy(ctx, cmd) + } + if policy != nil && !policy.CanBeUsedInPipeline() { + return fmt.Errorf( + "redis: cannot pipeline command %q with request policy ReqAllNodes/ReqAllShards/ReqMultiShard; Note: This behavior is subject to change in the future", cmd.Name(), + ) + } + slot := c.cmdSlot(cmd, -1) + var node *clusterNode + // For keyless commands (slot == -1), use ShardPicker if routing policies are enabled + if slot == -1 && !c.opt.DisableRoutingPolicies && c.opt.ShardPicker != nil { + if len(state.Masters) == 0 { + return errClusterNoNodes + } + idx := c.opt.ShardPicker.Next(len(state.Masters)) + node = state.Masters[idx] + } else { + node, err = state.slotMasterNode(slot) + if err != nil { + return err + } } cmdsMap.Add(node, cmd) } @@ -1601,6 +1807,14 @@ func (c *ClusterClient) TxPipelined(ctx context.Context, fn func(Pipeliner) erro } func (c *ClusterClient) processTxPipeline(ctx context.Context, cmds []Cmder) error { + // Only call time.Now() if pipeline operation duration callback is set to avoid overhead + var operationStart time.Time + pipelineOpDurationCallback := otel.GetPipelineOperationDurationCallback() + if pipelineOpDurationCallback != nil { + operationStart = time.Now() + } + totalAttempts := 0 + // Trim multi .. exec. cmds = cmds[1 : len(cmds)-1] @@ -1611,10 +1825,14 @@ func (c *ClusterClient) processTxPipeline(ctx context.Context, cmds []Cmder) err state, err := c.state.Get(ctx) if err != nil { setCmdsErr(cmds, err) + if pipelineOpDurationCallback != nil { + operationDuration := time.Since(operationStart) + pipelineOpDurationCallback(ctx, operationDuration, "MULTI", len(cmds), 1, err, nil, 0) + } return err } - keyedCmdsBySlot := c.slottedKeyedCommands(cmds) + keyedCmdsBySlot := c.slottedKeyedCommands(ctx, cmds) slot := -1 switch len(keyedCmdsBySlot) { case 0: @@ -1627,20 +1845,34 @@ func (c *ClusterClient) processTxPipeline(ctx context.Context, cmds []Cmder) err default: // TxPipeline does not support cross slot transaction. setCmdsErr(cmds, ErrCrossSlot) + if pipelineOpDurationCallback != nil { + operationDuration := time.Since(operationStart) + pipelineOpDurationCallback(ctx, operationDuration, "MULTI", len(cmds), 1, ErrCrossSlot, nil, 0) + } return ErrCrossSlot } node, err := state.slotMasterNode(slot) if err != nil { setCmdsErr(cmds, err) + if pipelineOpDurationCallback != nil { + operationDuration := time.Since(operationStart) + pipelineOpDurationCallback(ctx, operationDuration, "MULTI", len(cmds), 1, err, nil, 0) + } return err } + var lastErr error cmdsMap := map[*clusterNode][]Cmder{node: cmds} for attempt := 0; attempt <= c.opt.MaxRedirects; attempt++ { + totalAttempts++ if attempt > 0 { if err := internal.Sleep(ctx, c.retryBackoff(attempt)); err != nil { setCmdsErr(cmds, err) + if pipelineOpDurationCallback != nil { + operationDuration := time.Since(operationStart) + pipelineOpDurationCallback(ctx, operationDuration, "MULTI", len(cmds), totalAttempts, err, nil, 0) + } return err } } @@ -1661,6 +1893,16 @@ func (c *ClusterClient) processTxPipeline(ctx context.Context, cmds []Cmder) err break } cmdsMap = failedCmds.m + lastErr = cmdsFirstErr(cmds) + } + + if pipelineOpDurationCallback != nil { + operationDuration := time.Since(operationStart) + finalErr := cmdsFirstErr(cmds) + if finalErr == nil { + finalErr = lastErr + } + pipelineOpDurationCallback(ctx, operationDuration, "MULTI", len(cmds), totalAttempts, finalErr, nil, 0) } return cmdsFirstErr(cmds) @@ -1668,18 +1910,18 @@ func (c *ClusterClient) processTxPipeline(ctx context.Context, cmds []Cmder) err // slottedKeyedCommands returns a map of slot to commands taking into account // only commands that have keys. -func (c *ClusterClient) slottedKeyedCommands(cmds []Cmder) map[int][]Cmder { +func (c *ClusterClient) slottedKeyedCommands(ctx context.Context, cmds []Cmder) map[int][]Cmder { cmdsSlots := map[int][]Cmder{} - preferredRandomSlot := -1 + prefferedRandomSlot := -1 for _, cmd := range cmds { if cmdFirstKeyPos(cmd) == 0 { continue } - slot := c.cmdSlot(cmd, preferredRandomSlot) - if preferredRandomSlot == -1 { - preferredRandomSlot = slot + slot := c.cmdSlot(cmd, prefferedRandomSlot) + if prefferedRandomSlot == -1 { + prefferedRandomSlot = slot } cmdsSlots[slot] = append(cmdsSlots[slot], cmd) @@ -1838,14 +2080,13 @@ func (c *ClusterClient) cmdsMoved( func (c *ClusterClient) Watch(ctx context.Context, fn func(*Tx) error, keys ...string) error { if len(keys) == 0 { - return fmt.Errorf("redis: Watch requires at least one key") + return errNoWatchKeys } slot := hashtag.Slot(keys[0]) for _, key := range keys[1:] { if hashtag.Slot(key) != slot { - err := fmt.Errorf("redis: Watch requires all keys to be in the same slot") - return err + return errWatchCrosslot } } @@ -2014,7 +2255,6 @@ func (c *ClusterClient) cmdsInfo(ctx context.Context) (map[string]*CommandInfo, for _, idx := range perm { addr := addrs[idx] - node, err := c.nodes.GetOrCreate(addr) if err != nil { if firstErr == nil { @@ -2027,6 +2267,7 @@ func (c *ClusterClient) cmdsInfo(ctx context.Context) (map[string]*CommandInfo, if err == nil { return info, nil } + if firstErr == nil { firstErr = err } @@ -2038,35 +2279,48 @@ func (c *ClusterClient) cmdsInfo(ctx context.Context) (map[string]*CommandInfo, return nil, firstErr } +// cmdInfo will fetch and cache the command policies after the first execution func (c *ClusterClient) cmdInfo(ctx context.Context, name string) *CommandInfo { - cmdsInfo, err := c.cmdsInfoCache.Get(ctx) + // Use a separate context that won't be canceled to ensure command info lookup + // doesn't fail due to original context cancellation + cmdInfoCtx := c.context(ctx) + if c.opt.ContextTimeoutEnabled && ctx != nil { + // If context timeout is enabled, still use a reasonable timeout + var cancel context.CancelFunc + cmdInfoCtx, cancel = context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + } + + cmdsInfo, err := c.cmdsInfoCache.Get(cmdInfoCtx) if err != nil { - internal.Logger.Printf(context.TODO(), "getting command info: %s", err) + internal.Logger.Printf(cmdInfoCtx, "getting command info: %s", err) return nil } info := cmdsInfo[name] if info == nil { - internal.Logger.Printf(context.TODO(), "info for cmd=%s not found", name) + internal.Logger.Printf(cmdInfoCtx, "info for cmd=%s not found", name) } + return info } -func (c *ClusterClient) cmdSlot(cmd Cmder, preferredRandomSlot int) int { +func (c *ClusterClient) cmdSlot(cmd Cmder, prefferedSlot int) int { args := cmd.Args() if args[0] == "cluster" && (args[1] == "getkeysinslot" || args[1] == "countkeysinslot") { return args[2].(int) } - return cmdSlot(cmd, cmdFirstKeyPos(cmd), preferredRandomSlot) + return cmdSlot(cmd, cmdFirstKeyPos(cmd), prefferedSlot) } -func cmdSlot(cmd Cmder, pos int, preferredRandomSlot int) int { +func cmdSlot(cmd Cmder, pos int, prefferedRandomSlot int) int { if pos == 0 { - if preferredRandomSlot != -1 { - return preferredRandomSlot + if prefferedRandomSlot != -1 { + return prefferedRandomSlot } - return hashtag.RandomSlot() + // Return -1 for keyless commands to signal that ShardPicker should be used + return -1 } firstKey := cmd.stringArg(pos) return hashtag.Slot(firstKey) @@ -2091,6 +2345,36 @@ func (c *ClusterClient) cmdNode( return state.slotMasterNode(slot) } +func (c *ClusterClient) cmdNodeWithShardPicker( + ctx context.Context, + cmdName string, + slot int, + shardPicker routing.ShardPicker, +) (*clusterNode, error) { + state, err := c.state.Get(ctx) + if err != nil { + return nil, err + } + + // For keyless commands (slot == -1), use ShardPicker to select a shard + // This respects the user's configured ShardPicker policy + if slot == -1 { + if len(state.Masters) == 0 { + return nil, errClusterNoNodes + } + idx := shardPicker.Next(len(state.Masters)) + return state.Masters[idx], nil + } + + if c.opt.ReadOnly { + cmdInfo := c.cmdInfo(ctx, cmdName) + if cmdInfo != nil && cmdInfo.ReadOnly { + return c.slotReadOnlyNode(state, slot) + } + } + return state.slotMasterNode(slot) +} + func (c *ClusterClient) slotReadOnlyNode(state *clusterState, slot int) (*clusterNode, error) { if c.opt.RouteByLatency { return state.slotClosestNode(slot) @@ -2098,6 +2382,11 @@ func (c *ClusterClient) slotReadOnlyNode(state *clusterState, slot int) (*cluste if c.opt.RouteRandomly { return state.slotRandomNode(slot) } + + if c.opt.ShardPicker != nil { + return state.slotShardPickerSlaveNode(slot, c.opt.ShardPicker) + } + return state.slotSlaveNode(slot) } @@ -2145,6 +2434,31 @@ func (c *ClusterClient) context(ctx context.Context) context.Context { return context.Background() } +func (c *ClusterClient) GetResolver() *commandInfoResolver { + return c.cmdInfoResolver +} + +func (c *ClusterClient) SetCommandInfoResolver(cmdInfoResolver *commandInfoResolver) { + c.cmdInfoResolver = cmdInfoResolver +} + +// extractCommandInfo retrieves the routing policy for a command +func (c *ClusterClient) extractCommandInfo(ctx context.Context, cmd Cmder) *routing.CommandPolicy { + if cmdInfo := c.cmdInfo(ctx, cmd.Name()); cmdInfo != nil && cmdInfo.CommandPolicy != nil { + return cmdInfo.CommandPolicy + } + + return nil +} + +// NewDynamicResolver returns a CommandInfoResolver +// that uses the underlying cmdInfo cache to resolve the policies +func (c *ClusterClient) NewDynamicResolver() *commandInfoResolver { + return &commandInfoResolver{ + resolveFunc: c.extractCommandInfo, + } +} + func appendIfNotExist[T comparable](vals []T, newVal T) []T { for _, v := range vals { if v == newVal { diff --git a/vendor/github.com/redis/go-redis/v9/osscluster_router.go b/vendor/github.com/redis/go-redis/v9/osscluster_router.go new file mode 100644 index 00000000..3b001fef --- /dev/null +++ b/vendor/github.com/redis/go-redis/v9/osscluster_router.go @@ -0,0 +1,992 @@ +package redis + +import ( + "context" + "errors" + "fmt" + "reflect" + "sync" + "time" + + "github.com/redis/go-redis/v9/internal/hashtag" + "github.com/redis/go-redis/v9/internal/routing" +) + +var ( + errInvalidCmdPointer = errors.New("redis: invalid command pointer") + errNoCmdsToAggregate = errors.New("redis: no commands to aggregate") + errNoResToAggregate = errors.New("redis: no results to aggregate") + errInvalidCursorCmdArgsCount = errors.New("redis: FT.CURSOR command requires at least 3 arguments") + errInvalidCursorIdType = errors.New("redis: invalid cursor ID type") +) + +// slotResult represents the result of executing a command on a specific slot +type slotResult struct { + cmd Cmder + keys []string + err error +} + +// routeAndRun routes a command to the appropriate cluster nodes and executes it +func (c *ClusterClient) routeAndRun(ctx context.Context, cmd Cmder, node *clusterNode) error { + var policy *routing.CommandPolicy + if c.cmdInfoResolver != nil { + policy = c.cmdInfoResolver.GetCommandPolicy(ctx, cmd) + } + + // Set stepCount from cmdInfo if not already set + if cmd.stepCount() == 0 { + if cmdInfo := c.cmdInfo(ctx, cmd.Name()); cmdInfo != nil && cmdInfo.StepCount > 0 { + cmd.SetStepCount(cmdInfo.StepCount) + } + } + + if policy == nil { + return c.executeDefault(ctx, cmd, policy, node) + } + switch policy.Request { + case routing.ReqAllNodes: + return c.executeOnAllNodes(ctx, cmd, policy) + case routing.ReqAllShards: + return c.executeOnAllShards(ctx, cmd, policy) + case routing.ReqMultiShard: + return c.executeMultiShard(ctx, cmd, policy) + case routing.ReqSpecial: + return c.executeSpecialCommand(ctx, cmd, policy, node) + default: + return c.executeDefault(ctx, cmd, policy, node) + } +} + +// executeDefault handles standard command routing based on keys +func (c *ClusterClient) executeDefault(ctx context.Context, cmd Cmder, policy *routing.CommandPolicy, node *clusterNode) error { + if policy != nil && !c.hasKeys(cmd) { + if c.readOnlyEnabled() && policy.IsReadOnly() { + return c.executeOnArbitraryNode(ctx, cmd) + } + } + + return node.Client.Process(ctx, cmd) +} + +// executeOnArbitraryNode routes command to an arbitrary node +func (c *ClusterClient) executeOnArbitraryNode(ctx context.Context, cmd Cmder) error { + node := c.pickArbitraryNode(ctx) + if node == nil { + return errClusterNoNodes + } + return node.Client.Process(ctx, cmd) +} + +// executeOnAllNodes executes command on all nodes (masters and replicas) +func (c *ClusterClient) executeOnAllNodes(ctx context.Context, cmd Cmder, policy *routing.CommandPolicy) error { + state, err := c.state.Get(ctx) + if err != nil { + return err + } + + nodes := append(state.Masters, state.Slaves...) + if len(nodes) == 0 { + return errClusterNoNodes + } + + return c.executeParallel(ctx, cmd, nodes, policy) +} + +// executeOnAllShards executes command on all master shards +func (c *ClusterClient) executeOnAllShards(ctx context.Context, cmd Cmder, policy *routing.CommandPolicy) error { + state, err := c.state.Get(ctx) + if err != nil { + return err + } + + if len(state.Masters) == 0 { + return errClusterNoNodes + } + + return c.executeParallel(ctx, cmd, state.Masters, policy) +} + +// executeMultiShard handles commands that operate on multiple keys across shards +func (c *ClusterClient) executeMultiShard(ctx context.Context, cmd Cmder, policy *routing.CommandPolicy) error { + args := cmd.Args() + firstKeyPos := int(cmdFirstKeyPos(cmd)) + stepCount := int(cmd.stepCount()) + if stepCount == 0 { + stepCount = 1 // Default to 1 if not set + } + + if firstKeyPos == 0 || firstKeyPos >= len(args) { + return fmt.Errorf("redis: multi-shard command %s has no key arguments", cmd.Name()) + } + + // Group keys by slot + slotMap := make(map[int][]string) + keyOrder := make([]string, 0) + + for i := firstKeyPos; i < len(args); i += stepCount { + key, ok := args[i].(string) + if !ok { + return fmt.Errorf("redis: non-string key at position %d: %v", i, args[i]) + } + + slot := hashtag.Slot(key) + slotMap[slot] = append(slotMap[slot], key) + for j := 1; j < stepCount; j++ { + if i+j >= len(args) { + break + } + slotMap[slot] = append(slotMap[slot], args[i+j].(string)) + } + keyOrder = append(keyOrder, key) + } + + return c.executeMultiSlot(ctx, cmd, slotMap, keyOrder, policy) +} + +// executeMultiSlot executes commands across multiple slots concurrently +func (c *ClusterClient) executeMultiSlot(ctx context.Context, cmd Cmder, slotMap map[int][]string, keyOrder []string, policy *routing.CommandPolicy) error { + results := make(chan slotResult, len(slotMap)) + var wg sync.WaitGroup + + // Execute on each slot concurrently + for slot, keys := range slotMap { + wg.Add(1) + go func(slot int, keys []string) { + defer wg.Done() + + node, err := c.cmdNodeWithShardPicker(ctx, cmd.Name(), slot, c.opt.ShardPicker) + if err != nil { + results <- slotResult{nil, keys, err} + return + } + + // Create a command for this specific slot's keys + subCmd := c.createSlotSpecificCommand(ctx, cmd, keys) + err = node.Client.Process(ctx, subCmd) + results <- slotResult{subCmd, keys, err} + }(slot, keys) + } + + go func() { + wg.Wait() + close(results) + }() + + return c.aggregateMultiSlotResults(ctx, cmd, results, keyOrder, policy) +} + +// createSlotSpecificCommand creates a new command for a specific slot's keys +func (c *ClusterClient) createSlotSpecificCommand(ctx context.Context, originalCmd Cmder, keys []string) Cmder { + originalArgs := originalCmd.Args() + firstKeyPos := int(cmdFirstKeyPos(originalCmd)) + + // Build new args with only the specified keys + newArgs := make([]interface{}, 0, firstKeyPos+len(keys)) + + // Copy command name and arguments before the keys + newArgs = append(newArgs, originalArgs[:firstKeyPos]...) + + // Add the slot-specific keys + for _, key := range keys { + newArgs = append(newArgs, key) + } + + // Create a new command of the same type using the helper function + return createCommandByType(ctx, originalCmd.GetCmdType(), newArgs...) +} + +// createCommandByType creates a new command of the specified type with the given arguments +func createCommandByType(ctx context.Context, cmdType CmdType, args ...interface{}) Cmder { + switch cmdType { + case CmdTypeString: + return NewStringCmd(ctx, args...) + case CmdTypeInt: + return NewIntCmd(ctx, args...) + case CmdTypeBool: + return NewBoolCmd(ctx, args...) + case CmdTypeFloat: + return NewFloatCmd(ctx, args...) + case CmdTypeStringSlice: + return NewStringSliceCmd(ctx, args...) + case CmdTypeIntSlice: + return NewIntSliceCmd(ctx, args...) + case CmdTypeFloatSlice: + return NewFloatSliceCmd(ctx, args...) + case CmdTypeBoolSlice: + return NewBoolSliceCmd(ctx, args...) + case CmdTypeStatus: + return NewStatusCmd(ctx, args...) + case CmdTypeTime: + return NewTimeCmd(ctx, args...) + case CmdTypeMapStringString: + return NewMapStringStringCmd(ctx, args...) + case CmdTypeMapStringInt: + return NewMapStringIntCmd(ctx, args...) + case CmdTypeMapStringInterface: + return NewMapStringInterfaceCmd(ctx, args...) + case CmdTypeMapStringInterfaceSlice: + return NewMapStringInterfaceSliceCmd(ctx, args...) + case CmdTypeSlice: + return NewSliceCmd(ctx, args...) + case CmdTypeStringStructMap: + return NewStringStructMapCmd(ctx, args...) + case CmdTypeXMessageSlice: + return NewXMessageSliceCmd(ctx, args...) + case CmdTypeXStreamSlice: + return NewXStreamSliceCmd(ctx, args...) + case CmdTypeXPending: + return NewXPendingCmd(ctx, args...) + case CmdTypeXPendingExt: + return NewXPendingExtCmd(ctx, args...) + case CmdTypeXAutoClaim: + return NewXAutoClaimCmd(ctx, args...) + case CmdTypeXAutoClaimJustID: + return NewXAutoClaimJustIDCmd(ctx, args...) + case CmdTypeXInfoStreamFull: + return NewXInfoStreamFullCmd(ctx, args...) + case CmdTypeZSlice: + return NewZSliceCmd(ctx, args...) + case CmdTypeZWithKey: + return NewZWithKeyCmd(ctx, args...) + case CmdTypeClusterSlots: + return NewClusterSlotsCmd(ctx, args...) + case CmdTypeGeoPos: + return NewGeoPosCmd(ctx, args...) + case CmdTypeCommandsInfo: + return NewCommandsInfoCmd(ctx, args...) + case CmdTypeSlowLog: + return NewSlowLogCmd(ctx, args...) + case CmdTypeKeyValues: + return NewKeyValuesCmd(ctx, args...) + case CmdTypeZSliceWithKey: + return NewZSliceWithKeyCmd(ctx, args...) + case CmdTypeFunctionList: + return NewFunctionListCmd(ctx, args...) + case CmdTypeFunctionStats: + return NewFunctionStatsCmd(ctx, args...) + case CmdTypeKeyFlags: + return NewKeyFlagsCmd(ctx, args...) + case CmdTypeDuration: + return NewDurationCmd(ctx, time.Millisecond, args...) + } + return NewCmd(ctx, args...) +} + +// executeSpecialCommand handles commands with special routing requirements +func (c *ClusterClient) executeSpecialCommand(ctx context.Context, cmd Cmder, policy *routing.CommandPolicy, node *clusterNode) error { + switch cmd.Name() { + case "ft.cursor": + return c.executeCursorCommand(ctx, cmd) + default: + return c.executeDefault(ctx, cmd, policy, node) + } +} + +// executeCursorCommand handles FT.CURSOR commands with sticky routing +func (c *ClusterClient) executeCursorCommand(ctx context.Context, cmd Cmder) error { + args := cmd.Args() + if len(args) < 4 { + return errInvalidCursorCmdArgsCount + } + + cursorID, ok := args[3].(string) + if !ok { + return errInvalidCursorIdType + } + + // Route based on cursor ID to maintain stickiness + slot := hashtag.Slot(cursorID) + node, err := c.cmdNodeWithShardPicker(ctx, cmd.Name(), slot, c.opt.ShardPicker) + if err != nil { + return err + } + + return node.Client.Process(ctx, cmd) +} + +// executeParallel executes a command on multiple nodes concurrently +func (c *ClusterClient) executeParallel(ctx context.Context, cmd Cmder, nodes []*clusterNode, policy *routing.CommandPolicy) error { + if len(nodes) == 0 { + return errClusterNoNodes + } + + if len(nodes) == 1 { + return nodes[0].Client.Process(ctx, cmd) + } + + type nodeResult struct { + cmd Cmder + err error + } + + results := make(chan nodeResult, len(nodes)) + var wg sync.WaitGroup + + for _, node := range nodes { + wg.Add(1) + go func(n *clusterNode) { + defer wg.Done() + cmdCopy := cmd.Clone() + err := n.Client.Process(ctx, cmdCopy) + results <- nodeResult{cmdCopy, err} + }(node) + } + + go func() { + wg.Wait() + close(results) + }() + + // Collect results and check for errors + cmds := make([]Cmder, 0, len(nodes)) + var firstErr error + + for result := range results { + if result.err != nil && firstErr == nil { + firstErr = result.err + } + cmds = append(cmds, result.cmd) + } + + // If there was an error and no policy specified, fail fast + if firstErr != nil && (policy == nil || policy.Response == routing.RespDefaultKeyless) { + cmd.SetErr(firstErr) + return firstErr + } + + return c.aggregateResponses(cmd, cmds, policy) +} + +// aggregateMultiSlotResults aggregates results from multi-slot execution +func (c *ClusterClient) aggregateMultiSlotResults(ctx context.Context, cmd Cmder, results <-chan slotResult, keyOrder []string, policy *routing.CommandPolicy) error { + keyedResults := make(map[string]routing.AggregatorResErr) + var firstErr error + + for result := range results { + if result.err != nil && firstErr == nil { + firstErr = result.err + } + if result.cmd != nil && result.err == nil { + value, err := ExtractCommandValue(result.cmd) + + // Check if the result is a slice (e.g., from MGET) + if sliceValue, ok := value.([]interface{}); ok { + // Map each element to its corresponding key + for i, key := range result.keys { + if i < len(sliceValue) { + keyedResults[key] = routing.AggregatorResErr{Result: sliceValue[i], Err: err} + } else { + keyedResults[key] = routing.AggregatorResErr{Result: nil, Err: err} + } + } + } else { + // For non-slice results, map the entire result to each key + for _, key := range result.keys { + keyedResults[key] = routing.AggregatorResErr{Result: value, Err: err} + } + } + } + + // TODO: return multiple errors by order when we will implement multiple errors returning + if result.err != nil { + firstErr = result.err + } + } + + return c.aggregateKeyedValues(cmd, keyedResults, keyOrder, policy) +} + +// aggregateKeyedValues aggregates individual key-value pairs while preserving key order +func (c *ClusterClient) aggregateKeyedValues(cmd Cmder, keyedResults map[string]routing.AggregatorResErr, keyOrder []string, policy *routing.CommandPolicy) error { + if len(keyedResults) == 0 { + return errNoResToAggregate + } + + aggregator := c.createAggregator(policy, cmd, true) + + // Set key order for keyed aggregators + var keyedAgg *routing.DefaultKeyedAggregator + var isKeyedAgg bool + var err error + if keyedAgg, isKeyedAgg = aggregator.(*routing.DefaultKeyedAggregator); isKeyedAgg { + err = keyedAgg.BatchAddWithKeyOrder(keyedResults, keyOrder) + } else { + err = aggregator.BatchAdd(keyedResults) + } + + if err != nil { + return err + } + + return c.finishAggregation(cmd, aggregator) +} + +// aggregateResponses aggregates multiple shard responses +func (c *ClusterClient) aggregateResponses(cmd Cmder, cmds []Cmder, policy *routing.CommandPolicy) error { + if len(cmds) == 0 { + return errNoCmdsToAggregate + } + + if len(cmds) == 1 { + shardCmd := cmds[0] + if err := shardCmd.Err(); err != nil { + cmd.SetErr(err) + return err + } + value, _ := ExtractCommandValue(shardCmd) + return c.setCommandValue(cmd, value) + } + + aggregator := c.createAggregator(policy, cmd, false) + + batchWithErrs := []routing.AggregatorResErr{} + // Add all results to aggregator + for _, shardCmd := range cmds { + value, err := ExtractCommandValue(shardCmd) + batchWithErrs = append(batchWithErrs, routing.AggregatorResErr{ + Result: value, + Err: err, + }) + } + + err := aggregator.BatchSlice(batchWithErrs) + if err != nil { + return err + } + + return c.finishAggregation(cmd, aggregator) +} + +// createAggregator creates the appropriate response aggregator +func (c *ClusterClient) createAggregator(policy *routing.CommandPolicy, cmd Cmder, isKeyed bool) routing.ResponseAggregator { + if policy != nil { + return routing.NewResponseAggregator(policy.Response, cmd.Name()) + } + + if !isKeyed { + firstKeyPos := cmdFirstKeyPos(cmd) + isKeyed = firstKeyPos > 0 + } + + return routing.NewDefaultAggregator(isKeyed) +} + +// finishAggregation completes the aggregation process and sets the result +func (c *ClusterClient) finishAggregation(cmd Cmder, aggregator routing.ResponseAggregator) error { + finalValue, finalErr := aggregator.Result() + if finalErr != nil { + cmd.SetErr(finalErr) + return finalErr + } + + return c.setCommandValue(cmd, finalValue) +} + +// pickArbitraryNode selects a master or slave shard using the configured ShardPicker +func (c *ClusterClient) pickArbitraryNode(ctx context.Context) *clusterNode { + state, err := c.state.Get(ctx) + if err != nil || len(state.Masters) == 0 { + return nil + } + + allNodes := append(state.Masters, state.Slaves...) + + idx := c.opt.ShardPicker.Next(len(allNodes)) + return allNodes[idx] +} + +// hasKeys checks if a command operates on keys +func (c *ClusterClient) hasKeys(cmd Cmder) bool { + firstKeyPos := cmdFirstKeyPos(cmd) + return firstKeyPos > 0 +} + +func (c *ClusterClient) readOnlyEnabled() bool { + return c.opt.ReadOnly +} + +// setCommandValue sets the aggregated value on a command using the enum-based approach +func (c *ClusterClient) setCommandValue(cmd Cmder, value interface{}) error { + // If value is nil, it might mean ExtractCommandValue couldn't extract the value + // but the command might have executed successfully. In this case, don't set an error. + if value == nil { + // ExtractCommandValue returned nil - this means the command type is not supported + // in the aggregation flow. This is a programming error, not a runtime error. + if cmd.Err() != nil { + // Command already has an error, preserve it + return cmd.Err() + } + // Command executed successfully but we can't extract/set the aggregated value + // This indicates the command type needs to be added to ExtractCommandValue + return fmt.Errorf("redis: cannot aggregate command %s: unsupported command type %d", + cmd.Name(), cmd.GetCmdType()) + } + + switch cmd.GetCmdType() { + case CmdTypeGeneric: + if c, ok := cmd.(*Cmd); ok { + c.SetVal(value) + } + case CmdTypeString: + if c, ok := cmd.(*StringCmd); ok { + if v, ok := value.(string); ok { + c.SetVal(v) + } + } + case CmdTypeInt: + if c, ok := cmd.(*IntCmd); ok { + if v, ok := value.(int64); ok { + c.SetVal(v) + } else if v, ok := value.(float64); ok { + c.SetVal(int64(v)) + } + } + case CmdTypeBool: + if c, ok := cmd.(*BoolCmd); ok { + if v, ok := value.(bool); ok { + c.SetVal(v) + } + } + case CmdTypeFloat: + if c, ok := cmd.(*FloatCmd); ok { + if v, ok := value.(float64); ok { + c.SetVal(v) + } + } + case CmdTypeStringSlice: + if c, ok := cmd.(*StringSliceCmd); ok { + if v, ok := value.([]string); ok { + c.SetVal(v) + } + } + case CmdTypeIntSlice: + if c, ok := cmd.(*IntSliceCmd); ok { + if v, ok := value.([]int64); ok { + c.SetVal(v) + } else if v, ok := value.([]float64); ok { + els := len(v) + intSlc := make([]int, els) + for i := range v { + intSlc[i] = int(v[i]) + } + } + } + case CmdTypeFloatSlice: + if c, ok := cmd.(*FloatSliceCmd); ok { + if v, ok := value.([]float64); ok { + c.SetVal(v) + } + } + case CmdTypeBoolSlice: + if c, ok := cmd.(*BoolSliceCmd); ok { + if v, ok := value.([]bool); ok { + c.SetVal(v) + } + } + case CmdTypeMapStringString: + if c, ok := cmd.(*MapStringStringCmd); ok { + if v, ok := value.(map[string]string); ok { + c.SetVal(v) + } + } + case CmdTypeMapStringInt: + if c, ok := cmd.(*MapStringIntCmd); ok { + if v, ok := value.(map[string]int64); ok { + c.SetVal(v) + } + } + case CmdTypeMapStringInterface: + if c, ok := cmd.(*MapStringInterfaceCmd); ok { + if v, ok := value.(map[string]interface{}); ok { + c.SetVal(v) + } + } + case CmdTypeSlice: + if c, ok := cmd.(*SliceCmd); ok { + if v, ok := value.([]interface{}); ok { + c.SetVal(v) + } + } + case CmdTypeStatus: + if c, ok := cmd.(*StatusCmd); ok { + if v, ok := value.(string); ok { + c.SetVal(v) + } + } + case CmdTypeDuration: + if c, ok := cmd.(*DurationCmd); ok { + if v, ok := value.(time.Duration); ok { + c.SetVal(v) + } + } + case CmdTypeTime: + if c, ok := cmd.(*TimeCmd); ok { + if v, ok := value.(time.Time); ok { + c.SetVal(v) + } + } + case CmdTypeKeyValueSlice: + if c, ok := cmd.(*KeyValueSliceCmd); ok { + if v, ok := value.([]KeyValue); ok { + c.SetVal(v) + } + } + case CmdTypeStringStructMap: + if c, ok := cmd.(*StringStructMapCmd); ok { + if v, ok := value.(map[string]struct{}); ok { + c.SetVal(v) + } + } + case CmdTypeXMessageSlice: + if c, ok := cmd.(*XMessageSliceCmd); ok { + if v, ok := value.([]XMessage); ok { + c.SetVal(v) + } + } + case CmdTypeXStreamSlice: + if c, ok := cmd.(*XStreamSliceCmd); ok { + if v, ok := value.([]XStream); ok { + c.SetVal(v) + } + } + case CmdTypeXPending: + if c, ok := cmd.(*XPendingCmd); ok { + if v, ok := value.(*XPending); ok { + c.SetVal(v) + } + } + case CmdTypeXPendingExt: + if c, ok := cmd.(*XPendingExtCmd); ok { + if v, ok := value.([]XPendingExt); ok { + c.SetVal(v) + } + } + case CmdTypeXAutoClaim: + if c, ok := cmd.(*XAutoClaimCmd); ok { + if v, ok := value.(CmdTypeXAutoClaimValue); ok { + c.SetVal(v.messages, v.start) + } + } + case CmdTypeXAutoClaimJustID: + if c, ok := cmd.(*XAutoClaimJustIDCmd); ok { + if v, ok := value.(CmdTypeXAutoClaimJustIDValue); ok { + c.SetVal(v.ids, v.start) + } + } + case CmdTypeXInfoConsumers: + if c, ok := cmd.(*XInfoConsumersCmd); ok { + if v, ok := value.([]XInfoConsumer); ok { + c.SetVal(v) + } + } + case CmdTypeXInfoGroups: + if c, ok := cmd.(*XInfoGroupsCmd); ok { + if v, ok := value.([]XInfoGroup); ok { + c.SetVal(v) + } + } + case CmdTypeXInfoStream: + if c, ok := cmd.(*XInfoStreamCmd); ok { + if v, ok := value.(*XInfoStream); ok { + c.SetVal(v) + } + } + case CmdTypeXInfoStreamFull: + if c, ok := cmd.(*XInfoStreamFullCmd); ok { + if v, ok := value.(*XInfoStreamFull); ok { + c.SetVal(v) + } + } + case CmdTypeZSlice: + if c, ok := cmd.(*ZSliceCmd); ok { + if v, ok := value.([]Z); ok { + c.SetVal(v) + } + } + case CmdTypeZWithKey: + if c, ok := cmd.(*ZWithKeyCmd); ok { + if v, ok := value.(*ZWithKey); ok { + c.SetVal(v) + } + } + case CmdTypeScan: + if c, ok := cmd.(*ScanCmd); ok { + if v, ok := value.(CmdTypeScanValue); ok { + c.SetVal(v.keys, v.cursor) + } + } + case CmdTypeClusterSlots: + if c, ok := cmd.(*ClusterSlotsCmd); ok { + if v, ok := value.([]ClusterSlot); ok { + c.SetVal(v) + } + } + case CmdTypeGeoLocation: + if c, ok := cmd.(*GeoLocationCmd); ok { + if v, ok := value.([]GeoLocation); ok { + c.SetVal(v) + } + } + case CmdTypeGeoSearchLocation: + if c, ok := cmd.(*GeoSearchLocationCmd); ok { + if v, ok := value.([]GeoLocation); ok { + c.SetVal(v) + } + } + case CmdTypeGeoPos: + if c, ok := cmd.(*GeoPosCmd); ok { + if v, ok := value.([]*GeoPos); ok { + c.SetVal(v) + } + } + case CmdTypeCommandsInfo: + if c, ok := cmd.(*CommandsInfoCmd); ok { + if v, ok := value.(map[string]*CommandInfo); ok { + c.SetVal(v) + } + } + case CmdTypeSlowLog: + if c, ok := cmd.(*SlowLogCmd); ok { + if v, ok := value.([]SlowLog); ok { + c.SetVal(v) + } + } + case CmdTypeMapStringStringSlice: + if c, ok := cmd.(*MapStringStringSliceCmd); ok { + if v, ok := value.([]map[string]string); ok { + c.SetVal(v) + } + } + case CmdTypeMapMapStringInterface: + if c, ok := cmd.(*MapMapStringInterfaceCmd); ok { + if v, ok := value.(map[string]interface{}); ok { + c.SetVal(v) + } + } + case CmdTypeMapStringInterfaceSlice: + if c, ok := cmd.(*MapStringInterfaceSliceCmd); ok { + if v, ok := value.([]map[string]interface{}); ok { + c.SetVal(v) + } + } + case CmdTypeKeyValues: + if c, ok := cmd.(*KeyValuesCmd); ok { + // KeyValuesCmd needs a key string and values slice + if v, ok := value.(CmdTypeKeyValuesValue); ok { + c.SetVal(v.key, v.values) + } + } + case CmdTypeZSliceWithKey: + if c, ok := cmd.(*ZSliceWithKeyCmd); ok { + // ZSliceWithKeyCmd needs a key string and Z slice + if v, ok := value.(CmdTypeZSliceWithKeyValue); ok { + c.SetVal(v.key, v.zSlice) + } + } + case CmdTypeFunctionList: + if c, ok := cmd.(*FunctionListCmd); ok { + if v, ok := value.([]Library); ok { + c.SetVal(v) + } + } + case CmdTypeFunctionStats: + if c, ok := cmd.(*FunctionStatsCmd); ok { + if v, ok := value.(FunctionStats); ok { + c.SetVal(v) + } + } + case CmdTypeLCS: + if c, ok := cmd.(*LCSCmd); ok { + if v, ok := value.(*LCSMatch); ok { + c.SetVal(v) + } + } + case CmdTypeKeyFlags: + if c, ok := cmd.(*KeyFlagsCmd); ok { + if v, ok := value.([]KeyFlags); ok { + c.SetVal(v) + } + } + case CmdTypeClusterLinks: + if c, ok := cmd.(*ClusterLinksCmd); ok { + if v, ok := value.([]ClusterLink); ok { + c.SetVal(v) + } + } + case CmdTypeClusterShards: + if c, ok := cmd.(*ClusterShardsCmd); ok { + if v, ok := value.([]ClusterShard); ok { + c.SetVal(v) + } + } + case CmdTypeRankWithScore: + if c, ok := cmd.(*RankWithScoreCmd); ok { + if v, ok := value.(RankScore); ok { + c.SetVal(v) + } + } + case CmdTypeClientInfo: + if c, ok := cmd.(*ClientInfoCmd); ok { + if v, ok := value.(*ClientInfo); ok { + c.SetVal(v) + } + } + case CmdTypeACLLog: + if c, ok := cmd.(*ACLLogCmd); ok { + if v, ok := value.([]*ACLLogEntry); ok { + c.SetVal(v) + } + } + case CmdTypeInfo: + if c, ok := cmd.(*InfoCmd); ok { + if v, ok := value.(map[string]map[string]string); ok { + c.SetVal(v) + } + } + case CmdTypeMonitor: + // MonitorCmd doesn't have SetVal method + // Skip setting value for MonitorCmd + case CmdTypeJSON: + if c, ok := cmd.(*JSONCmd); ok { + if v, ok := value.(string); ok { + c.SetVal(v) + } + } + case CmdTypeJSONSlice: + if c, ok := cmd.(*JSONSliceCmd); ok { + if v, ok := value.([]interface{}); ok { + c.SetVal(v) + } + } + case CmdTypeIntPointerSlice: + if c, ok := cmd.(*IntPointerSliceCmd); ok { + if v, ok := value.([]*int64); ok { + c.SetVal(v) + } + } + case CmdTypeScanDump: + if c, ok := cmd.(*ScanDumpCmd); ok { + if v, ok := value.(ScanDump); ok { + c.SetVal(v) + } + } + case CmdTypeBFInfo: + if c, ok := cmd.(*BFInfoCmd); ok { + if v, ok := value.(BFInfo); ok { + c.SetVal(v) + } + } + case CmdTypeCFInfo: + if c, ok := cmd.(*CFInfoCmd); ok { + if v, ok := value.(CFInfo); ok { + c.SetVal(v) + } + } + case CmdTypeCMSInfo: + if c, ok := cmd.(*CMSInfoCmd); ok { + if v, ok := value.(CMSInfo); ok { + c.SetVal(v) + } + } + case CmdTypeTopKInfo: + if c, ok := cmd.(*TopKInfoCmd); ok { + if v, ok := value.(TopKInfo); ok { + c.SetVal(v) + } + } + case CmdTypeTDigestInfo: + if c, ok := cmd.(*TDigestInfoCmd); ok { + if v, ok := value.(TDigestInfo); ok { + c.SetVal(v) + } + } + case CmdTypeFTSynDump: + if c, ok := cmd.(*FTSynDumpCmd); ok { + if v, ok := value.([]FTSynDumpResult); ok { + c.SetVal(v) + } + } + case CmdTypeAggregate: + if c, ok := cmd.(*AggregateCmd); ok { + if v, ok := value.(*FTAggregateResult); ok { + c.SetVal(v) + } + } + case CmdTypeFTInfo: + if c, ok := cmd.(*FTInfoCmd); ok { + if v, ok := value.(FTInfoResult); ok { + c.SetVal(v) + } + } + case CmdTypeFTSpellCheck: + if c, ok := cmd.(*FTSpellCheckCmd); ok { + if v, ok := value.([]SpellCheckResult); ok { + c.SetVal(v) + } + } + case CmdTypeFTSearch: + if c, ok := cmd.(*FTSearchCmd); ok { + if v, ok := value.(FTSearchResult); ok { + c.SetVal(v) + } + } + case CmdTypeTSTimestampValue: + if c, ok := cmd.(*TSTimestampValueCmd); ok { + if v, ok := value.(TSTimestampValue); ok { + c.SetVal(v) + } + } + case CmdTypeTSTimestampValueSlice: + if c, ok := cmd.(*TSTimestampValueSliceCmd); ok { + if v, ok := value.([]TSTimestampValue); ok { + c.SetVal(v) + } + } + default: + // Fallback to reflection for unknown types + return c.setCommandValueReflection(cmd, value) + } + + return nil +} + +// setCommandValueReflection is a fallback function that uses reflection +func (c *ClusterClient) setCommandValueReflection(cmd Cmder, value interface{}) error { + cmdValue := reflect.ValueOf(cmd) + if cmdValue.Kind() != reflect.Ptr || cmdValue.IsNil() { + return errInvalidCmdPointer + } + + setValMethod := cmdValue.MethodByName("SetVal") + if !setValMethod.IsValid() { + return fmt.Errorf("redis: command %T does not have SetVal method", cmd) + } + + args := []reflect.Value{reflect.ValueOf(value)} + + switch cmd.(type) { + case *XAutoClaimCmd, *XAutoClaimJustIDCmd: + args = append(args, reflect.ValueOf("")) + case *ScanCmd: + args = append(args, reflect.ValueOf(uint64(0))) + case *KeyValuesCmd, *ZSliceWithKeyCmd: + if key, ok := value.(string); ok { + args = []reflect.Value{reflect.ValueOf(key)} + if _, ok := cmd.(*ZSliceWithKeyCmd); ok { + args = append(args, reflect.ValueOf([]Z{})) + } else { + args = append(args, reflect.ValueOf([]string{})) + } + } + } + + defer func() { + if r := recover(); r != nil { + cmd.SetErr(fmt.Errorf("redis: failed to set command value: %v", r)) + } + }() + + setValMethod.Call(args) + return nil +} diff --git a/vendor/github.com/redis/go-redis/v9/otel.go b/vendor/github.com/redis/go-redis/v9/otel.go new file mode 100644 index 00000000..a81377d4 --- /dev/null +++ b/vendor/github.com/redis/go-redis/v9/otel.go @@ -0,0 +1,204 @@ +package redis + +import ( + "context" + "net" + "time" + + "github.com/redis/go-redis/v9/internal/otel" + "github.com/redis/go-redis/v9/internal/pool" +) + +// ConnInfo provides information about a Redis connection for metrics. +type ConnInfo interface { + RemoteAddr() net.Addr + PoolName() string +} + +type Pooler interface { + PoolStats() *pool.Stats +} + +type PubSubPooler interface { + Stats() *pool.PubSubStats +} + +// OTelRecorder is the interface for recording OpenTelemetry metrics. + +type OTelRecorder interface { + // RecordOperationDuration records the total operation duration (including all retries) + RecordOperationDuration(ctx context.Context, duration time.Duration, cmd Cmder, attempts int, err error, cn ConnInfo, dbIndex int) + + // RecordPipelineOperationDuration records the total pipeline/transaction duration. + // operationName should be "PIPELINE" for regular pipelines or "MULTI" for transactions. + RecordPipelineOperationDuration(ctx context.Context, duration time.Duration, operationName string, cmdCount int, attempts int, err error, cn ConnInfo, dbIndex int) + + // RecordConnectionCreateTime records the time it took to create a new connection + RecordConnectionCreateTime(ctx context.Context, duration time.Duration, cn ConnInfo) + + // RecordConnectionRelaxedTimeout records when connection timeout is relaxed/unrelaxed + // delta: +1 for relaxed, -1 for unrelaxed + // poolName: name of the connection pool (e.g., "main", "pubsub") + // notificationType: the notification type that triggered the timeout relaxation (e.g., "MOVING", "HANDOFF") + RecordConnectionRelaxedTimeout(ctx context.Context, delta int, cn ConnInfo, poolName, notificationType string) + + // RecordConnectionHandoff records when a connection is handed off to another node + // poolName: name of the connection pool (e.g., "main", "pubsub") + RecordConnectionHandoff(ctx context.Context, cn ConnInfo, poolName string) + + // RecordError records client errors (ASK, MOVED, handshake failures, etc.) + // errorType: type of error (e.g., "ASK", "MOVED", "HANDSHAKE_FAILED") + // statusCode: Redis response status code if available (e.g., "MOVED", "ASK") + // isInternal: whether this is an internal error + // retryAttempts: number of retry attempts made + RecordError(ctx context.Context, errorType string, cn ConnInfo, statusCode string, isInternal bool, retryAttempts int) + + // RecordMaintenanceNotification records when a maintenance notification is received + // notificationType: the type of notification (e.g., "MOVING", "MIGRATING", etc.) + RecordMaintenanceNotification(ctx context.Context, cn ConnInfo, notificationType string) + + // RecordConnectionWaitTime records the time spent waiting for a connection from the pool + RecordConnectionWaitTime(ctx context.Context, duration time.Duration, cn ConnInfo) + + // RecordConnectionClosed records when a connection is closed + // reason: reason for closing (e.g., "idle", "max_lifetime", "error", "pool_closed") + // err: the error that caused the close (nil for non-error closures) + RecordConnectionClosed(ctx context.Context, cn ConnInfo, reason string, err error) + + // RecordPubSubMessage records a Pub/Sub message + // direction: "sent" or "received" + // channel: channel name (may be hidden for cardinality reduction) + // sharded: true for sharded pub/sub (SPUBLISH/SSUBSCRIBE) + RecordPubSubMessage(ctx context.Context, cn ConnInfo, direction, channel string, sharded bool) + + // RecordStreamLag records the lag for stream consumer group processing + // lag: time difference between message creation and consumption + // streamName: name of the stream (may be hidden for cardinality reduction) + // consumerGroup: name of the consumer group + // consumerName: name of the consumer + RecordStreamLag(ctx context.Context, lag time.Duration, cn ConnInfo, streamName, consumerGroup, consumerName string) +} + +// This is used for async gauge metrics that need to pull stats from pools periodically. +type OTelPoolRegistrar interface { + // RegisterPool is called when a new client is created with its main connection pool. + // poolName: unique identifier for the pool (e.g., "main_abc123") + RegisterPool(poolName string, pool Pooler) + // UnregisterPool is called when a client is closed to remove its pool from the registry. + UnregisterPool(pool Pooler) + // RegisterPubSubPool is called when a new client is created with a PubSub pool. + // poolName: unique identifier for the pool (e.g., "main_abc123_pubsub") + RegisterPubSubPool(poolName string, pool PubSubPooler) + // UnregisterPubSubPool is called when a PubSub client is closed to remove its pool. + UnregisterPubSubPool(pool PubSubPooler) +} + +// SetOTelRecorder sets the global OpenTelemetry recorder. +func SetOTelRecorder(r OTelRecorder) { + if r == nil { + otel.SetGlobalRecorder(nil) + return + } + otel.SetGlobalRecorder(&otelRecorderAdapter{r}) +} + +type otelRecorderAdapter struct { + recorder OTelRecorder +} + +// toConnInfo converts *pool.Conn to ConnInfo interface properly. +// This ensures that a nil *pool.Conn becomes a true nil interface, +// not a non-nil interface containing a nil pointer. +func toConnInfo(cn *pool.Conn) ConnInfo { + if cn == nil { + return nil + } + return cn +} + +func (a *otelRecorderAdapter) RecordOperationDuration(ctx context.Context, duration time.Duration, cmd otel.Cmder, attempts int, err error, cn *pool.Conn, dbIndex int) { + // Convert internal Cmder to public Cmder + if publicCmd, ok := cmd.(Cmder); ok { + a.recorder.RecordOperationDuration(ctx, duration, publicCmd, attempts, err, toConnInfo(cn), dbIndex) + } +} + +func (a *otelRecorderAdapter) RecordPipelineOperationDuration(ctx context.Context, duration time.Duration, operationName string, cmdCount int, attempts int, err error, cn *pool.Conn, dbIndex int) { + a.recorder.RecordPipelineOperationDuration(ctx, duration, operationName, cmdCount, attempts, err, toConnInfo(cn), dbIndex) +} + +func (a *otelRecorderAdapter) RecordConnectionCreateTime(ctx context.Context, duration time.Duration, cn *pool.Conn) { + a.recorder.RecordConnectionCreateTime(ctx, duration, toConnInfo(cn)) +} + +func (a *otelRecorderAdapter) RecordConnectionRelaxedTimeout(ctx context.Context, delta int, cn *pool.Conn, poolName, notificationType string) { + a.recorder.RecordConnectionRelaxedTimeout(ctx, delta, toConnInfo(cn), poolName, notificationType) +} + +func (a *otelRecorderAdapter) RecordConnectionHandoff(ctx context.Context, cn *pool.Conn, poolName string) { + a.recorder.RecordConnectionHandoff(ctx, toConnInfo(cn), poolName) +} + +func (a *otelRecorderAdapter) RecordError(ctx context.Context, errorType string, cn *pool.Conn, statusCode string, isInternal bool, retryAttempts int) { + a.recorder.RecordError(ctx, errorType, toConnInfo(cn), statusCode, isInternal, retryAttempts) +} + +func (a *otelRecorderAdapter) RecordMaintenanceNotification(ctx context.Context, cn *pool.Conn, notificationType string) { + a.recorder.RecordMaintenanceNotification(ctx, toConnInfo(cn), notificationType) +} + +func (a *otelRecorderAdapter) RecordConnectionWaitTime(ctx context.Context, duration time.Duration, cn *pool.Conn) { + a.recorder.RecordConnectionWaitTime(ctx, duration, toConnInfo(cn)) +} + +func (a *otelRecorderAdapter) RecordConnectionClosed(ctx context.Context, cn *pool.Conn, reason string, err error) { + a.recorder.RecordConnectionClosed(ctx, toConnInfo(cn), reason, err) +} + +func (a *otelRecorderAdapter) RecordPubSubMessage(ctx context.Context, cn *pool.Conn, direction, channel string, sharded bool) { + a.recorder.RecordPubSubMessage(ctx, toConnInfo(cn), direction, channel, sharded) +} + +func (a *otelRecorderAdapter) RecordStreamLag(ctx context.Context, lag time.Duration, cn *pool.Conn, streamName, consumerGroup, consumerName string) { + a.recorder.RecordStreamLag(ctx, lag, toConnInfo(cn), streamName, consumerGroup, consumerName) +} + +func (a *otelRecorderAdapter) RegisterPool(poolName string, p pool.Pooler) { + if registrar, ok := a.recorder.(OTelPoolRegistrar); ok { + registrar.RegisterPool(poolName, &poolerAdapter{p}) + } +} + +func (a *otelRecorderAdapter) UnregisterPool(p pool.Pooler) { + if registrar, ok := a.recorder.(OTelPoolRegistrar); ok { + registrar.UnregisterPool(&poolerAdapter{p}) + } +} + +func (a *otelRecorderAdapter) RegisterPubSubPool(poolName string, p otel.PubSubPooler) { + if registrar, ok := a.recorder.(OTelPoolRegistrar); ok { + registrar.RegisterPubSubPool(poolName, &pubSubPoolerAdapter{p}) + } +} + +func (a *otelRecorderAdapter) UnregisterPubSubPool(p otel.PubSubPooler) { + if registrar, ok := a.recorder.(OTelPoolRegistrar); ok { + registrar.UnregisterPubSubPool(&pubSubPoolerAdapter{p}) + } +} + +type poolerAdapter struct { + p pool.Pooler +} + +func (a *poolerAdapter) PoolStats() *pool.Stats { + return a.p.Stats() +} + +type pubSubPoolerAdapter struct { + p otel.PubSubPooler +} + +func (a *pubSubPoolerAdapter) Stats() *pool.PubSubStats { + return a.p.Stats() +} diff --git a/vendor/github.com/redis/go-redis/v9/probabilistic.go b/vendor/github.com/redis/go-redis/v9/probabilistic.go index c26e7cad..ee67911e 100644 --- a/vendor/github.com/redis/go-redis/v9/probabilistic.go +++ b/vendor/github.com/redis/go-redis/v9/probabilistic.go @@ -225,8 +225,9 @@ type ScanDumpCmd struct { func newScanDumpCmd(ctx context.Context, args ...interface{}) *ScanDumpCmd { return &ScanDumpCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeScanDump, }, } } @@ -270,6 +271,13 @@ func (cmd *ScanDumpCmd) readReply(rd *proto.Reader) (err error) { return nil } +func (cmd *ScanDumpCmd) Clone() Cmder { + return &ScanDumpCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: cmd.val, // ScanDump is a simple struct, can be copied directly + } +} + // Returns information about a Bloom filter. // For more information - https://redis.io/commands/bf.info/ func (c cmdable) BFInfo(ctx context.Context, key string) *BFInfoCmd { @@ -296,8 +304,9 @@ type BFInfoCmd struct { func NewBFInfoCmd(ctx context.Context, args ...interface{}) *BFInfoCmd { return &BFInfoCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeBFInfo, }, } } @@ -388,6 +397,13 @@ func (cmd *BFInfoCmd) readReply(rd *proto.Reader) (err error) { return nil } +func (cmd *BFInfoCmd) Clone() Cmder { + return &BFInfoCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: cmd.val, // BFInfo is a simple struct, can be copied directly + } +} + // BFInfoCapacity returns information about the capacity of a Bloom filter. // For more information - https://redis.io/commands/bf.info/ func (c cmdable) BFInfoCapacity(ctx context.Context, key string) *BFInfoCmd { @@ -625,8 +641,9 @@ type CFInfoCmd struct { func NewCFInfoCmd(ctx context.Context, args ...interface{}) *CFInfoCmd { return &CFInfoCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeCFInfo, }, } } @@ -692,6 +709,13 @@ func (cmd *CFInfoCmd) readReply(rd *proto.Reader) (err error) { return nil } +func (cmd *CFInfoCmd) Clone() Cmder { + return &CFInfoCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: cmd.val, // CFInfo is a simple struct, can be copied directly + } +} + // CFInfo returns information about a Cuckoo filter. // For more information - https://redis.io/commands/cf.info/ func (c cmdable) CFInfo(ctx context.Context, key string) *CFInfoCmd { @@ -787,8 +811,9 @@ type CMSInfoCmd struct { func NewCMSInfoCmd(ctx context.Context, args ...interface{}) *CMSInfoCmd { return &CMSInfoCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeCMSInfo, }, } } @@ -843,6 +868,13 @@ func (cmd *CMSInfoCmd) readReply(rd *proto.Reader) (err error) { return nil } +func (cmd *CMSInfoCmd) Clone() Cmder { + return &CMSInfoCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: cmd.val, // CMSInfo is a simple struct, can be copied directly + } +} + // CMSInfo returns information about a Count-Min Sketch filter. // For more information - https://redis.io/commands/cms.info/ func (c cmdable) CMSInfo(ctx context.Context, key string) *CMSInfoCmd { @@ -980,8 +1012,9 @@ type TopKInfoCmd struct { func NewTopKInfoCmd(ctx context.Context, args ...interface{}) *TopKInfoCmd { return &TopKInfoCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeTopKInfo, }, } } @@ -1038,6 +1071,13 @@ func (cmd *TopKInfoCmd) readReply(rd *proto.Reader) (err error) { return nil } +func (cmd *TopKInfoCmd) Clone() Cmder { + return &TopKInfoCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: cmd.val, // TopKInfo is a simple struct, can be copied directly + } +} + // TopKInfo returns information about a Top-K filter. // For more information - https://redis.io/commands/topk.info/ func (c cmdable) TopKInfo(ctx context.Context, key string) *TopKInfoCmd { @@ -1227,8 +1267,9 @@ type TDigestInfoCmd struct { func NewTDigestInfoCmd(ctx context.Context, args ...interface{}) *TDigestInfoCmd { return &TDigestInfoCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeTDigestInfo, }, } } @@ -1295,6 +1336,13 @@ func (cmd *TDigestInfoCmd) readReply(rd *proto.Reader) (err error) { return nil } +func (cmd *TDigestInfoCmd) Clone() Cmder { + return &TDigestInfoCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: cmd.val, // TDigestInfo is a simple struct, can be copied directly + } +} + // TDigestInfo returns information about a t-Digest data structure. // For more information - https://redis.io/commands/tdigest.info/ func (c cmdable) TDigestInfo(ctx context.Context, key string) *TDigestInfoCmd { diff --git a/vendor/github.com/redis/go-redis/v9/pubsub.go b/vendor/github.com/redis/go-redis/v9/pubsub.go index 959a5c45..49eec935 100644 --- a/vendor/github.com/redis/go-redis/v9/pubsub.go +++ b/vendor/github.com/redis/go-redis/v9/pubsub.go @@ -8,6 +8,7 @@ import ( "time" "github.com/redis/go-redis/v9/internal" + "github.com/redis/go-redis/v9/internal/otel" "github.com/redis/go-redis/v9/internal/pool" "github.com/redis/go-redis/v9/internal/proto" "github.com/redis/go-redis/v9/push" @@ -403,7 +404,7 @@ func (p *Pong) String() string { return "Pong" } -func (c *PubSub) newMessage(reply interface{}) (interface{}, error) { +func (c *PubSub) newMessage(ctx context.Context, cn *pool.Conn, reply interface{}) (interface{}, error) { switch reply := reply.(type) { case string: return &Pong{ @@ -420,30 +421,42 @@ func (c *PubSub) newMessage(reply interface{}) (interface{}, error) { Count: int(reply[2].(int64)), }, nil case "message", "smessage": + channel := reply[1].(string) + sharded := kind == "smessage" switch payload := reply[2].(type) { case string: - return &Message{ - Channel: reply[1].(string), + msg := &Message{ + Channel: channel, Payload: payload, - }, nil + } + // Record PubSub message received + otel.RecordPubSubMessage(ctx, cn, "received", channel, sharded) + return msg, nil case []interface{}: ss := make([]string, len(payload)) for i, s := range payload { ss[i] = s.(string) } - return &Message{ - Channel: reply[1].(string), + msg := &Message{ + Channel: channel, PayloadSlice: ss, - }, nil + } + // Record PubSub message received + otel.RecordPubSubMessage(ctx, cn, "received", channel, sharded) + return msg, nil default: return nil, fmt.Errorf("redis: unsupported pubsub message payload: %T", payload) } case "pmessage": - return &Message{ + channel := reply[2].(string) + msg := &Message{ Pattern: reply[1].(string), - Channel: reply[2].(string), + Channel: channel, Payload: reply[3].(string), - }, nil + } + // Record PubSub message received (pattern message, not sharded) + otel.RecordPubSubMessage(ctx, cn, "received", channel, false) + return msg, nil case "pong": return &Pong{ Payload: reply[1].(string), @@ -485,7 +498,7 @@ func (c *PubSub) ReceiveTimeout(ctx context.Context, timeout time.Duration) (int return nil, err } - return c.newMessage(c.cmd.Val()) + return c.newMessage(ctx, cn, c.cmd.Val()) } // Receive returns a message as a Subscription, Message, Pong or error. @@ -734,7 +747,7 @@ func (c *channel) initMsgChan() { } case <-timer.C: internal.Logger.Printf( - ctx, "redis: %s channel is full for %s (message is dropped)", + ctx, "redis: %v channel is full for %s (message is dropped)", c, c.chanSendTimeout) } default: @@ -788,7 +801,7 @@ func (c *channel) initAllChan() { } case <-timer.C: internal.Logger.Printf( - ctx, "redis: %s channel is full for %s (message is dropped)", + ctx, "redis: %v channel is full for %s (message is dropped)", c, c.chanSendTimeout) } default: diff --git a/vendor/github.com/redis/go-redis/v9/pubsub_commands.go b/vendor/github.com/redis/go-redis/v9/pubsub_commands.go index 28622aa6..ccc0ed52 100644 --- a/vendor/github.com/redis/go-redis/v9/pubsub_commands.go +++ b/vendor/github.com/redis/go-redis/v9/pubsub_commands.go @@ -1,6 +1,10 @@ package redis -import "context" +import ( + "context" + + "github.com/redis/go-redis/v9/internal/otel" +) type PubSubCmdable interface { Publish(ctx context.Context, channel string, message interface{}) *IntCmd @@ -16,12 +20,20 @@ type PubSubCmdable interface { func (c cmdable) Publish(ctx context.Context, channel string, message interface{}) *IntCmd { cmd := NewIntCmd(ctx, "publish", channel, message) _ = c(ctx, cmd) + // Record PubSub message sent (if command succeeded) + if cmd.Err() == nil { + otel.RecordPubSubMessage(ctx, nil, "sent", channel, false) + } return cmd } func (c cmdable) SPublish(ctx context.Context, channel string, message interface{}) *IntCmd { cmd := NewIntCmd(ctx, "spublish", channel, message) _ = c(ctx, cmd) + // Record PubSub message sent (if command succeeded) + if cmd.Err() == nil { + otel.RecordPubSubMessage(ctx, nil, "sent", channel, true) + } return cmd } diff --git a/vendor/github.com/redis/go-redis/v9/redis.go b/vendor/github.com/redis/go-redis/v9/redis.go index a6a71067..85622e43 100644 --- a/vendor/github.com/redis/go-redis/v9/redis.go +++ b/vendor/github.com/redis/go-redis/v9/redis.go @@ -13,6 +13,7 @@ import ( "github.com/redis/go-redis/v9/internal" "github.com/redis/go-redis/v9/internal/auth/streaming" "github.com/redis/go-redis/v9/internal/hscan" + "github.com/redis/go-redis/v9/internal/otel" "github.com/redis/go-redis/v9/internal/pool" "github.com/redis/go-redis/v9/internal/proto" "github.com/redis/go-redis/v9/maintnotifications" @@ -27,7 +28,11 @@ const Nil = proto.Nil // SetLogger set custom log // Use with VoidLogger to disable logging. +// If logger is nil, the call is ignored and the existing logger is kept. func SetLogger(logger internal.Logging) { + if logger == nil { + return + } internal.Logger = logger } @@ -238,6 +243,7 @@ func (c *baseClient) clone() *baseClient { clone := &baseClient{ opt: c.opt, connPool: c.connPool, + pubSubPool: c.pubSubPool, onClose: c.onClose, pushProcessor: c.pushProcessor, maintNotificationsManager: maintNotificationsManager, @@ -298,6 +304,13 @@ func (c *baseClient) _getConn(ctx context.Context) (*pool.Conn, error) { return nil, err } + if dialStartNs := cn.GetDialStartNs(); dialStartNs > 0 { + if cb := pool.GetMetricConnectionCreateTimeCallback(); cb != nil { + duration := time.Duration(time.Now().UnixNano() - dialStartNs) + cb(ctx, duration, cn) + } + } + // initConn will transition to IDLE state, so we need to acquire it // before returning it to the user. if !cn.TryAcquire() { @@ -537,7 +550,10 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error { c.optLock.RLock() maintNotifEnabled := c.opt.MaintNotificationsConfig != nil && c.opt.MaintNotificationsConfig.Mode != maintnotifications.ModeDisabled protocol := c.opt.Protocol - endpointType := c.opt.MaintNotificationsConfig.EndpointType + var endpointType maintnotifications.EndpointType + if maintNotifEnabled { + endpointType = c.opt.MaintNotificationsConfig.EndpointType + } c.optLock.RUnlock() var maintNotifHandshakeErr error if maintNotifEnabled && protocol == 3 { @@ -559,6 +575,12 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error { // enabled mode, fail the connection c.optLock.Unlock() cn.GetStateMachine().Transition(pool.StateClosed) + + // Record handshake failure metric + if errorCallback := pool.GetMetricErrorCallback(); errorCallback != nil { + errorCallback(ctx, "HANDSHAKE_FAILED", cn, "HANDSHAKE_FAILED", true, 0) + } + return fmt.Errorf("failed to enable maintnotifications: %w", maintNotifHandshakeErr) default: // will handle auto and any other // Disabling logging here as it's too noisy. @@ -662,20 +684,119 @@ func (c *baseClient) dial(ctx context.Context, network, addr string) (net.Conn, } func (c *baseClient) process(ctx context.Context, cmd Cmder) error { + // Start measuring total operation duration (includes all retries) + // Only call time.Now() if operation duration callback is set to avoid overhead + var operationStart time.Time + opDurationCallback := otel.GetOperationDurationCallback() + if opDurationCallback != nil { + operationStart = time.Now() + } + var lastConn *pool.Conn + var lastErr error + totalAttempts := 0 for attempt := 0; attempt <= c.opt.MaxRetries; attempt++ { + totalAttempts++ attempt := attempt - retry, err := c._process(ctx, cmd, attempt) + retry, cn, err := c._process(ctx, cmd, attempt) + if cn != nil { + lastConn = cn + } if err == nil || !retry { + // Record total operation duration + if opDurationCallback != nil { + operationDuration := time.Since(operationStart) + opDurationCallback(ctx, operationDuration, cmd, totalAttempts, err, lastConn, c.opt.DB) + } + + if err != nil { + if errorCallback := pool.GetMetricErrorCallback(); errorCallback != nil { + errorType, statusCode, isInternal := classifyCommandError(err) + errorCallback(ctx, errorType, lastConn, statusCode, isInternal, totalAttempts-1) + } + } return err } lastErr = err } + + // Record failed operation after all retries + if opDurationCallback != nil { + operationDuration := time.Since(operationStart) + opDurationCallback(ctx, operationDuration, cmd, totalAttempts, lastErr, lastConn, c.opt.DB) + } + + // Record error metric for exhausted retries + if errorCallback := pool.GetMetricErrorCallback(); errorCallback != nil { + errorType, statusCode, isInternal := classifyCommandError(lastErr) + errorCallback(ctx, errorType, lastConn, statusCode, isInternal, totalAttempts-1) + } + return lastErr } +// classifyCommandError classifies an error for metrics reporting. +// Returns: errorType, statusCode, isInternal +// - errorType: A string describing the error type (e.g., "TIMEOUT", "NETWORK", "ERR") +// - statusCode: The Redis error prefix or error category +// - isInternal: true for network/timeout errors, false for Redis server errors +func classifyCommandError(err error) (errorType, statusCode string, isInternal bool) { + if err == nil { + return "", "", false + } + + errStr := err.Error() + + // Check for timeout errors + if netErr, ok := err.(net.Error); ok && netErr.Timeout() { + return "TIMEOUT", "TIMEOUT", true + } + + // Check for network errors + if _, ok := err.(net.Error); ok { + return "NETWORK", "NETWORK", true + } + + // Check for context errors + if errors.Is(err, context.Canceled) { + return "CONTEXT_CANCELED", "CONTEXT_CANCELED", true + } + if errors.Is(err, context.DeadlineExceeded) { + return "CONTEXT_TIMEOUT", "CONTEXT_TIMEOUT", true + } + + // Check for Redis errors + // Examples: "ERR ...", "WRONGTYPE ...", "CLUSTERDOWN ..." + if len(errStr) > 0 { + // Find the first space to extract the prefix + spaceIdx := 0 + for i, c := range errStr { + if c == ' ' { + spaceIdx = i + break + } + } + if spaceIdx == 0 { + spaceIdx = len(errStr) + } + prefix := errStr[:spaceIdx] + isUppercase := true + for _, c := range prefix { + if c < 'A' || c > 'Z' { + isUppercase = false + break + } + } + if isUppercase && len(prefix) > 0 { + return prefix, prefix, false + } + } + + return "UNKNOWN", "UNKNOWN", true +} + func (c *baseClient) assertUnstableCommand(cmd Cmder) (bool, error) { switch cmd.(type) { case *AggregateCmd, *FTInfoCmd, *FTSpellCheckCmd, *FTSearchCmd, *FTSynDumpCmd: @@ -689,15 +810,17 @@ func (c *baseClient) assertUnstableCommand(cmd Cmder) (bool, error) { } } -func (c *baseClient) _process(ctx context.Context, cmd Cmder, attempt int) (bool, error) { +func (c *baseClient) _process(ctx context.Context, cmd Cmder, attempt int) (bool, *pool.Conn, error) { if attempt > 0 { if err := internal.Sleep(ctx, c.retryBackoff(attempt)); err != nil { - return false, err + return false, nil, err } } + var usedConn *pool.Conn retryTimeout := uint32(0) if err := c.withConn(ctx, func(ctx context.Context, cn *pool.Conn) error { + usedConn = cn // Process any pending push notifications before executing the command if err := c.processPushNotifications(ctx, cn); err != nil { internal.Logger.Printf(ctx, "push: error processing pending notifications before command: %v", err) @@ -738,10 +861,10 @@ func (c *baseClient) _process(ctx context.Context, cmd Cmder, attempt int) (bool return nil }); err != nil { retry := shouldRetry(err, atomic.LoadUint32(&retryTimeout) == 1) - return retry, err + return retry, usedConn, err } - return false, nil + return false, usedConn, nil } func (c *baseClient) retryBackoff(attempt int) time.Duration { @@ -830,6 +953,10 @@ func (c *baseClient) Close() error { firstErr = err } } + + // Unregister pools from OTel before closing them + otel.UnregisterPools(c.connPool, c.pubSubPool) + if c.connPool != nil { if err := c.connPool.Close(); err != nil && firstErr == nil { firstErr = err @@ -848,14 +975,14 @@ func (c *baseClient) getAddr() string { } func (c *baseClient) processPipeline(ctx context.Context, cmds []Cmder) error { - if err := c.generalProcessPipeline(ctx, cmds, c.pipelineProcessCmds); err != nil { + if err := c.generalProcessPipeline(ctx, cmds, c.pipelineProcessCmds, "PIPELINE"); err != nil { return err } return cmdsFirstErr(cmds) } func (c *baseClient) processTxPipeline(ctx context.Context, cmds []Cmder) error { - if err := c.generalProcessPipeline(ctx, cmds, c.txPipelineProcessCmds); err != nil { + if err := c.generalProcessPipeline(ctx, cmds, c.txPipelineProcessCmds, "MULTI"); err != nil { return err } return cmdsFirstErr(cmds) @@ -864,13 +991,27 @@ func (c *baseClient) processTxPipeline(ctx context.Context, cmds []Cmder) error type pipelineProcessor func(context.Context, *pool.Conn, []Cmder) (bool, error) func (c *baseClient) generalProcessPipeline( - ctx context.Context, cmds []Cmder, p pipelineProcessor, + ctx context.Context, cmds []Cmder, p pipelineProcessor, operationName string, ) error { + // Only call time.Now() if pipeline operation duration callback is set to avoid overhead + var operationStart time.Time + pipelineOpDurationCallback := otel.GetPipelineOperationDurationCallback() + if pipelineOpDurationCallback != nil { + operationStart = time.Now() + } + var lastConn *pool.Conn + totalAttempts := 0 + var lastErr error for attempt := 0; attempt <= c.opt.MaxRetries; attempt++ { + totalAttempts++ if attempt > 0 { if err := internal.Sleep(ctx, c.retryBackoff(attempt)); err != nil { setCmdsErr(cmds, err) + if pipelineOpDurationCallback != nil { + operationDuration := time.Since(operationStart) + pipelineOpDurationCallback(ctx, operationDuration, operationName, len(cmds), totalAttempts, err, lastConn, c.opt.DB) + } return err } } @@ -878,6 +1019,7 @@ func (c *baseClient) generalProcessPipeline( // Enable retries by default to retry dial errors returned by withConn. canRetry := true lastErr = c.withConn(ctx, func(ctx context.Context, cn *pool.Conn) error { + lastConn = cn // Process any pending push notifications before executing the pipeline if err := c.processPushNotifications(ctx, cn); err != nil { internal.Logger.Printf(ctx, "push: error processing pending notifications before processing pipeline: %v", err) @@ -891,9 +1033,31 @@ func (c *baseClient) generalProcessPipeline( if !isRedisError(lastErr) { setCmdsErr(cmds, lastErr) } + if pipelineOpDurationCallback != nil { + operationDuration := time.Since(operationStart) + pipelineOpDurationCallback(ctx, operationDuration, operationName, len(cmds), totalAttempts, lastErr, lastConn, c.opt.DB) + } + + if lastErr != nil { + if errorCallback := pool.GetMetricErrorCallback(); errorCallback != nil { + errorType, statusCode, isInternal := classifyCommandError(lastErr) + errorCallback(ctx, errorType, lastConn, statusCode, isInternal, totalAttempts-1) + } + } return lastErr } } + + if pipelineOpDurationCallback != nil { + operationDuration := time.Since(operationStart) + pipelineOpDurationCallback(ctx, operationDuration, operationName, len(cmds), totalAttempts, lastErr, lastConn, c.opt.DB) + } + + if errorCallback := pool.GetMetricErrorCallback(); errorCallback != nil { + errorType, statusCode, isInternal := classifyCommandError(lastErr) + errorCallback(ctx, errorType, lastConn, statusCode, isInternal, totalAttempts-1) + } + return lastErr } @@ -1055,13 +1219,18 @@ func NewClient(opt *Options) *Client { // set opt push processor for child clients c.opt.PushNotificationProcessor = c.pushProcessor + // Generate unique pool names for metrics + uniqueID := generateUniqueID() + mainPoolName := opt.Addr + "_" + uniqueID + pubsubPoolName := opt.Addr + "_" + uniqueID + "_pubsub" + // Create connection pools var err error - c.connPool, err = newConnPool(opt, c.dialHook) + c.connPool, err = newConnPool(opt, c.dialHook, mainPoolName) if err != nil { panic(fmt.Errorf("redis: failed to create connection pool: %w", err)) } - c.pubSubPool, err = newPubSubPool(opt, c.dialHook) + c.pubSubPool, err = newPubSubPool(opt, c.dialHook, pubsubPoolName) if err != nil { panic(fmt.Errorf("redis: failed to create pubsub pool: %w", err)) } @@ -1092,6 +1261,10 @@ func NewClient(opt *Options) *Client { } } + // Register pools with OTel recorder if it supports pool registration + // This allows async gauge metrics to pull stats from pools periodically + otel.RegisterPools(c.connPool, c.pubSubPool, opt.Addr) + return &c } @@ -1127,6 +1300,16 @@ func (c *Client) Options() *Options { return c.opt } +// NodeAddress returns the address of the Redis node as reported by the server. +// For cluster clients, this is the endpoint from CLUSTER SLOTS before any transformation +// (e.g., loopback replacement). For standalone clients, this defaults to Addr. +// +// This is useful for matching the source field in maintenance notifications +// (e.g. SMIGRATED). +func (c *Client) NodeAddress() string { + return c.opt.NodeAddress +} + // GetMaintNotificationsManager returns the maintnotifications manager instance for monitoring and control. // Returns nil if maintnotifications are not enabled. func (c *Client) GetMaintNotificationsManager() *maintnotifications.Manager { diff --git a/vendor/github.com/redis/go-redis/v9/ring.go b/vendor/github.com/redis/go-redis/v9/ring.go index 49657a56..d9220ddb 100644 --- a/vendor/github.com/redis/go-redis/v9/ring.go +++ b/vendor/github.com/redis/go-redis/v9/ring.go @@ -127,11 +127,11 @@ type RingOptions struct { // PoolFIFO uses FIFO mode for each node connection pool GET/PUT (default LIFO). PoolFIFO bool - PoolSize int - PoolTimeout time.Duration - MinIdleConns int - MaxIdleConns int - MaxActiveConns int + PoolSize int + PoolTimeout time.Duration + MinIdleConns int + MaxIdleConns int + MaxActiveConns int ConnMaxIdleTime time.Duration ConnMaxLifetime time.Duration ConnMaxLifetimeJitter time.Duration @@ -237,17 +237,17 @@ func (opt *RingOptions) clientOptions() *Options { WriteTimeout: opt.WriteTimeout, ContextTimeoutEnabled: opt.ContextTimeoutEnabled, - PoolFIFO: opt.PoolFIFO, - PoolSize: opt.PoolSize, - PoolTimeout: opt.PoolTimeout, - MinIdleConns: opt.MinIdleConns, - MaxIdleConns: opt.MaxIdleConns, - MaxActiveConns: opt.MaxActiveConns, + PoolFIFO: opt.PoolFIFO, + PoolSize: opt.PoolSize, + PoolTimeout: opt.PoolTimeout, + MinIdleConns: opt.MinIdleConns, + MaxIdleConns: opt.MaxIdleConns, + MaxActiveConns: opt.MaxActiveConns, ConnMaxIdleTime: opt.ConnMaxIdleTime, ConnMaxLifetime: opt.ConnMaxLifetime, ConnMaxLifetimeJitter: opt.ConnMaxLifetimeJitter, ReadBufferSize: opt.ReadBufferSize, - WriteBufferSize: opt.WriteBufferSize, + WriteBufferSize: opt.WriteBufferSize, TLSConfig: opt.TLSConfig, Limiter: opt.Limiter, diff --git a/vendor/github.com/redis/go-redis/v9/search_commands.go b/vendor/github.com/redis/go-redis/v9/search_commands.go index 9018b3de..0fef8ffc 100644 --- a/vendor/github.com/redis/go-redis/v9/search_commands.go +++ b/vendor/github.com/redis/go-redis/v9/search_commands.go @@ -372,12 +372,18 @@ const ( // FTHybridVectorExpression represents a vector expression in hybrid search type FTHybridVectorExpression struct { - VectorField string - VectorData Vector - Method FTHybridVectorMethod - MethodParams []interface{} - Filter string - YieldScoreAs string + VectorField string + VectorData Vector + // VectorParamName specifies the parameter name for passing vector data via PARAMS mechanism. + // REQUIRED for Redis 8.6+ (inline vector blobs are not supported in 8.6+). + // Optional for Redis 8.4-8.5 (both inline and PARAMS are supported). + // When set, the vector blob will be passed as: VSIM @field $VectorParamName PARAMS ... VectorParamName + // When empty, the vector blob will be inlined: VSIM @field (fails on Redis 8.6+) + VectorParamName string + Method FTHybridVectorMethod + MethodParams []interface{} + Filter string + YieldScoreAs string } // FTHybridCombineOptions represents options for result fusion @@ -768,8 +774,9 @@ func ProcessAggregateResult(data []interface{}) (*FTAggregateResult, error) { func NewAggregateCmd(ctx context.Context, args ...interface{}) *AggregateCmd { return &AggregateCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeAggregate, }, } } @@ -810,6 +817,31 @@ func (cmd *AggregateCmd) readReply(rd *proto.Reader) (err error) { return nil } +func (cmd *AggregateCmd) Clone() Cmder { + var val *FTAggregateResult + if cmd.val != nil { + val = &FTAggregateResult{ + Total: cmd.val.Total, + } + if cmd.val.Rows != nil { + val.Rows = make([]AggregateRow, len(cmd.val.Rows)) + for i, row := range cmd.val.Rows { + val.Rows[i] = AggregateRow{} + if row.Fields != nil { + val.Rows[i].Fields = make(map[string]interface{}, len(row.Fields)) + for k, v := range row.Fields { + val.Rows[i].Fields[k] = v + } + } + } + } + } + return &AggregateCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + // FTAggregateWithArgs - Performs a search query on an index and applies a series of aggregate transformations to the result. // The 'index' parameter specifies the index to search, and the 'query' parameter specifies the search query. // This function also allows for specifying additional options such as: Verbatim, LoadAll, Load, Timeout, GroupBy, SortBy, SortByMax, Apply, LimitOffset, Limit, Filter, WithCursor, Params, and DialectVersion. @@ -1597,8 +1629,9 @@ type FTInfoCmd struct { func newFTInfoCmd(ctx context.Context, args ...interface{}) *FTInfoCmd { return &FTInfoCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeFTInfo, }, } } @@ -1660,6 +1693,68 @@ func (cmd *FTInfoCmd) readReply(rd *proto.Reader) (err error) { return nil } +func (cmd *FTInfoCmd) Clone() Cmder { + val := FTInfoResult{ + IndexErrors: cmd.val.IndexErrors, + BytesPerRecordAvg: cmd.val.BytesPerRecordAvg, + Cleaning: cmd.val.Cleaning, + CursorStats: cmd.val.CursorStats, + DocTableSizeMB: cmd.val.DocTableSizeMB, + GCStats: cmd.val.GCStats, + GeoshapesSzMB: cmd.val.GeoshapesSzMB, + HashIndexingFailures: cmd.val.HashIndexingFailures, + IndexDefinition: cmd.val.IndexDefinition, + IndexName: cmd.val.IndexName, + Indexing: cmd.val.Indexing, + InvertedSzMB: cmd.val.InvertedSzMB, + KeyTableSizeMB: cmd.val.KeyTableSizeMB, + MaxDocID: cmd.val.MaxDocID, + NumDocs: cmd.val.NumDocs, + NumRecords: cmd.val.NumRecords, + NumTerms: cmd.val.NumTerms, + NumberOfUses: cmd.val.NumberOfUses, + OffsetBitsPerRecordAvg: cmd.val.OffsetBitsPerRecordAvg, + OffsetVectorsSzMB: cmd.val.OffsetVectorsSzMB, + OffsetsPerTermAvg: cmd.val.OffsetsPerTermAvg, + PercentIndexed: cmd.val.PercentIndexed, + RecordsPerDocAvg: cmd.val.RecordsPerDocAvg, + SortableValuesSizeMB: cmd.val.SortableValuesSizeMB, + TagOverheadSzMB: cmd.val.TagOverheadSzMB, + TextOverheadSzMB: cmd.val.TextOverheadSzMB, + TotalIndexMemorySzMB: cmd.val.TotalIndexMemorySzMB, + TotalIndexingTime: cmd.val.TotalIndexingTime, + TotalInvertedIndexBlocks: cmd.val.TotalInvertedIndexBlocks, + VectorIndexSzMB: cmd.val.VectorIndexSzMB, + } + // Clone slices and maps + if cmd.val.Attributes != nil { + val.Attributes = make([]FTAttribute, len(cmd.val.Attributes)) + copy(val.Attributes, cmd.val.Attributes) + } + if cmd.val.DialectStats != nil { + val.DialectStats = make(map[string]int, len(cmd.val.DialectStats)) + for k, v := range cmd.val.DialectStats { + val.DialectStats[k] = v + } + } + if cmd.val.FieldStatistics != nil { + val.FieldStatistics = make([]FieldStatistic, len(cmd.val.FieldStatistics)) + copy(val.FieldStatistics, cmd.val.FieldStatistics) + } + if cmd.val.IndexOptions != nil { + val.IndexOptions = make([]string, len(cmd.val.IndexOptions)) + copy(val.IndexOptions, cmd.val.IndexOptions) + } + if cmd.val.IndexDefinition.Prefixes != nil { + val.IndexDefinition.Prefixes = make([]string, len(cmd.val.IndexDefinition.Prefixes)) + copy(val.IndexDefinition.Prefixes, cmd.val.IndexDefinition.Prefixes) + } + return &FTInfoCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + // FTInfo - Retrieves information about an index. // The 'index' parameter specifies the index to retrieve information about. // For more information, please refer to the Redis documentation: @@ -1716,8 +1811,9 @@ type FTSpellCheckCmd struct { func newFTSpellCheckCmd(ctx context.Context, args ...interface{}) *FTSpellCheckCmd { return &FTSpellCheckCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeFTSpellCheck, }, } } @@ -1813,6 +1909,26 @@ func parseFTSpellCheck(data []interface{}) ([]SpellCheckResult, error) { return results, nil } +func (cmd *FTSpellCheckCmd) Clone() Cmder { + var val []SpellCheckResult + if cmd.val != nil { + val = make([]SpellCheckResult, len(cmd.val)) + for i, result := range cmd.val { + val[i] = SpellCheckResult{ + Term: result.Term, + } + if result.Suggestions != nil { + val[i].Suggestions = make([]SpellCheckSuggestion, len(result.Suggestions)) + copy(val[i].Suggestions, result.Suggestions) + } + } + } + return &FTSpellCheckCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + func parseFTSearch(data []interface{}, noContent, withScores, withPayloads, withSortKeys bool) (FTSearchResult, error) { if len(data) < 1 { return FTSearchResult{}, fmt.Errorf("unexpected search result format") @@ -1909,8 +2025,9 @@ type FTSearchCmd struct { func newFTSearchCmd(ctx context.Context, options *FTSearchOptions, args ...interface{}) *FTSearchCmd { return &FTSearchCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeFTSearch, }, options: options, } @@ -1952,6 +2069,89 @@ func (cmd *FTSearchCmd) readReply(rd *proto.Reader) (err error) { return nil } +func (cmd *FTSearchCmd) Clone() Cmder { + val := FTSearchResult{ + Total: cmd.val.Total, + } + if cmd.val.Docs != nil { + val.Docs = make([]Document, len(cmd.val.Docs)) + for i, doc := range cmd.val.Docs { + val.Docs[i] = Document{ + ID: doc.ID, + Score: doc.Score, + Payload: doc.Payload, + SortKey: doc.SortKey, + } + if doc.Fields != nil { + val.Docs[i].Fields = make(map[string]string, len(doc.Fields)) + for k, v := range doc.Fields { + val.Docs[i].Fields[k] = v + } + } + } + } + var options *FTSearchOptions + if cmd.options != nil { + options = &FTSearchOptions{ + NoContent: cmd.options.NoContent, + Verbatim: cmd.options.Verbatim, + NoStopWords: cmd.options.NoStopWords, + WithScores: cmd.options.WithScores, + WithPayloads: cmd.options.WithPayloads, + WithSortKeys: cmd.options.WithSortKeys, + Slop: cmd.options.Slop, + Timeout: cmd.options.Timeout, + InOrder: cmd.options.InOrder, + Language: cmd.options.Language, + Expander: cmd.options.Expander, + Scorer: cmd.options.Scorer, + ExplainScore: cmd.options.ExplainScore, + Payload: cmd.options.Payload, + SortByWithCount: cmd.options.SortByWithCount, + LimitOffset: cmd.options.LimitOffset, + Limit: cmd.options.Limit, + CountOnly: cmd.options.CountOnly, + DialectVersion: cmd.options.DialectVersion, + } + // Clone slices and maps + if cmd.options.Filters != nil { + options.Filters = make([]FTSearchFilter, len(cmd.options.Filters)) + copy(options.Filters, cmd.options.Filters) + } + if cmd.options.GeoFilter != nil { + options.GeoFilter = make([]FTSearchGeoFilter, len(cmd.options.GeoFilter)) + copy(options.GeoFilter, cmd.options.GeoFilter) + } + if cmd.options.InKeys != nil { + options.InKeys = make([]interface{}, len(cmd.options.InKeys)) + copy(options.InKeys, cmd.options.InKeys) + } + if cmd.options.InFields != nil { + options.InFields = make([]interface{}, len(cmd.options.InFields)) + copy(options.InFields, cmd.options.InFields) + } + if cmd.options.Return != nil { + options.Return = make([]FTSearchReturn, len(cmd.options.Return)) + copy(options.Return, cmd.options.Return) + } + if cmd.options.SortBy != nil { + options.SortBy = make([]FTSearchSortBy, len(cmd.options.SortBy)) + copy(options.SortBy, cmd.options.SortBy) + } + if cmd.options.Params != nil { + options.Params = make(map[string]interface{}, len(cmd.options.Params)) + for k, v := range cmd.options.Params { + options.Params[k] = v + } + } + } + return &FTSearchCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + options: options, + } +} + // FTHybridResult represents the result of a hybrid search operation type FTHybridResult struct { TotalResults int @@ -2153,6 +2353,111 @@ func (cmd *FTHybridCmd) readReply(rd *proto.Reader) (err error) { return nil } +func (cmd *FTHybridCmd) Clone() Cmder { + val := FTHybridResult{ + TotalResults: cmd.val.TotalResults, + ExecutionTime: cmd.val.ExecutionTime, + } + if cmd.val.Results != nil { + val.Results = make([]map[string]interface{}, len(cmd.val.Results)) + for i, result := range cmd.val.Results { + val.Results[i] = make(map[string]interface{}, len(result)) + for k, v := range result { + val.Results[i][k] = v + } + } + } + if cmd.val.Warnings != nil { + val.Warnings = make([]string, len(cmd.val.Warnings)) + copy(val.Warnings, cmd.val.Warnings) + } + + var cursorVal *FTHybridCursorResult + if cmd.cursorVal != nil { + cursorVal = &FTHybridCursorResult{ + SearchCursorID: cmd.cursorVal.SearchCursorID, + VsimCursorID: cmd.cursorVal.VsimCursorID, + } + } + + var options *FTHybridOptions + if cmd.options != nil { + options = &FTHybridOptions{ + CountExpressions: cmd.options.CountExpressions, + Load: cmd.options.Load, + Filter: cmd.options.Filter, + LimitOffset: cmd.options.LimitOffset, + Limit: cmd.options.Limit, + ExplainScore: cmd.options.ExplainScore, + Timeout: cmd.options.Timeout, + WithCursor: cmd.options.WithCursor, + } + // Clone slices and maps + if cmd.options.SearchExpressions != nil { + options.SearchExpressions = make([]FTHybridSearchExpression, len(cmd.options.SearchExpressions)) + copy(options.SearchExpressions, cmd.options.SearchExpressions) + } + if cmd.options.VectorExpressions != nil { + options.VectorExpressions = make([]FTHybridVectorExpression, len(cmd.options.VectorExpressions)) + copy(options.VectorExpressions, cmd.options.VectorExpressions) + } + if cmd.options.Combine != nil { + options.Combine = &FTHybridCombineOptions{ + Method: cmd.options.Combine.Method, + Count: cmd.options.Combine.Count, + Window: cmd.options.Combine.Window, + Constant: cmd.options.Combine.Constant, + Alpha: cmd.options.Combine.Alpha, + Beta: cmd.options.Combine.Beta, + YieldScoreAs: cmd.options.Combine.YieldScoreAs, + } + } + if cmd.options.GroupBy != nil { + options.GroupBy = &FTHybridGroupBy{ + Count: cmd.options.GroupBy.Count, + ReduceFunc: cmd.options.GroupBy.ReduceFunc, + ReduceCount: cmd.options.GroupBy.ReduceCount, + } + if cmd.options.GroupBy.Fields != nil { + options.GroupBy.Fields = make([]string, len(cmd.options.GroupBy.Fields)) + copy(options.GroupBy.Fields, cmd.options.GroupBy.Fields) + } + if cmd.options.GroupBy.ReduceParams != nil { + options.GroupBy.ReduceParams = make([]interface{}, len(cmd.options.GroupBy.ReduceParams)) + copy(options.GroupBy.ReduceParams, cmd.options.GroupBy.ReduceParams) + } + } + if cmd.options.Apply != nil { + options.Apply = make([]FTHybridApply, len(cmd.options.Apply)) + copy(options.Apply, cmd.options.Apply) + } + if cmd.options.SortBy != nil { + options.SortBy = make([]FTSearchSortBy, len(cmd.options.SortBy)) + copy(options.SortBy, cmd.options.SortBy) + } + if cmd.options.Params != nil { + options.Params = make(map[string]interface{}, len(cmd.options.Params)) + for k, v := range cmd.options.Params { + options.Params[k] = v + } + } + if cmd.options.WithCursorOptions != nil { + options.WithCursorOptions = &FTHybridWithCursor{ + MaxIdle: cmd.options.WithCursorOptions.MaxIdle, + Count: cmd.options.WithCursorOptions.Count, + } + } + } + + return &FTHybridCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + cursorVal: cursorVal, + options: options, + withCursor: cmd.withCursor, + } +} + // FTSearch - Executes a search query on an index. // The 'index' parameter specifies the index to search, and the 'query' parameter specifies the search query. // For more information, please refer to the Redis documentation about [FT.SEARCH]. @@ -2412,8 +2717,9 @@ func (c cmdable) FTSearchWithArgs(ctx context.Context, index string, query strin func NewFTSynDumpCmd(ctx context.Context, args ...interface{}) *FTSynDumpCmd { return &FTSynDumpCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeFTSynDump, }, } } @@ -2479,6 +2785,26 @@ func (cmd *FTSynDumpCmd) readReply(rd *proto.Reader) error { return nil } +func (cmd *FTSynDumpCmd) Clone() Cmder { + var val []FTSynDumpResult + if cmd.val != nil { + val = make([]FTSynDumpResult, len(cmd.val)) + for i, result := range cmd.val { + val[i] = FTSynDumpResult{ + Term: result.Term, + } + if result.Synonyms != nil { + val[i].Synonyms = make([]string, len(result.Synonyms)) + copy(val[i].Synonyms, result.Synonyms) + } + } + } + return &FTSynDumpCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + // FTSynDump - Dumps the contents of a synonym group. // The 'index' parameter specifies the index to dump. // For more information, please refer to the Redis documentation: @@ -2572,12 +2898,27 @@ func (c cmdable) FTHybridWithArgs(ctx context.Context, index string, options *FT // For FT.HYBRID, we need to send just the raw vector bytes, not the Value() format // Value() returns [format, data] but FT.HYBRID expects just the blob vectorValue := vectorExpr.VectorData.Value() + var vectorBlob interface{} if len(vectorValue) >= 2 { // vectorValue is [format, data, ...] - we only want the data part - args = append(args, vectorValue[1]) + vectorBlob = vectorValue[1] } else { // Fallback for unexpected format - args = append(args, vectorValue...) + vectorBlob = vectorValue + } + + // If VectorParamName is provided, use PARAMS mechanism (required for Redis 8.6+) + // If not provided, inline the vector blob (works on Redis 8.4/8.5, fails on 8.6+) + if vectorExpr.VectorParamName != "" { + // Use PARAMS mechanism + args = append(args, "$"+vectorExpr.VectorParamName) + if options.Params == nil { + options.Params = make(map[string]interface{}) + } + options.Params[vectorExpr.VectorParamName] = vectorBlob + } else { + // Inline the vector blob (deprecated in Redis 8.6+) + args = append(args, vectorBlob) } if vectorExpr.Method != "" { diff --git a/vendor/github.com/redis/go-redis/v9/sentinel.go b/vendor/github.com/redis/go-redis/v9/sentinel.go index b393a589..24646c14 100644 --- a/vendor/github.com/redis/go-redis/v9/sentinel.go +++ b/vendor/github.com/redis/go-redis/v9/sentinel.go @@ -16,7 +16,6 @@ import ( "github.com/redis/go-redis/v9/internal" "github.com/redis/go-redis/v9/internal/pool" "github.com/redis/go-redis/v9/internal/rand" - "github.com/redis/go-redis/v9/internal/util" "github.com/redis/go-redis/v9/maintnotifications" "github.com/redis/go-redis/v9/push" ) @@ -121,11 +120,16 @@ type FailoverOptions struct { PoolFIFO bool - PoolSize int - PoolTimeout time.Duration - MinIdleConns int - MaxIdleConns int - MaxActiveConns int + PoolSize int + + // MaxConcurrentDials is the maximum number of concurrent connection creation goroutines. + // If <= 0, defaults to PoolSize. If > PoolSize, it will be capped at PoolSize. + MaxConcurrentDials int + + PoolTimeout time.Duration + MinIdleConns int + MaxIdleConns int + MaxActiveConns int ConnMaxIdleTime time.Duration ConnMaxLifetime time.Duration ConnMaxLifetimeJitter time.Duration @@ -153,6 +157,10 @@ type FailoverOptions struct { UnstableResp3 bool + // PushNotificationProcessor is the processor for handling push notifications. + // If nil, a default processor will be created for RESP3 connections. + PushNotificationProcessor push.NotificationProcessor + // MaintNotificationsConfig is not supported for FailoverClients at the moment // MaintNotificationsConfig provides custom configuration for maintnotifications upgrades. // When MaintNotificationsConfig.Mode is not "disabled", the client will handle @@ -186,19 +194,21 @@ func (opt *FailoverOptions) clientOptions() *Options { ReadBufferSize: opt.ReadBufferSize, WriteBufferSize: opt.WriteBufferSize, - DialTimeout: opt.DialTimeout, - DialerRetries: opt.DialerRetries, - DialerRetryTimeout: opt.DialerRetryTimeout, - ReadTimeout: opt.ReadTimeout, - WriteTimeout: opt.WriteTimeout, + DialTimeout: opt.DialTimeout, + DialerRetries: opt.DialerRetries, + DialerRetryTimeout: opt.DialerRetryTimeout, + ReadTimeout: opt.ReadTimeout, + WriteTimeout: opt.WriteTimeout, + ContextTimeoutEnabled: opt.ContextTimeoutEnabled, - PoolFIFO: opt.PoolFIFO, - PoolSize: opt.PoolSize, - PoolTimeout: opt.PoolTimeout, - MinIdleConns: opt.MinIdleConns, - MaxIdleConns: opt.MaxIdleConns, - MaxActiveConns: opt.MaxActiveConns, + PoolFIFO: opt.PoolFIFO, + PoolSize: opt.PoolSize, + MaxConcurrentDials: opt.MaxConcurrentDials, + PoolTimeout: opt.PoolTimeout, + MinIdleConns: opt.MinIdleConns, + MaxIdleConns: opt.MaxIdleConns, + MaxActiveConns: opt.MaxActiveConns, ConnMaxIdleTime: opt.ConnMaxIdleTime, ConnMaxLifetime: opt.ConnMaxLifetime, ConnMaxLifetimeJitter: opt.ConnMaxLifetimeJitter, @@ -208,8 +218,9 @@ func (opt *FailoverOptions) clientOptions() *Options { DisableIdentity: opt.DisableIdentity, DisableIndentity: opt.DisableIndentity, - IdentitySuffix: opt.IdentitySuffix, - UnstableResp3: opt.UnstableResp3, + IdentitySuffix: opt.IdentitySuffix, + UnstableResp3: opt.UnstableResp3, + PushNotificationProcessor: opt.PushNotificationProcessor, MaintNotificationsConfig: &maintnotifications.Config{ Mode: maintnotifications.ModeDisabled, @@ -237,19 +248,21 @@ func (opt *FailoverOptions) sentinelOptions(addr string) *Options { ReadBufferSize: 4096, WriteBufferSize: 4096, - DialTimeout: opt.DialTimeout, - DialerRetries: opt.DialerRetries, - DialerRetryTimeout: opt.DialerRetryTimeout, - ReadTimeout: opt.ReadTimeout, - WriteTimeout: opt.WriteTimeout, + DialTimeout: opt.DialTimeout, + DialerRetries: opt.DialerRetries, + DialerRetryTimeout: opt.DialerRetryTimeout, + ReadTimeout: opt.ReadTimeout, + WriteTimeout: opt.WriteTimeout, + ContextTimeoutEnabled: opt.ContextTimeoutEnabled, - PoolFIFO: opt.PoolFIFO, - PoolSize: opt.PoolSize, - PoolTimeout: opt.PoolTimeout, - MinIdleConns: opt.MinIdleConns, - MaxIdleConns: opt.MaxIdleConns, - MaxActiveConns: opt.MaxActiveConns, + PoolFIFO: opt.PoolFIFO, + PoolSize: opt.PoolSize, + MaxConcurrentDials: opt.MaxConcurrentDials, + PoolTimeout: opt.PoolTimeout, + MinIdleConns: opt.MinIdleConns, + MaxIdleConns: opt.MaxIdleConns, + MaxActiveConns: opt.MaxActiveConns, ConnMaxIdleTime: opt.ConnMaxIdleTime, ConnMaxLifetime: opt.ConnMaxLifetime, ConnMaxLifetimeJitter: opt.ConnMaxLifetimeJitter, @@ -259,8 +272,9 @@ func (opt *FailoverOptions) sentinelOptions(addr string) *Options { DisableIdentity: opt.DisableIdentity, DisableIndentity: opt.DisableIndentity, - IdentitySuffix: opt.IdentitySuffix, - UnstableResp3: opt.UnstableResp3, + IdentitySuffix: opt.IdentitySuffix, + UnstableResp3: opt.UnstableResp3, + PushNotificationProcessor: opt.PushNotificationProcessor, MaintNotificationsConfig: &maintnotifications.Config{ Mode: maintnotifications.ModeDisabled, @@ -294,26 +308,31 @@ func (opt *FailoverOptions) clusterOptions() *ClusterOptions { ReadBufferSize: opt.ReadBufferSize, WriteBufferSize: opt.WriteBufferSize, - DialTimeout: opt.DialTimeout, - ReadTimeout: opt.ReadTimeout, - WriteTimeout: opt.WriteTimeout, + DialTimeout: opt.DialTimeout, + DialerRetries: opt.DialerRetries, + DialerRetryTimeout: opt.DialerRetryTimeout, + ReadTimeout: opt.ReadTimeout, + WriteTimeout: opt.WriteTimeout, + ContextTimeoutEnabled: opt.ContextTimeoutEnabled, - PoolFIFO: opt.PoolFIFO, - PoolSize: opt.PoolSize, - PoolTimeout: opt.PoolTimeout, - MinIdleConns: opt.MinIdleConns, - MaxIdleConns: opt.MaxIdleConns, - MaxActiveConns: opt.MaxActiveConns, - ConnMaxIdleTime: opt.ConnMaxIdleTime, - ConnMaxLifetime: opt.ConnMaxLifetime, + PoolFIFO: opt.PoolFIFO, + PoolSize: opt.PoolSize, + MaxConcurrentDials: opt.MaxConcurrentDials, + PoolTimeout: opt.PoolTimeout, + MinIdleConns: opt.MinIdleConns, + MaxIdleConns: opt.MaxIdleConns, + MaxActiveConns: opt.MaxActiveConns, + ConnMaxIdleTime: opt.ConnMaxIdleTime, + ConnMaxLifetime: opt.ConnMaxLifetime, TLSConfig: opt.TLSConfig, - DisableIdentity: opt.DisableIdentity, - DisableIndentity: opt.DisableIndentity, - IdentitySuffix: opt.IdentitySuffix, - FailingTimeoutSeconds: opt.FailingTimeoutSeconds, + DisableIdentity: opt.DisableIdentity, + DisableIndentity: opt.DisableIndentity, + IdentitySuffix: opt.IdentitySuffix, + FailingTimeoutSeconds: opt.FailingTimeoutSeconds, + PushNotificationProcessor: opt.PushNotificationProcessor, MaintNotificationsConfig: &maintnotifications.Config{ Mode: maintnotifications.ModeDisabled, @@ -417,17 +436,20 @@ func setupFailoverConnParams(u *url.URL, o *FailoverOptions) (*FailoverOptions, o.MinRetryBackoff = q.duration("min_retry_backoff") o.MaxRetryBackoff = q.duration("max_retry_backoff") o.DialTimeout = q.duration("dial_timeout") + o.DialerRetries = q.int("dialer_retries") + o.DialerRetryTimeout = q.duration("dialer_retry_timeout") o.ReadTimeout = q.duration("read_timeout") o.WriteTimeout = q.duration("write_timeout") o.ContextTimeoutEnabled = q.bool("context_timeout_enabled") o.PoolFIFO = q.bool("pool_fifo") o.PoolSize = q.int("pool_size") + o.MaxConcurrentDials = q.int("max_concurrent_dials") o.MinIdleConns = q.int("min_idle_conns") o.MaxIdleConns = q.int("max_idle_conns") o.MaxActiveConns = q.int("max_active_conns") o.ConnMaxLifetime = q.duration("conn_max_lifetime") if q.has("conn_max_lifetime_jitter") { - o.ConnMaxLifetimeJitter = util.MinDuration(q.duration("conn_max_lifetime_jitter"), o.ConnMaxLifetime) + o.ConnMaxLifetimeJitter = min(q.duration("conn_max_lifetime_jitter"), o.ConnMaxLifetime) } o.ConnMaxIdleTime = q.duration("conn_max_idle_time") o.PoolTimeout = q.duration("pool_timeout") @@ -511,12 +533,17 @@ func NewFailoverClient(failoverOpt *FailoverOptions) *Client { // Use void processor by default for RESP2 connections rdb.pushProcessor = initializePushProcessor(opt) + // Generate unique pool names for metrics + uniqueID := generateUniqueID() + mainPoolName := opt.Addr + "_" + uniqueID + pubsubPoolName := opt.Addr + "_" + uniqueID + "_pubsub" + var err error - rdb.connPool, err = newConnPool(opt, rdb.dialHook) + rdb.connPool, err = newConnPool(opt, rdb.dialHook, mainPoolName) if err != nil { panic(fmt.Errorf("redis: failed to create connection pool: %w", err)) } - rdb.pubSubPool, err = newPubSubPool(opt, rdb.dialHook) + rdb.pubSubPool, err = newPubSubPool(opt, rdb.dialHook, pubsubPoolName) if err != nil { panic(fmt.Errorf("redis: failed to create pubsub pool: %w", err)) } @@ -595,12 +622,18 @@ func NewSentinelClient(opt *Options) *SentinelClient { dial: c.baseClient.dial, process: c.baseClient.process, }) + + // Generate unique pool names for metrics + uniqueID := generateUniqueID() + mainPoolName := opt.Addr + "_" + uniqueID + pubsubPoolName := opt.Addr + "_" + uniqueID + "_pubsub" + var err error - c.connPool, err = newConnPool(opt, c.dialHook) + c.connPool, err = newConnPool(opt, c.dialHook, mainPoolName) if err != nil { panic(fmt.Errorf("redis: failed to create connection pool: %w", err)) } - c.pubSubPool, err = newPubSubPool(opt, c.dialHook) + c.pubSubPool, err = newPubSubPool(opt, c.dialHook, pubsubPoolName) if err != nil { panic(fmt.Errorf("redis: failed to create pubsub pool: %w", err)) } @@ -848,7 +881,7 @@ func (c *sentinelFailover) MasterAddr(ctx context.Context) (string, error) { if sentinel != nil { addr, err := c.getMasterAddr(ctx, sentinel) if err != nil { - if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { + if isContextError(ctx.Err()) { return "", err } // Continue on other errors @@ -866,7 +899,7 @@ func (c *sentinelFailover) MasterAddr(ctx context.Context) (string, error) { addr, err := c.getMasterAddr(ctx, c.sentinel) if err != nil { _ = c.closeSentinel() - if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { + if isContextError(ctx.Err()) { return "", err } // Continue on other errors @@ -925,22 +958,7 @@ func (c *sentinelFailover) MasterAddr(ctx context.Context) (string, error) { for err := range errCh { errs = append(errs, err) } - return "", fmt.Errorf("redis: all sentinels specified in configuration are unreachable: %s", joinErrors(errs)) -} - -func joinErrors(errs []error) string { - if len(errs) == 0 { - return "" - } - if len(errs) == 1 { - return errs[0].Error() - } - b := []byte(errs[0].Error()) - for _, err := range errs[1:] { - b = append(b, '\n') - b = append(b, err.Error()...) - } - return util.BytesToString(b) + return "", fmt.Errorf("redis: all sentinels specified in configuration are unreachable: %w", errors.Join(errs...)) } func (c *sentinelFailover) replicaAddrs(ctx context.Context, useDisconnected bool) ([]string, error) { @@ -951,7 +969,7 @@ func (c *sentinelFailover) replicaAddrs(ctx context.Context, useDisconnected boo if sentinel != nil { addrs, err := c.getReplicaAddrs(ctx, sentinel) if err != nil { - if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { + if isContextError(ctx.Err()) { return nil, err } // Continue on other errors @@ -969,7 +987,7 @@ func (c *sentinelFailover) replicaAddrs(ctx context.Context, useDisconnected boo addrs, err := c.getReplicaAddrs(ctx, c.sentinel) if err != nil { _ = c.closeSentinel() - if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { + if isContextError(ctx.Err()) { return nil, err } // Continue on other errors @@ -991,7 +1009,7 @@ func (c *sentinelFailover) replicaAddrs(ctx context.Context, useDisconnected boo replicas, err := sentinel.Replicas(ctx, c.opt.MasterName).Result() if err != nil { _ = sentinel.Close() - if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { + if isContextError(ctx.Err()) { return nil, err } internal.Logger.Printf(ctx, "sentinel: Replicas master=%q failed: %s", diff --git a/vendor/github.com/redis/go-redis/v9/set_commands.go b/vendor/github.com/redis/go-redis/v9/set_commands.go index 79efa6e4..2a465728 100644 --- a/vendor/github.com/redis/go-redis/v9/set_commands.go +++ b/vendor/github.com/redis/go-redis/v9/set_commands.go @@ -6,6 +6,8 @@ import ( "github.com/redis/go-redis/v9/internal/hashtag" ) +// SetCmdable is an interface for Redis set commands. +// Sets are unordered collections of unique strings. type SetCmdable interface { SAdd(ctx context.Context, key string, members ...interface{}) *IntCmd SCard(ctx context.Context, key string) *IntCmd @@ -29,8 +31,12 @@ type SetCmdable interface { SUnionStore(ctx context.Context, destination string, keys ...string) *IntCmd } -//------------------------------------------------------------------------------ - +// Returns the number of elements that were added to the set, not including all +// the elements already present in the set. +// +// For more information about the command please refer to [SADD]. +// +// [SADD]: (https://redis.io/docs/latest/commands/sadd/) func (c cmdable) SAdd(ctx context.Context, key string, members ...interface{}) *IntCmd { args := make([]interface{}, 2, 2+len(members)) args[0] = "sadd" @@ -41,12 +47,25 @@ func (c cmdable) SAdd(ctx context.Context, key string, members ...interface{}) * return cmd } +// Returns the set cardinality (number of elements) of the set stored at key. +// Returns 0 if key does not exist. +// +// For more information about the command please refer to [SCARD]. +// +// [SCARD]: (https://redis.io/docs/latest/commands/scard/) func (c cmdable) SCard(ctx context.Context, key string) *IntCmd { cmd := NewIntCmd(ctx, "scard", key) _ = c(ctx, cmd) return cmd } +// Returns the members of the set resulting from the difference between the first set +// and all the successive sets. +// Keys that do not exist are considered to be empty sets. +// +// For more information about the command please refer to [SDIFF]. +// +// [SDIFF]: (https://redis.io/docs/latest/commands/sdiff/) func (c cmdable) SDiff(ctx context.Context, keys ...string) *StringSliceCmd { args := make([]interface{}, 1+len(keys)) args[0] = "sdiff" @@ -58,6 +77,13 @@ func (c cmdable) SDiff(ctx context.Context, keys ...string) *StringSliceCmd { return cmd } +// Stores the members of the set resulting from the difference between the first set +// and all the successive sets into destination. +// If destination already exists, it is overwritten. +// +// For more information about the command please refer to [SDIFFSTORE]. +// +// [SDIFFSTORE]: (https://redis.io/docs/latest/commands/sdiffstore/) func (c cmdable) SDiffStore(ctx context.Context, destination string, keys ...string) *IntCmd { args := make([]interface{}, 2+len(keys)) args[0] = "sdiffstore" @@ -70,6 +96,13 @@ func (c cmdable) SDiffStore(ctx context.Context, destination string, keys ...str return cmd } +// Returns the members of the set resulting from the intersection of all the given sets. +// Keys that do not exist are considered to be empty sets. +// With one of the keys being an empty set, the resulting set is also empty. +// +// For more information about the command please refer to [SINTER]. +// +// [SINTER]: (https://redis.io/docs/latest/commands/sinter/) func (c cmdable) SInter(ctx context.Context, keys ...string) *StringSliceCmd { args := make([]interface{}, 1+len(keys)) args[0] = "sinter" @@ -81,6 +114,16 @@ func (c cmdable) SInter(ctx context.Context, keys ...string) *StringSliceCmd { return cmd } +// Returns the cardinality of the set resulting from the intersection of all the given sets. +// Keys that do not exist are considered to be empty sets. +// With one of the keys being an empty set, the resulting set is also empty. +// +// The limit parameter sets an upper bound on the number of results returned. +// If limit is 0, no limit is applied. +// +// For more information about the command please refer to [SINTERCARD]. +// +// [SINTERCARD]: (https://redis.io/docs/latest/commands/sintercard/) func (c cmdable) SInterCard(ctx context.Context, limit int64, keys ...string) *IntCmd { numKeys := len(keys) args := make([]interface{}, 4+numKeys) @@ -96,6 +139,13 @@ func (c cmdable) SInterCard(ctx context.Context, limit int64, keys ...string) *I return cmd } +// Stores the members of the set resulting from the intersection of all the given sets +// into destination. +// If destination already exists, it is overwritten. +// +// For more information about the command please refer to [SINTERSTORE]. +// +// [SINTERSTORE]: (https://redis.io/docs/latest/commands/sinterstore/) func (c cmdable) SInterStore(ctx context.Context, destination string, keys ...string) *IntCmd { args := make([]interface{}, 2+len(keys)) args[0] = "sinterstore" @@ -108,13 +158,26 @@ func (c cmdable) SInterStore(ctx context.Context, destination string, keys ...st return cmd } +// Returns if member is a member of the set stored at key. +// Returns true if the element is a member of the set, false if it is not a member +// or if key does not exist. +// +// For more information about the command please refer to [SISMEMBER]. +// +// [SISMEMBER]: (https://redis.io/docs/latest/commands/sismember/) func (c cmdable) SIsMember(ctx context.Context, key string, member interface{}) *BoolCmd { cmd := NewBoolCmd(ctx, "sismember", key, member) _ = c(ctx, cmd) return cmd } -// SMIsMember Redis `SMISMEMBER key member [member ...]` command. +// Returns whether each member is a member of the set stored at key. +// For each member, returns true if the element is a member of the set, false if it is not +// a member or if key does not exist. +// +// For more information about the command please refer to [SMISMEMBER]. +// +// [SMISMEMBER]: (https://redis.io/docs/latest/commands/smismember/) func (c cmdable) SMIsMember(ctx context.Context, key string, members ...interface{}) *BoolSliceCmd { args := make([]interface{}, 2, 2+len(members)) args[0] = "smismember" @@ -125,54 +188,100 @@ func (c cmdable) SMIsMember(ctx context.Context, key string, members ...interfac return cmd } -// SMembers Redis `SMEMBERS key` command output as a slice. +// Returns all the members of the set value stored at key. +// Returns an empty slice if key does not exist. +// +// For more information about the command please refer to [SMEMBERS]. +// +// [SMEMBERS]: (https://redis.io/docs/latest/commands/smembers/) func (c cmdable) SMembers(ctx context.Context, key string) *StringSliceCmd { cmd := NewStringSliceCmd(ctx, "smembers", key) _ = c(ctx, cmd) return cmd } -// SMembersMap Redis `SMEMBERS key` command output as a map. +// Returns all the members of the set value stored at key as a map. +// Returns an empty map if key does not exist. +// +// For more information about the command please refer to [SMEMBERS]. +// +// [SMEMBERS]: (https://redis.io/docs/latest/commands/smembers/) func (c cmdable) SMembersMap(ctx context.Context, key string) *StringStructMapCmd { cmd := NewStringStructMapCmd(ctx, "smembers", key) _ = c(ctx, cmd) return cmd } +// Moves member from the set at source to the set at destination. +// This operation is atomic. In every given moment the element will appear to be a member +// of source or destination for other clients. +// +// For more information about the command please refer to [SMOVE]. +// +// [SMOVE]: (https://redis.io/docs/latest/commands/smove/) func (c cmdable) SMove(ctx context.Context, source, destination string, member interface{}) *BoolCmd { cmd := NewBoolCmd(ctx, "smove", source, destination, member) _ = c(ctx, cmd) return cmd } -// SPop Redis `SPOP key` command. +// Removes and returns one or more random members from the set value stored at key. +// This version returns a single random member. +// +// For more information about the command please refer to [SPOP]. +// +// [SPOP]: (https://redis.io/docs/latest/commands/spop/) func (c cmdable) SPop(ctx context.Context, key string) *StringCmd { cmd := NewStringCmd(ctx, "spop", key) _ = c(ctx, cmd) return cmd } -// SPopN Redis `SPOP key count` command. +// Removes and returns one or more random members from the set value stored at key. +// This version returns up to count random members. +// +// For more information about the command please refer to [SPOP]. +// +// [SPOP]: (https://redis.io/docs/latest/commands/spop/) func (c cmdable) SPopN(ctx context.Context, key string, count int64) *StringSliceCmd { cmd := NewStringSliceCmd(ctx, "spop", key, count) _ = c(ctx, cmd) return cmd } -// SRandMember Redis `SRANDMEMBER key` command. +// Returns a random member from the set value stored at key. +// This version returns a single random member without removing it. +// +// For more information about the command please refer to [SRANDMEMBER]. +// +// [SRANDMEMBER]: (https://redis.io/docs/latest/commands/srandmember/) func (c cmdable) SRandMember(ctx context.Context, key string) *StringCmd { cmd := NewStringCmd(ctx, "srandmember", key) _ = c(ctx, cmd) return cmd } -// SRandMemberN Redis `SRANDMEMBER key count` command. +// Returns an array of random members from the set value stored at key. +// This version returns up to count random members without removing them. +// When called with a positive count, returns distinct elements. +// When called with a negative count, allows for repeated elements. +// +// For more information about the command please refer to [SRANDMEMBER]. +// +// [SRANDMEMBER]: (https://redis.io/docs/latest/commands/srandmember/) func (c cmdable) SRandMemberN(ctx context.Context, key string, count int64) *StringSliceCmd { cmd := NewStringSliceCmd(ctx, "srandmember", key, count) _ = c(ctx, cmd) return cmd } +// Removes the specified members from the set stored at key. +// Specified members that are not a member of this set are ignored. +// If key does not exist, it is treated as an empty set and this command returns 0. +// +// For more information about the command please refer to [SREM]. +// +// [SREM]: (https://redis.io/docs/latest/commands/srem/) func (c cmdable) SRem(ctx context.Context, key string, members ...interface{}) *IntCmd { args := make([]interface{}, 2, 2+len(members)) args[0] = "srem" @@ -183,6 +292,12 @@ func (c cmdable) SRem(ctx context.Context, key string, members ...interface{}) * return cmd } +// Returns the members of the set resulting from the union of all the given sets. +// Keys that do not exist are considered to be empty sets. +// +// For more information about the command please refer to [SUNION]. +// +// [SUNION]: (https://redis.io/docs/latest/commands/sunion/) func (c cmdable) SUnion(ctx context.Context, keys ...string) *StringSliceCmd { args := make([]interface{}, 1+len(keys)) args[0] = "sunion" @@ -194,6 +309,13 @@ func (c cmdable) SUnion(ctx context.Context, keys ...string) *StringSliceCmd { return cmd } +// Stores the members of the set resulting from the union of all the given sets +// into destination. +// If destination already exists, it is overwritten. +// +// For more information about the command please refer to [SUNIONSTORE]. +// +// [SUNIONSTORE]: (https://redis.io/docs/latest/commands/sunionstore/) func (c cmdable) SUnionStore(ctx context.Context, destination string, keys ...string) *IntCmd { args := make([]interface{}, 2+len(keys)) args[0] = "sunionstore" @@ -206,6 +328,17 @@ func (c cmdable) SUnionStore(ctx context.Context, destination string, keys ...st return cmd } +// Incrementally iterates the set elements stored at key. +// This is a cursor-based iterator that allows scanning large sets efficiently. +// +// Parameters: +// - cursor: The cursor value for the iteration (use 0 to start a new scan) +// - match: Optional pattern to match elements (empty string means no pattern) +// - count: Optional hint about how many elements to return per iteration +// +// For more information about the command please refer to [SSCAN]. +// +// [SSCAN]: (https://redis.io/docs/latest/commands/sscan/) func (c cmdable) SScan(ctx context.Context, key string, cursor uint64, match string, count int64) *ScanCmd { args := []interface{}{"sscan", key, cursor} if match != "" { diff --git a/vendor/github.com/redis/go-redis/v9/sortedset_commands.go b/vendor/github.com/redis/go-redis/v9/sortedset_commands.go index 7827babc..4a6c8f13 100644 --- a/vendor/github.com/redis/go-redis/v9/sortedset_commands.go +++ b/vendor/github.com/redis/go-redis/v9/sortedset_commands.go @@ -479,10 +479,16 @@ func (c cmdable) zRangeBy(ctx context.Context, zcmd, key string, opt *ZRangeBy, return cmd } +// ZRangeByScore returns members in a sorted set within a range of scores. +// +// Deprecated: Use ZRangeArgs with ByScore option instead as of Redis 6.2.0. func (c cmdable) ZRangeByScore(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd { return c.zRangeBy(ctx, "zrangebyscore", key, opt, false) } +// ZRangeByLex returns members in a sorted set within a lexicographical range. +// +// Deprecated: Use ZRangeArgs with ByLex option instead as of Redis 6.2.0. func (c cmdable) ZRangeByLex(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd { return c.zRangeBy(ctx, "zrangebylex", key, opt, false) } @@ -559,6 +565,9 @@ func (c cmdable) ZRemRangeByLex(ctx context.Context, key, min, max string) *IntC return cmd } +// ZRevRange returns members in a sorted set within a range of indexes in reverse order. +// +// Deprecated: Use ZRangeArgs with Rev option instead as of Redis 6.2.0. func (c cmdable) ZRevRange(ctx context.Context, key string, start, stop int64) *StringSliceCmd { cmd := NewStringSliceCmd(ctx, "zrevrange", key, start, stop) _ = c(ctx, cmd) @@ -588,10 +597,16 @@ func (c cmdable) zRevRangeBy(ctx context.Context, zcmd, key string, opt *ZRangeB return cmd } +// ZRevRangeByScore returns members in a sorted set within a range of scores in reverse order. +// +// Deprecated: Use ZRangeArgs with Rev and ByScore options instead as of Redis 6.2.0. func (c cmdable) ZRevRangeByScore(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd { return c.zRevRangeBy(ctx, "zrevrangebyscore", key, opt) } +// ZRevRangeByLex returns members in a sorted set within a lexicographical range in reverse order. +// +// Deprecated: Use ZRangeArgs with Rev and ByLex options instead as of Redis 6.2.0. func (c cmdable) ZRevRangeByLex(ctx context.Context, key string, opt *ZRangeBy) *StringSliceCmd { return c.zRevRangeBy(ctx, "zrevrangebylex", key, opt) } diff --git a/vendor/github.com/redis/go-redis/v9/stream_commands.go b/vendor/github.com/redis/go-redis/v9/stream_commands.go index 5eb2e19c..89ae6a1b 100644 --- a/vendor/github.com/redis/go-redis/v9/stream_commands.go +++ b/vendor/github.com/redis/go-redis/v9/stream_commands.go @@ -2,7 +2,11 @@ package redis import ( "context" + "strconv" + "strings" "time" + + "github.com/redis/go-redis/v9/internal/otel" ) type StreamCmdable interface { @@ -43,6 +47,7 @@ type StreamCmdable interface { XInfoStream(ctx context.Context, key string) *XInfoStreamCmd XInfoStreamFull(ctx context.Context, key string, count int) *XInfoStreamFullCmd XInfoConsumers(ctx context.Context, key string, group string) *XInfoConsumersCmd + XCfgSet(ctx context.Context, a *XCfgSetArgs) *StatusCmd } // XAddArgs accepts values in the following formats: @@ -52,25 +57,51 @@ type StreamCmdable interface { // // Note that map will not preserve the order of key-value pairs. // MaxLen/MaxLenApprox and MinID are in conflict, only one of them can be used. +// +// For idempotent production (at-most-once production): +// - ProducerID: A unique identifier for the producer (required for both IDMP and IDMPAUTO) +// - IdempotentID: A unique identifier for the message (used with IDMP) +// - IdempotentAuto: If true, Redis will auto-generate an idempotent ID based on message content (IDMPAUTO) +// +// ProducerID and IdempotentID are mutually exclusive with IdempotentAuto. +// When using idempotent production, ID must be "*" or empty. type XAddArgs struct { Stream string NoMkStream bool MaxLen int64 // MAXLEN N MinID string // Approx causes MaxLen and MinID to use "~" matcher (instead of "="). - Approx bool - Limit int64 - Mode string - ID string - Values interface{} + Approx bool + Limit int64 + Mode string + ID string + Values interface{} + ProducerID string // Producer ID for idempotent production (IDMP or IDMPAUTO) + IdempotentID string // Idempotent ID for IDMP + IdempotentAuto bool // Use IDMPAUTO to auto-generate idempotent ID based on content } func (c cmdable) XAdd(ctx context.Context, a *XAddArgs) *StringCmd { - args := make([]interface{}, 0, 11) + args := make([]interface{}, 0, 15) args = append(args, "xadd", a.Stream) if a.NoMkStream { args = append(args, "nomkstream") } + + if a.Mode != "" { + args = append(args, a.Mode) + } + + if a.ProducerID != "" { + if a.IdempotentAuto { + // IDMPAUTO pid + args = append(args, "idmpauto", a.ProducerID) + } else if a.IdempotentID != "" { + // IDMP pid iid + args = append(args, "idmp", a.ProducerID, a.IdempotentID) + } + } + switch { case a.MaxLen > 0: if a.Approx { @@ -89,10 +120,6 @@ func (c cmdable) XAdd(ctx context.Context, a *XAddArgs) *StringCmd { args = append(args, "limit", a.Limit) } - if a.Mode != "" { - args = append(args, a.Mode) - } - if a.ID != "" { args = append(args, a.ID) } else { @@ -299,6 +326,26 @@ func (c cmdable) XReadGroup(ctx context.Context, a *XReadGroupArgs) *XStreamSlic } cmd.SetFirstKeyPos(keyPos) _ = c(ctx, cmd) + + // Record stream lag for each message (if command succeeded) + if cmd.Err() == nil { + streams := cmd.Val() + for _, stream := range streams { + for _, msg := range stream.Messages { + // Parse message ID to extract timestamp (format: "millisecondsTime-sequenceNumber") + if parts := strings.SplitN(msg.ID, "-", 2); len(parts) == 2 { + if timestampMs, err := strconv.ParseInt(parts[0], 10, 64); err == nil { + // Calculate lag (time since message was created) + messageTime := time.Unix(0, timestampMs*int64(time.Millisecond)) + lag := time.Since(messageTime) + // Record lag metric + otel.RecordStreamLag(ctx, lag, nil, stream.Stream, a.Group, a.Consumer) + } + } + } + } + } + return cmd } @@ -527,3 +574,28 @@ func (c cmdable) XInfoStreamFull(ctx context.Context, key string, count int) *XI _ = c(ctx, cmd) return cmd } + +// XCfgSetArgs represents the arguments for the XCFGSET command. +// Duration is the duration, in seconds, that Redis keeps each idempotent ID. +// MaxSize is the maximum number of most recent idempotent IDs that Redis keeps for each producer ID. +type XCfgSetArgs struct { + Stream string + Duration int64 + MaxSize int64 +} + +// XCfgSet sets the idempotent production configuration for a stream. +// XCFGSET key [IDMP-DURATION duration] [IDMP-MAXSIZE maxsize] +func (c cmdable) XCfgSet(ctx context.Context, a *XCfgSetArgs) *StatusCmd { + args := make([]interface{}, 0, 6) + args = append(args, "xcfgset", a.Stream) + if a.Duration > 0 { + args = append(args, "idmp-duration", a.Duration) + } + if a.MaxSize > 0 { + args = append(args, "idmp-maxsize", a.MaxSize) + } + cmd := NewStatusCmd(ctx, args...) + _ = c(ctx, cmd) + return cmd +} diff --git a/vendor/github.com/redis/go-redis/v9/string_commands.go b/vendor/github.com/redis/go-redis/v9/string_commands.go index f3c33f4c..f69d3d05 100644 --- a/vendor/github.com/redis/go-redis/v9/string_commands.go +++ b/vendor/github.com/redis/go-redis/v9/string_commands.go @@ -143,6 +143,9 @@ func (c cmdable) GetRange(ctx context.Context, key string, start, end int64) *St return cmd } +// GetSet returns the old value stored at key and sets it to the new value. +// +// Deprecated: Use SetArgs with Get option instead as of Redis 6.2.0. func (c cmdable) GetSet(ctx context.Context, key string, value interface{}) *StringCmd { cmd := NewStringCmd(ctx, "getset", key, value) _ = c(ctx, cmd) @@ -415,14 +418,18 @@ func (c cmdable) SetArgs(ctx context.Context, key string, value interface{}, a S return cmd } -// SetEx Redis `SETEx key expiration value` command. +// SetEx sets the value and expiration of a key. +// +// Deprecated: Use Set with expiration instead as of Redis 2.6.12. func (c cmdable) SetEx(ctx context.Context, key string, value interface{}, expiration time.Duration) *StatusCmd { cmd := NewStatusCmd(ctx, "setex", key, formatSec(ctx, expiration), value) _ = c(ctx, cmd) return cmd } -// SetNX Redis `SET key value [expiration] NX` command. +// SetNX sets the value of a key only if the key does not exist. +// +// Deprecated: Use Set with NX option instead as of Redis 2.6.12. // // Zero expiration means the key has no expiration time. // KeepTTL is a Redis KEEPTTL option to keep existing TTL, it requires your redis-server version >= 6.0, diff --git a/vendor/github.com/redis/go-redis/v9/timeseries_commands.go b/vendor/github.com/redis/go-redis/v9/timeseries_commands.go index 82d8cdfc..15d80168 100644 --- a/vendor/github.com/redis/go-redis/v9/timeseries_commands.go +++ b/vendor/github.com/redis/go-redis/v9/timeseries_commands.go @@ -2,9 +2,9 @@ package redis import ( "context" - "strconv" "github.com/redis/go-redis/v9/internal/proto" + "github.com/redis/go-redis/v9/internal/util" ) type TimeseriesCmdable interface { @@ -96,6 +96,8 @@ const ( VarP VarS Twa + CountNaN + CountAll ) func (a Aggregator) String() string { @@ -128,6 +130,10 @@ func (a Aggregator) String() string { return "VAR.S" case Twa: return "TWA" + case CountNaN: + return "COUNTNAN" + case CountAll: + return "COUNTALL" default: return "" } @@ -486,8 +492,9 @@ type TSTimestampValueCmd struct { func newTSTimestampValueCmd(ctx context.Context, args ...interface{}) *TSTimestampValueCmd { return &TSTimestampValueCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeTSTimestampValue, }, } } @@ -524,7 +531,7 @@ func (cmd *TSTimestampValueCmd) readReply(rd *proto.Reader) (err error) { return err } cmd.val.Timestamp = timestamp - cmd.val.Value, err = strconv.ParseFloat(value, 64) + cmd.val.Value, err = util.ParseStringToFloat(value) if err != nil { return err } @@ -533,6 +540,13 @@ func (cmd *TSTimestampValueCmd) readReply(rd *proto.Reader) (err error) { return nil } +func (cmd *TSTimestampValueCmd) Clone() Cmder { + return &TSTimestampValueCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: cmd.val, // TSTimestampValue is a simple struct, can be copied directly + } +} + // TSInfo - Returns information about a time-series key. // For more information - https://redis.io/commands/ts.info/ func (c cmdable) TSInfo(ctx context.Context, key string) *MapStringInterfaceCmd { @@ -704,8 +718,9 @@ type TSTimestampValueSliceCmd struct { func newTSTimestampValueSliceCmd(ctx context.Context, args ...interface{}) *TSTimestampValueSliceCmd { return &TSTimestampValueSliceCmd{ baseCmd: baseCmd{ - ctx: ctx, - args: args, + ctx: ctx, + args: args, + cmdType: CmdTypeTSTimestampValueSlice, }, } } @@ -743,7 +758,7 @@ func (cmd *TSTimestampValueSliceCmd) readReply(rd *proto.Reader) (err error) { return err } cmd.val[i].Timestamp = timestamp - cmd.val[i].Value, err = strconv.ParseFloat(value, 64) + cmd.val[i].Value, err = util.ParseStringToFloat(value) if err != nil { return err } @@ -752,6 +767,18 @@ func (cmd *TSTimestampValueSliceCmd) readReply(rd *proto.Reader) (err error) { return nil } +func (cmd *TSTimestampValueSliceCmd) Clone() Cmder { + var val []TSTimestampValue + if cmd.val != nil { + val = make([]TSTimestampValue, len(cmd.val)) + copy(val, cmd.val) + } + return &TSTimestampValueSliceCmd{ + baseCmd: cmd.cloneBaseCmd(), + val: val, + } +} + // TSMRange - Returns a range of samples from multiple time-series keys. // For more information - https://redis.io/commands/ts.mrange/ func (c cmdable) TSMRange(ctx context.Context, fromTimestamp int, toTimestamp int, filterExpr []string) *MapStringSliceInterfaceCmd { diff --git a/vendor/github.com/redis/go-redis/v9/universal.go b/vendor/github.com/redis/go-redis/v9/universal.go index c5951366..2531cb59 100644 --- a/vendor/github.com/redis/go-redis/v9/universal.go +++ b/vendor/github.com/redis/go-redis/v9/universal.go @@ -8,6 +8,7 @@ import ( "github.com/redis/go-redis/v9/auth" "github.com/redis/go-redis/v9/maintnotifications" + "github.com/redis/go-redis/v9/push" ) // UniversalOptions information is required by UniversalClient to establish @@ -57,7 +58,18 @@ type UniversalOptions struct { MinRetryBackoff time.Duration MaxRetryBackoff time.Duration - DialTimeout time.Duration + DialTimeout time.Duration + + // DialerRetries is the maximum number of retry attempts when dialing fails. + // + // default: 5 + DialerRetries int + + // DialerRetryTimeout is the backoff duration between retry attempts. + // + // default: 100 milliseconds + DialerRetryTimeout time.Duration + ReadTimeout time.Duration WriteTimeout time.Duration ContextTimeoutEnabled bool @@ -79,11 +91,16 @@ type UniversalOptions struct { // PoolFIFO uses FIFO mode for each node connection pool GET/PUT (default LIFO). PoolFIFO bool - PoolSize int - PoolTimeout time.Duration - MinIdleConns int - MaxIdleConns int - MaxActiveConns int + PoolSize int + + // MaxConcurrentDials is the maximum number of concurrent connection creation goroutines. + // If <= 0, defaults to PoolSize. If > PoolSize, it will be capped at PoolSize. + MaxConcurrentDials int + + PoolTimeout time.Duration + MinIdleConns int + MaxIdleConns int + MaxActiveConns int ConnMaxIdleTime time.Duration ConnMaxLifetime time.Duration ConnMaxLifetimeJitter time.Duration @@ -122,6 +139,10 @@ type UniversalOptions struct { UnstableResp3 bool + // PushNotificationProcessor is the processor for handling push notifications. + // If nil, a default processor will be created for RESP3 connections. + PushNotificationProcessor push.NotificationProcessor + // IsClusterMode can be used when only one Addrs is provided (e.g. Elasticache supports setting up cluster mode with configuration endpoint). IsClusterMode bool @@ -157,33 +178,37 @@ func (o *UniversalOptions) Cluster() *ClusterOptions { MinRetryBackoff: o.MinRetryBackoff, MaxRetryBackoff: o.MaxRetryBackoff, - DialTimeout: o.DialTimeout, - ReadTimeout: o.ReadTimeout, - WriteTimeout: o.WriteTimeout, + DialTimeout: o.DialTimeout, + DialerRetries: o.DialerRetries, + DialerRetryTimeout: o.DialerRetryTimeout, + ReadTimeout: o.ReadTimeout, + WriteTimeout: o.WriteTimeout, + ContextTimeoutEnabled: o.ContextTimeoutEnabled, ReadBufferSize: o.ReadBufferSize, WriteBufferSize: o.WriteBufferSize, - PoolFIFO: o.PoolFIFO, - - PoolSize: o.PoolSize, - PoolTimeout: o.PoolTimeout, - MinIdleConns: o.MinIdleConns, - MaxIdleConns: o.MaxIdleConns, - MaxActiveConns: o.MaxActiveConns, + PoolFIFO: o.PoolFIFO, + PoolSize: o.PoolSize, + MaxConcurrentDials: o.MaxConcurrentDials, + PoolTimeout: o.PoolTimeout, + MinIdleConns: o.MinIdleConns, + MaxIdleConns: o.MaxIdleConns, + MaxActiveConns: o.MaxActiveConns, ConnMaxIdleTime: o.ConnMaxIdleTime, ConnMaxLifetime: o.ConnMaxLifetime, ConnMaxLifetimeJitter: o.ConnMaxLifetimeJitter, TLSConfig: o.TLSConfig, - DisableIdentity: o.DisableIdentity, - DisableIndentity: o.DisableIndentity, - IdentitySuffix: o.IdentitySuffix, - FailingTimeoutSeconds: o.FailingTimeoutSeconds, - UnstableResp3: o.UnstableResp3, - MaintNotificationsConfig: o.MaintNotificationsConfig, + DisableIdentity: o.DisableIdentity, + DisableIndentity: o.DisableIndentity, + IdentitySuffix: o.IdentitySuffix, + FailingTimeoutSeconds: o.FailingTimeoutSeconds, + UnstableResp3: o.UnstableResp3, + PushNotificationProcessor: o.PushNotificationProcessor, + MaintNotificationsConfig: o.MaintNotificationsConfig, } } @@ -219,20 +244,24 @@ func (o *UniversalOptions) Failover() *FailoverOptions { MinRetryBackoff: o.MinRetryBackoff, MaxRetryBackoff: o.MaxRetryBackoff, - DialTimeout: o.DialTimeout, - ReadTimeout: o.ReadTimeout, - WriteTimeout: o.WriteTimeout, + DialTimeout: o.DialTimeout, + DialerRetries: o.DialerRetries, + DialerRetryTimeout: o.DialerRetryTimeout, + ReadTimeout: o.ReadTimeout, + WriteTimeout: o.WriteTimeout, + ContextTimeoutEnabled: o.ContextTimeoutEnabled, ReadBufferSize: o.ReadBufferSize, WriteBufferSize: o.WriteBufferSize, - PoolFIFO: o.PoolFIFO, - PoolSize: o.PoolSize, - PoolTimeout: o.PoolTimeout, - MinIdleConns: o.MinIdleConns, - MaxIdleConns: o.MaxIdleConns, - MaxActiveConns: o.MaxActiveConns, + PoolFIFO: o.PoolFIFO, + PoolSize: o.PoolSize, + MaxConcurrentDials: o.MaxConcurrentDials, + PoolTimeout: o.PoolTimeout, + MinIdleConns: o.MinIdleConns, + MaxIdleConns: o.MaxIdleConns, + MaxActiveConns: o.MaxActiveConns, ConnMaxIdleTime: o.ConnMaxIdleTime, ConnMaxLifetime: o.ConnMaxLifetime, ConnMaxLifetimeJitter: o.ConnMaxLifetimeJitter, @@ -241,10 +270,11 @@ func (o *UniversalOptions) Failover() *FailoverOptions { ReplicaOnly: o.ReadOnly, - DisableIdentity: o.DisableIdentity, - DisableIndentity: o.DisableIndentity, - IdentitySuffix: o.IdentitySuffix, - UnstableResp3: o.UnstableResp3, + DisableIdentity: o.DisableIdentity, + DisableIndentity: o.DisableIndentity, + IdentitySuffix: o.IdentitySuffix, + UnstableResp3: o.UnstableResp3, + PushNotificationProcessor: o.PushNotificationProcessor, // Note: MaintNotificationsConfig not supported for FailoverOptions } } @@ -274,30 +304,36 @@ func (o *UniversalOptions) Simple() *Options { MinRetryBackoff: o.MinRetryBackoff, MaxRetryBackoff: o.MaxRetryBackoff, - DialTimeout: o.DialTimeout, - ReadTimeout: o.ReadTimeout, - WriteTimeout: o.WriteTimeout, + DialTimeout: o.DialTimeout, + DialerRetries: o.DialerRetries, + DialerRetryTimeout: o.DialerRetryTimeout, + ReadTimeout: o.ReadTimeout, + WriteTimeout: o.WriteTimeout, + ContextTimeoutEnabled: o.ContextTimeoutEnabled, ReadBufferSize: o.ReadBufferSize, WriteBufferSize: o.WriteBufferSize, - PoolFIFO: o.PoolFIFO, - PoolSize: o.PoolSize, - PoolTimeout: o.PoolTimeout, - MinIdleConns: o.MinIdleConns, - MaxIdleConns: o.MaxIdleConns, - MaxActiveConns: o.MaxActiveConns, - ConnMaxIdleTime: o.ConnMaxIdleTime, - ConnMaxLifetime: o.ConnMaxLifetime, + PoolFIFO: o.PoolFIFO, + PoolSize: o.PoolSize, + MaxConcurrentDials: o.MaxConcurrentDials, + PoolTimeout: o.PoolTimeout, + MinIdleConns: o.MinIdleConns, + MaxIdleConns: o.MaxIdleConns, + MaxActiveConns: o.MaxActiveConns, + ConnMaxIdleTime: o.ConnMaxIdleTime, + ConnMaxLifetime: o.ConnMaxLifetime, + ConnMaxLifetimeJitter: o.ConnMaxLifetimeJitter, TLSConfig: o.TLSConfig, - DisableIdentity: o.DisableIdentity, - DisableIndentity: o.DisableIndentity, - IdentitySuffix: o.IdentitySuffix, - UnstableResp3: o.UnstableResp3, - MaintNotificationsConfig: o.MaintNotificationsConfig, + DisableIdentity: o.DisableIdentity, + DisableIndentity: o.DisableIndentity, + IdentitySuffix: o.IdentitySuffix, + UnstableResp3: o.UnstableResp3, + PushNotificationProcessor: o.PushNotificationProcessor, + MaintNotificationsConfig: o.MaintNotificationsConfig, } } diff --git a/vendor/github.com/redis/go-redis/v9/version.go b/vendor/github.com/redis/go-redis/v9/version.go index e198259f..49f001e5 100644 --- a/vendor/github.com/redis/go-redis/v9/version.go +++ b/vendor/github.com/redis/go-redis/v9/version.go @@ -2,5 +2,5 @@ package redis // Version is the current release version. func Version() string { - return "9.17.3" + return "9.18.0" } diff --git a/vendor/go.uber.org/atomic/.codecov.yml b/vendor/go.uber.org/atomic/.codecov.yml new file mode 100644 index 00000000..571116cc --- /dev/null +++ b/vendor/go.uber.org/atomic/.codecov.yml @@ -0,0 +1,19 @@ +coverage: + range: 80..100 + round: down + precision: 2 + + status: + project: # measuring the overall project coverage + default: # context, you can create multiple ones with custom titles + enabled: yes # must be yes|true to enable this status + target: 100 # specify the target coverage for each commit status + # option: "auto" (must increase from parent commit or pull request base) + # option: "X%" a static target percentage to hit + if_not_found: success # if parent is not found report status as success, error, or failure + if_ci_failed: error # if ci fails report status as success, error, or failure + +# Also update COVER_IGNORE_PKGS in the Makefile. +ignore: + - /internal/gen-atomicint/ + - /internal/gen-valuewrapper/ diff --git a/vendor/go.uber.org/atomic/.gitignore b/vendor/go.uber.org/atomic/.gitignore new file mode 100644 index 00000000..2e337a0e --- /dev/null +++ b/vendor/go.uber.org/atomic/.gitignore @@ -0,0 +1,15 @@ +/bin +.DS_Store +/vendor +cover.html +cover.out +lint.log + +# Binaries +*.test + +# Profiling output +*.prof + +# Output of fossa analyzer +/fossa diff --git a/vendor/go.uber.org/atomic/CHANGELOG.md b/vendor/go.uber.org/atomic/CHANGELOG.md new file mode 100644 index 00000000..6f87f33f --- /dev/null +++ b/vendor/go.uber.org/atomic/CHANGELOG.md @@ -0,0 +1,127 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [1.11.0] - 2023-05-02 +### Fixed +- Fix initialization of `Value` wrappers. + +### Added +- Add `String` method to `atomic.Pointer[T]` type allowing users to safely print +underlying values of pointers. + +[1.11.0]: https://github.com/uber-go/atomic/compare/v1.10.0...v1.11.0 + +## [1.10.0] - 2022-08-11 +### Added +- Add `atomic.Float32` type for atomic operations on `float32`. +- Add `CompareAndSwap` and `Swap` methods to `atomic.String`, `atomic.Error`, + and `atomic.Value`. +- Add generic `atomic.Pointer[T]` type for atomic operations on pointers of any + type. This is present only for Go 1.18 or higher, and is a drop-in for + replacement for the standard library's `sync/atomic.Pointer` type. + +### Changed +- Deprecate `CAS` methods on all types in favor of corresponding + `CompareAndSwap` methods. + +Thanks to @eNV25 and @icpd for their contributions to this release. + +[1.10.0]: https://github.com/uber-go/atomic/compare/v1.9.0...v1.10.0 + +## [1.9.0] - 2021-07-15 +### Added +- Add `Float64.Swap` to match int atomic operations. +- Add `atomic.Time` type for atomic operations on `time.Time` values. + +[1.9.0]: https://github.com/uber-go/atomic/compare/v1.8.0...v1.9.0 + +## [1.8.0] - 2021-06-09 +### Added +- Add `atomic.Uintptr` type for atomic operations on `uintptr` values. +- Add `atomic.UnsafePointer` type for atomic operations on `unsafe.Pointer` values. + +[1.8.0]: https://github.com/uber-go/atomic/compare/v1.7.0...v1.8.0 + +## [1.7.0] - 2020-09-14 +### Added +- Support JSON serialization and deserialization of primitive atomic types. +- Support Text marshalling and unmarshalling for string atomics. + +### Changed +- Disallow incorrect comparison of atomic values in a non-atomic way. + +### Removed +- Remove dependency on `golang.org/x/{lint, tools}`. + +[1.7.0]: https://github.com/uber-go/atomic/compare/v1.6.0...v1.7.0 + +## [1.6.0] - 2020-02-24 +### Changed +- Drop library dependency on `golang.org/x/{lint, tools}`. + +[1.6.0]: https://github.com/uber-go/atomic/compare/v1.5.1...v1.6.0 + +## [1.5.1] - 2019-11-19 +- Fix bug where `Bool.CAS` and `Bool.Toggle` do work correctly together + causing `CAS` to fail even though the old value matches. + +[1.5.1]: https://github.com/uber-go/atomic/compare/v1.5.0...v1.5.1 + +## [1.5.0] - 2019-10-29 +### Changed +- With Go modules, only the `go.uber.org/atomic` import path is supported now. + If you need to use the old import path, please add a `replace` directive to + your `go.mod`. + +[1.5.0]: https://github.com/uber-go/atomic/compare/v1.4.0...v1.5.0 + +## [1.4.0] - 2019-05-01 +### Added + - Add `atomic.Error` type for atomic operations on `error` values. + +[1.4.0]: https://github.com/uber-go/atomic/compare/v1.3.2...v1.4.0 + +## [1.3.2] - 2018-05-02 +### Added +- Add `atomic.Duration` type for atomic operations on `time.Duration` values. + +[1.3.2]: https://github.com/uber-go/atomic/compare/v1.3.1...v1.3.2 + +## [1.3.1] - 2017-11-14 +### Fixed +- Revert optimization for `atomic.String.Store("")` which caused data races. + +[1.3.1]: https://github.com/uber-go/atomic/compare/v1.3.0...v1.3.1 + +## [1.3.0] - 2017-11-13 +### Added +- Add `atomic.Bool.CAS` for compare-and-swap semantics on bools. + +### Changed +- Optimize `atomic.String.Store("")` by avoiding an allocation. + +[1.3.0]: https://github.com/uber-go/atomic/compare/v1.2.0...v1.3.0 + +## [1.2.0] - 2017-04-12 +### Added +- Shadow `atomic.Value` from `sync/atomic`. + +[1.2.0]: https://github.com/uber-go/atomic/compare/v1.1.0...v1.2.0 + +## [1.1.0] - 2017-03-10 +### Added +- Add atomic `Float64` type. + +### Changed +- Support new `go.uber.org/atomic` import path. + +[1.1.0]: https://github.com/uber-go/atomic/compare/v1.0.0...v1.1.0 + +## [1.0.0] - 2016-07-18 + +- Initial release. + +[1.0.0]: https://github.com/uber-go/atomic/releases/tag/v1.0.0 diff --git a/vendor/go.uber.org/atomic/LICENSE.txt b/vendor/go.uber.org/atomic/LICENSE.txt new file mode 100644 index 00000000..8765c9fb --- /dev/null +++ b/vendor/go.uber.org/atomic/LICENSE.txt @@ -0,0 +1,19 @@ +Copyright (c) 2016 Uber Technologies, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/go.uber.org/atomic/Makefile b/vendor/go.uber.org/atomic/Makefile new file mode 100644 index 00000000..46c945b3 --- /dev/null +++ b/vendor/go.uber.org/atomic/Makefile @@ -0,0 +1,79 @@ +# Directory to place `go install`ed binaries into. +export GOBIN ?= $(shell pwd)/bin + +GOLINT = $(GOBIN)/golint +GEN_ATOMICINT = $(GOBIN)/gen-atomicint +GEN_ATOMICWRAPPER = $(GOBIN)/gen-atomicwrapper +STATICCHECK = $(GOBIN)/staticcheck + +GO_FILES ?= $(shell find . '(' -path .git -o -path vendor ')' -prune -o -name '*.go' -print) + +# Also update ignore section in .codecov.yml. +COVER_IGNORE_PKGS = \ + go.uber.org/atomic/internal/gen-atomicint \ + go.uber.org/atomic/internal/gen-atomicwrapper + +.PHONY: build +build: + go build ./... + +.PHONY: test +test: + go test -race ./... + +.PHONY: gofmt +gofmt: + $(eval FMT_LOG := $(shell mktemp -t gofmt.XXXXX)) + gofmt -e -s -l $(GO_FILES) > $(FMT_LOG) || true + @[ ! -s "$(FMT_LOG)" ] || (echo "gofmt failed:" && cat $(FMT_LOG) && false) + +$(GOLINT): + cd tools && go install golang.org/x/lint/golint + +$(STATICCHECK): + cd tools && go install honnef.co/go/tools/cmd/staticcheck + +$(GEN_ATOMICWRAPPER): $(wildcard ./internal/gen-atomicwrapper/*) + go build -o $@ ./internal/gen-atomicwrapper + +$(GEN_ATOMICINT): $(wildcard ./internal/gen-atomicint/*) + go build -o $@ ./internal/gen-atomicint + +.PHONY: golint +golint: $(GOLINT) + $(GOLINT) ./... + +.PHONY: staticcheck +staticcheck: $(STATICCHECK) + $(STATICCHECK) ./... + +.PHONY: lint +lint: gofmt golint staticcheck generatenodirty + +# comma separated list of packages to consider for code coverage. +COVER_PKG = $(shell \ + go list -find ./... | \ + grep -v $(foreach pkg,$(COVER_IGNORE_PKGS),-e "^$(pkg)$$") | \ + paste -sd, -) + +.PHONY: cover +cover: + go test -coverprofile=cover.out -coverpkg $(COVER_PKG) -v ./... + go tool cover -html=cover.out -o cover.html + +.PHONY: generate +generate: $(GEN_ATOMICINT) $(GEN_ATOMICWRAPPER) + go generate ./... + +.PHONY: generatenodirty +generatenodirty: + @[ -z "$$(git status --porcelain)" ] || ( \ + echo "Working tree is dirty. Commit your changes first."; \ + git status; \ + exit 1 ) + @make generate + @status=$$(git status --porcelain); \ + [ -z "$$status" ] || ( \ + echo "Working tree is dirty after `make generate`:"; \ + echo "$$status"; \ + echo "Please ensure that the generated code is up-to-date." ) diff --git a/vendor/go.uber.org/atomic/README.md b/vendor/go.uber.org/atomic/README.md new file mode 100644 index 00000000..96b47a1f --- /dev/null +++ b/vendor/go.uber.org/atomic/README.md @@ -0,0 +1,63 @@ +# atomic [![GoDoc][doc-img]][doc] [![Build Status][ci-img]][ci] [![Coverage Status][cov-img]][cov] [![Go Report Card][reportcard-img]][reportcard] + +Simple wrappers for primitive types to enforce atomic access. + +## Installation + +```shell +$ go get -u go.uber.org/atomic@v1 +``` + +### Legacy Import Path + +As of v1.5.0, the import path `go.uber.org/atomic` is the only supported way +of using this package. If you are using Go modules, this package will fail to +compile with the legacy import path path `github.com/uber-go/atomic`. + +We recommend migrating your code to the new import path but if you're unable +to do so, or if your dependencies are still using the old import path, you +will have to add a `replace` directive to your `go.mod` file downgrading the +legacy import path to an older version. + +``` +replace github.com/uber-go/atomic => github.com/uber-go/atomic v1.4.0 +``` + +You can do so automatically by running the following command. + +```shell +$ go mod edit -replace github.com/uber-go/atomic=github.com/uber-go/atomic@v1.4.0 +``` + +## Usage + +The standard library's `sync/atomic` is powerful, but it's easy to forget which +variables must be accessed atomically. `go.uber.org/atomic` preserves all the +functionality of the standard library, but wraps the primitive types to +provide a safer, more convenient API. + +```go +var atom atomic.Uint32 +atom.Store(42) +atom.Sub(2) +atom.CAS(40, 11) +``` + +See the [documentation][doc] for a complete API specification. + +## Development Status + +Stable. + +--- + +Released under the [MIT License](LICENSE.txt). + +[doc-img]: https://godoc.org/github.com/uber-go/atomic?status.svg +[doc]: https://godoc.org/go.uber.org/atomic +[ci-img]: https://github.com/uber-go/atomic/actions/workflows/go.yml/badge.svg +[ci]: https://github.com/uber-go/atomic/actions/workflows/go.yml +[cov-img]: https://codecov.io/gh/uber-go/atomic/branch/master/graph/badge.svg +[cov]: https://codecov.io/gh/uber-go/atomic +[reportcard-img]: https://goreportcard.com/badge/go.uber.org/atomic +[reportcard]: https://goreportcard.com/report/go.uber.org/atomic diff --git a/vendor/go.uber.org/atomic/bool.go b/vendor/go.uber.org/atomic/bool.go new file mode 100644 index 00000000..f0a2ddd1 --- /dev/null +++ b/vendor/go.uber.org/atomic/bool.go @@ -0,0 +1,88 @@ +// @generated Code generated by gen-atomicwrapper. + +// Copyright (c) 2020-2023 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +import ( + "encoding/json" +) + +// Bool is an atomic type-safe wrapper for bool values. +type Bool struct { + _ nocmp // disallow non-atomic comparison + + v Uint32 +} + +var _zeroBool bool + +// NewBool creates a new Bool. +func NewBool(val bool) *Bool { + x := &Bool{} + if val != _zeroBool { + x.Store(val) + } + return x +} + +// Load atomically loads the wrapped bool. +func (x *Bool) Load() bool { + return truthy(x.v.Load()) +} + +// Store atomically stores the passed bool. +func (x *Bool) Store(val bool) { + x.v.Store(boolToInt(val)) +} + +// CAS is an atomic compare-and-swap for bool values. +// +// Deprecated: Use CompareAndSwap. +func (x *Bool) CAS(old, new bool) (swapped bool) { + return x.CompareAndSwap(old, new) +} + +// CompareAndSwap is an atomic compare-and-swap for bool values. +func (x *Bool) CompareAndSwap(old, new bool) (swapped bool) { + return x.v.CompareAndSwap(boolToInt(old), boolToInt(new)) +} + +// Swap atomically stores the given bool and returns the old +// value. +func (x *Bool) Swap(val bool) (old bool) { + return truthy(x.v.Swap(boolToInt(val))) +} + +// MarshalJSON encodes the wrapped bool into JSON. +func (x *Bool) MarshalJSON() ([]byte, error) { + return json.Marshal(x.Load()) +} + +// UnmarshalJSON decodes a bool from JSON. +func (x *Bool) UnmarshalJSON(b []byte) error { + var v bool + if err := json.Unmarshal(b, &v); err != nil { + return err + } + x.Store(v) + return nil +} diff --git a/vendor/go.uber.org/atomic/bool_ext.go b/vendor/go.uber.org/atomic/bool_ext.go new file mode 100644 index 00000000..a2e60e98 --- /dev/null +++ b/vendor/go.uber.org/atomic/bool_ext.go @@ -0,0 +1,53 @@ +// Copyright (c) 2020 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +import ( + "strconv" +) + +//go:generate bin/gen-atomicwrapper -name=Bool -type=bool -wrapped=Uint32 -pack=boolToInt -unpack=truthy -cas -swap -json -file=bool.go + +func truthy(n uint32) bool { + return n == 1 +} + +func boolToInt(b bool) uint32 { + if b { + return 1 + } + return 0 +} + +// Toggle atomically negates the Boolean and returns the previous value. +func (b *Bool) Toggle() (old bool) { + for { + old := b.Load() + if b.CAS(old, !old) { + return old + } + } +} + +// String encodes the wrapped value as a string. +func (b *Bool) String() string { + return strconv.FormatBool(b.Load()) +} diff --git a/vendor/go.uber.org/atomic/doc.go b/vendor/go.uber.org/atomic/doc.go new file mode 100644 index 00000000..ae7390ee --- /dev/null +++ b/vendor/go.uber.org/atomic/doc.go @@ -0,0 +1,23 @@ +// Copyright (c) 2020 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// Package atomic provides simple wrappers around numerics to enforce atomic +// access. +package atomic diff --git a/vendor/go.uber.org/atomic/duration.go b/vendor/go.uber.org/atomic/duration.go new file mode 100644 index 00000000..7c23868f --- /dev/null +++ b/vendor/go.uber.org/atomic/duration.go @@ -0,0 +1,89 @@ +// @generated Code generated by gen-atomicwrapper. + +// Copyright (c) 2020-2023 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +import ( + "encoding/json" + "time" +) + +// Duration is an atomic type-safe wrapper for time.Duration values. +type Duration struct { + _ nocmp // disallow non-atomic comparison + + v Int64 +} + +var _zeroDuration time.Duration + +// NewDuration creates a new Duration. +func NewDuration(val time.Duration) *Duration { + x := &Duration{} + if val != _zeroDuration { + x.Store(val) + } + return x +} + +// Load atomically loads the wrapped time.Duration. +func (x *Duration) Load() time.Duration { + return time.Duration(x.v.Load()) +} + +// Store atomically stores the passed time.Duration. +func (x *Duration) Store(val time.Duration) { + x.v.Store(int64(val)) +} + +// CAS is an atomic compare-and-swap for time.Duration values. +// +// Deprecated: Use CompareAndSwap. +func (x *Duration) CAS(old, new time.Duration) (swapped bool) { + return x.CompareAndSwap(old, new) +} + +// CompareAndSwap is an atomic compare-and-swap for time.Duration values. +func (x *Duration) CompareAndSwap(old, new time.Duration) (swapped bool) { + return x.v.CompareAndSwap(int64(old), int64(new)) +} + +// Swap atomically stores the given time.Duration and returns the old +// value. +func (x *Duration) Swap(val time.Duration) (old time.Duration) { + return time.Duration(x.v.Swap(int64(val))) +} + +// MarshalJSON encodes the wrapped time.Duration into JSON. +func (x *Duration) MarshalJSON() ([]byte, error) { + return json.Marshal(x.Load()) +} + +// UnmarshalJSON decodes a time.Duration from JSON. +func (x *Duration) UnmarshalJSON(b []byte) error { + var v time.Duration + if err := json.Unmarshal(b, &v); err != nil { + return err + } + x.Store(v) + return nil +} diff --git a/vendor/go.uber.org/atomic/duration_ext.go b/vendor/go.uber.org/atomic/duration_ext.go new file mode 100644 index 00000000..4c18b0a9 --- /dev/null +++ b/vendor/go.uber.org/atomic/duration_ext.go @@ -0,0 +1,40 @@ +// Copyright (c) 2020 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +import "time" + +//go:generate bin/gen-atomicwrapper -name=Duration -type=time.Duration -wrapped=Int64 -pack=int64 -unpack=time.Duration -cas -swap -json -imports time -file=duration.go + +// Add atomically adds to the wrapped time.Duration and returns the new value. +func (d *Duration) Add(delta time.Duration) time.Duration { + return time.Duration(d.v.Add(int64(delta))) +} + +// Sub atomically subtracts from the wrapped time.Duration and returns the new value. +func (d *Duration) Sub(delta time.Duration) time.Duration { + return time.Duration(d.v.Sub(int64(delta))) +} + +// String encodes the wrapped value as a string. +func (d *Duration) String() string { + return d.Load().String() +} diff --git a/vendor/go.uber.org/atomic/error.go b/vendor/go.uber.org/atomic/error.go new file mode 100644 index 00000000..b7e3f129 --- /dev/null +++ b/vendor/go.uber.org/atomic/error.go @@ -0,0 +1,72 @@ +// @generated Code generated by gen-atomicwrapper. + +// Copyright (c) 2020-2023 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +// Error is an atomic type-safe wrapper for error values. +type Error struct { + _ nocmp // disallow non-atomic comparison + + v Value +} + +var _zeroError error + +// NewError creates a new Error. +func NewError(val error) *Error { + x := &Error{} + if val != _zeroError { + x.Store(val) + } + return x +} + +// Load atomically loads the wrapped error. +func (x *Error) Load() error { + return unpackError(x.v.Load()) +} + +// Store atomically stores the passed error. +func (x *Error) Store(val error) { + x.v.Store(packError(val)) +} + +// CompareAndSwap is an atomic compare-and-swap for error values. +func (x *Error) CompareAndSwap(old, new error) (swapped bool) { + if x.v.CompareAndSwap(packError(old), packError(new)) { + return true + } + + if old == _zeroError { + // If the old value is the empty value, then it's possible the + // underlying Value hasn't been set and is nil, so retry with nil. + return x.v.CompareAndSwap(nil, packError(new)) + } + + return false +} + +// Swap atomically stores the given error and returns the old +// value. +func (x *Error) Swap(val error) (old error) { + return unpackError(x.v.Swap(packError(val))) +} diff --git a/vendor/go.uber.org/atomic/error_ext.go b/vendor/go.uber.org/atomic/error_ext.go new file mode 100644 index 00000000..d31fb633 --- /dev/null +++ b/vendor/go.uber.org/atomic/error_ext.go @@ -0,0 +1,39 @@ +// Copyright (c) 2020-2022 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +// atomic.Value panics on nil inputs, or if the underlying type changes. +// Stabilize by always storing a custom struct that we control. + +//go:generate bin/gen-atomicwrapper -name=Error -type=error -wrapped=Value -pack=packError -unpack=unpackError -compareandswap -swap -file=error.go + +type packedError struct{ Value error } + +func packError(v error) interface{} { + return packedError{v} +} + +func unpackError(v interface{}) error { + if err, ok := v.(packedError); ok { + return err.Value + } + return nil +} diff --git a/vendor/go.uber.org/atomic/float32.go b/vendor/go.uber.org/atomic/float32.go new file mode 100644 index 00000000..62c36334 --- /dev/null +++ b/vendor/go.uber.org/atomic/float32.go @@ -0,0 +1,77 @@ +// @generated Code generated by gen-atomicwrapper. + +// Copyright (c) 2020-2023 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +import ( + "encoding/json" + "math" +) + +// Float32 is an atomic type-safe wrapper for float32 values. +type Float32 struct { + _ nocmp // disallow non-atomic comparison + + v Uint32 +} + +var _zeroFloat32 float32 + +// NewFloat32 creates a new Float32. +func NewFloat32(val float32) *Float32 { + x := &Float32{} + if val != _zeroFloat32 { + x.Store(val) + } + return x +} + +// Load atomically loads the wrapped float32. +func (x *Float32) Load() float32 { + return math.Float32frombits(x.v.Load()) +} + +// Store atomically stores the passed float32. +func (x *Float32) Store(val float32) { + x.v.Store(math.Float32bits(val)) +} + +// Swap atomically stores the given float32 and returns the old +// value. +func (x *Float32) Swap(val float32) (old float32) { + return math.Float32frombits(x.v.Swap(math.Float32bits(val))) +} + +// MarshalJSON encodes the wrapped float32 into JSON. +func (x *Float32) MarshalJSON() ([]byte, error) { + return json.Marshal(x.Load()) +} + +// UnmarshalJSON decodes a float32 from JSON. +func (x *Float32) UnmarshalJSON(b []byte) error { + var v float32 + if err := json.Unmarshal(b, &v); err != nil { + return err + } + x.Store(v) + return nil +} diff --git a/vendor/go.uber.org/atomic/float32_ext.go b/vendor/go.uber.org/atomic/float32_ext.go new file mode 100644 index 00000000..b0cd8d9c --- /dev/null +++ b/vendor/go.uber.org/atomic/float32_ext.go @@ -0,0 +1,76 @@ +// Copyright (c) 2020-2022 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +import ( + "math" + "strconv" +) + +//go:generate bin/gen-atomicwrapper -name=Float32 -type=float32 -wrapped=Uint32 -pack=math.Float32bits -unpack=math.Float32frombits -swap -json -imports math -file=float32.go + +// Add atomically adds to the wrapped float32 and returns the new value. +func (f *Float32) Add(delta float32) float32 { + for { + old := f.Load() + new := old + delta + if f.CAS(old, new) { + return new + } + } +} + +// Sub atomically subtracts from the wrapped float32 and returns the new value. +func (f *Float32) Sub(delta float32) float32 { + return f.Add(-delta) +} + +// CAS is an atomic compare-and-swap for float32 values. +// +// Deprecated: Use CompareAndSwap +func (f *Float32) CAS(old, new float32) (swapped bool) { + return f.CompareAndSwap(old, new) +} + +// CompareAndSwap is an atomic compare-and-swap for float32 values. +// +// Note: CompareAndSwap handles NaN incorrectly. NaN != NaN using Go's inbuilt operators +// but CompareAndSwap allows a stored NaN to compare equal to a passed in NaN. +// This avoids typical CompareAndSwap loops from blocking forever, e.g., +// +// for { +// old := atom.Load() +// new = f(old) +// if atom.CompareAndSwap(old, new) { +// break +// } +// } +// +// If CompareAndSwap did not match NaN to match, then the above would loop forever. +func (f *Float32) CompareAndSwap(old, new float32) (swapped bool) { + return f.v.CompareAndSwap(math.Float32bits(old), math.Float32bits(new)) +} + +// String encodes the wrapped value as a string. +func (f *Float32) String() string { + // 'g' is the behavior for floats with %v. + return strconv.FormatFloat(float64(f.Load()), 'g', -1, 32) +} diff --git a/vendor/go.uber.org/atomic/float64.go b/vendor/go.uber.org/atomic/float64.go new file mode 100644 index 00000000..5bc11caa --- /dev/null +++ b/vendor/go.uber.org/atomic/float64.go @@ -0,0 +1,77 @@ +// @generated Code generated by gen-atomicwrapper. + +// Copyright (c) 2020-2023 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +import ( + "encoding/json" + "math" +) + +// Float64 is an atomic type-safe wrapper for float64 values. +type Float64 struct { + _ nocmp // disallow non-atomic comparison + + v Uint64 +} + +var _zeroFloat64 float64 + +// NewFloat64 creates a new Float64. +func NewFloat64(val float64) *Float64 { + x := &Float64{} + if val != _zeroFloat64 { + x.Store(val) + } + return x +} + +// Load atomically loads the wrapped float64. +func (x *Float64) Load() float64 { + return math.Float64frombits(x.v.Load()) +} + +// Store atomically stores the passed float64. +func (x *Float64) Store(val float64) { + x.v.Store(math.Float64bits(val)) +} + +// Swap atomically stores the given float64 and returns the old +// value. +func (x *Float64) Swap(val float64) (old float64) { + return math.Float64frombits(x.v.Swap(math.Float64bits(val))) +} + +// MarshalJSON encodes the wrapped float64 into JSON. +func (x *Float64) MarshalJSON() ([]byte, error) { + return json.Marshal(x.Load()) +} + +// UnmarshalJSON decodes a float64 from JSON. +func (x *Float64) UnmarshalJSON(b []byte) error { + var v float64 + if err := json.Unmarshal(b, &v); err != nil { + return err + } + x.Store(v) + return nil +} diff --git a/vendor/go.uber.org/atomic/float64_ext.go b/vendor/go.uber.org/atomic/float64_ext.go new file mode 100644 index 00000000..48c52b0a --- /dev/null +++ b/vendor/go.uber.org/atomic/float64_ext.go @@ -0,0 +1,76 @@ +// Copyright (c) 2020-2022 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +import ( + "math" + "strconv" +) + +//go:generate bin/gen-atomicwrapper -name=Float64 -type=float64 -wrapped=Uint64 -pack=math.Float64bits -unpack=math.Float64frombits -swap -json -imports math -file=float64.go + +// Add atomically adds to the wrapped float64 and returns the new value. +func (f *Float64) Add(delta float64) float64 { + for { + old := f.Load() + new := old + delta + if f.CAS(old, new) { + return new + } + } +} + +// Sub atomically subtracts from the wrapped float64 and returns the new value. +func (f *Float64) Sub(delta float64) float64 { + return f.Add(-delta) +} + +// CAS is an atomic compare-and-swap for float64 values. +// +// Deprecated: Use CompareAndSwap +func (f *Float64) CAS(old, new float64) (swapped bool) { + return f.CompareAndSwap(old, new) +} + +// CompareAndSwap is an atomic compare-and-swap for float64 values. +// +// Note: CompareAndSwap handles NaN incorrectly. NaN != NaN using Go's inbuilt operators +// but CompareAndSwap allows a stored NaN to compare equal to a passed in NaN. +// This avoids typical CompareAndSwap loops from blocking forever, e.g., +// +// for { +// old := atom.Load() +// new = f(old) +// if atom.CompareAndSwap(old, new) { +// break +// } +// } +// +// If CompareAndSwap did not match NaN to match, then the above would loop forever. +func (f *Float64) CompareAndSwap(old, new float64) (swapped bool) { + return f.v.CompareAndSwap(math.Float64bits(old), math.Float64bits(new)) +} + +// String encodes the wrapped value as a string. +func (f *Float64) String() string { + // 'g' is the behavior for floats with %v. + return strconv.FormatFloat(f.Load(), 'g', -1, 64) +} diff --git a/vendor/go.uber.org/atomic/gen.go b/vendor/go.uber.org/atomic/gen.go new file mode 100644 index 00000000..1e9ef4f8 --- /dev/null +++ b/vendor/go.uber.org/atomic/gen.go @@ -0,0 +1,27 @@ +// Copyright (c) 2020 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +//go:generate bin/gen-atomicint -name=Int32 -wrapped=int32 -file=int32.go +//go:generate bin/gen-atomicint -name=Int64 -wrapped=int64 -file=int64.go +//go:generate bin/gen-atomicint -name=Uint32 -wrapped=uint32 -unsigned -file=uint32.go +//go:generate bin/gen-atomicint -name=Uint64 -wrapped=uint64 -unsigned -file=uint64.go +//go:generate bin/gen-atomicint -name=Uintptr -wrapped=uintptr -unsigned -file=uintptr.go diff --git a/vendor/go.uber.org/atomic/int32.go b/vendor/go.uber.org/atomic/int32.go new file mode 100644 index 00000000..5320eac1 --- /dev/null +++ b/vendor/go.uber.org/atomic/int32.go @@ -0,0 +1,109 @@ +// @generated Code generated by gen-atomicint. + +// Copyright (c) 2020-2023 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +import ( + "encoding/json" + "strconv" + "sync/atomic" +) + +// Int32 is an atomic wrapper around int32. +type Int32 struct { + _ nocmp // disallow non-atomic comparison + + v int32 +} + +// NewInt32 creates a new Int32. +func NewInt32(val int32) *Int32 { + return &Int32{v: val} +} + +// Load atomically loads the wrapped value. +func (i *Int32) Load() int32 { + return atomic.LoadInt32(&i.v) +} + +// Add atomically adds to the wrapped int32 and returns the new value. +func (i *Int32) Add(delta int32) int32 { + return atomic.AddInt32(&i.v, delta) +} + +// Sub atomically subtracts from the wrapped int32 and returns the new value. +func (i *Int32) Sub(delta int32) int32 { + return atomic.AddInt32(&i.v, -delta) +} + +// Inc atomically increments the wrapped int32 and returns the new value. +func (i *Int32) Inc() int32 { + return i.Add(1) +} + +// Dec atomically decrements the wrapped int32 and returns the new value. +func (i *Int32) Dec() int32 { + return i.Sub(1) +} + +// CAS is an atomic compare-and-swap. +// +// Deprecated: Use CompareAndSwap. +func (i *Int32) CAS(old, new int32) (swapped bool) { + return i.CompareAndSwap(old, new) +} + +// CompareAndSwap is an atomic compare-and-swap. +func (i *Int32) CompareAndSwap(old, new int32) (swapped bool) { + return atomic.CompareAndSwapInt32(&i.v, old, new) +} + +// Store atomically stores the passed value. +func (i *Int32) Store(val int32) { + atomic.StoreInt32(&i.v, val) +} + +// Swap atomically swaps the wrapped int32 and returns the old value. +func (i *Int32) Swap(val int32) (old int32) { + return atomic.SwapInt32(&i.v, val) +} + +// MarshalJSON encodes the wrapped int32 into JSON. +func (i *Int32) MarshalJSON() ([]byte, error) { + return json.Marshal(i.Load()) +} + +// UnmarshalJSON decodes JSON into the wrapped int32. +func (i *Int32) UnmarshalJSON(b []byte) error { + var v int32 + if err := json.Unmarshal(b, &v); err != nil { + return err + } + i.Store(v) + return nil +} + +// String encodes the wrapped value as a string. +func (i *Int32) String() string { + v := i.Load() + return strconv.FormatInt(int64(v), 10) +} diff --git a/vendor/go.uber.org/atomic/int64.go b/vendor/go.uber.org/atomic/int64.go new file mode 100644 index 00000000..460821d0 --- /dev/null +++ b/vendor/go.uber.org/atomic/int64.go @@ -0,0 +1,109 @@ +// @generated Code generated by gen-atomicint. + +// Copyright (c) 2020-2023 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +import ( + "encoding/json" + "strconv" + "sync/atomic" +) + +// Int64 is an atomic wrapper around int64. +type Int64 struct { + _ nocmp // disallow non-atomic comparison + + v int64 +} + +// NewInt64 creates a new Int64. +func NewInt64(val int64) *Int64 { + return &Int64{v: val} +} + +// Load atomically loads the wrapped value. +func (i *Int64) Load() int64 { + return atomic.LoadInt64(&i.v) +} + +// Add atomically adds to the wrapped int64 and returns the new value. +func (i *Int64) Add(delta int64) int64 { + return atomic.AddInt64(&i.v, delta) +} + +// Sub atomically subtracts from the wrapped int64 and returns the new value. +func (i *Int64) Sub(delta int64) int64 { + return atomic.AddInt64(&i.v, -delta) +} + +// Inc atomically increments the wrapped int64 and returns the new value. +func (i *Int64) Inc() int64 { + return i.Add(1) +} + +// Dec atomically decrements the wrapped int64 and returns the new value. +func (i *Int64) Dec() int64 { + return i.Sub(1) +} + +// CAS is an atomic compare-and-swap. +// +// Deprecated: Use CompareAndSwap. +func (i *Int64) CAS(old, new int64) (swapped bool) { + return i.CompareAndSwap(old, new) +} + +// CompareAndSwap is an atomic compare-and-swap. +func (i *Int64) CompareAndSwap(old, new int64) (swapped bool) { + return atomic.CompareAndSwapInt64(&i.v, old, new) +} + +// Store atomically stores the passed value. +func (i *Int64) Store(val int64) { + atomic.StoreInt64(&i.v, val) +} + +// Swap atomically swaps the wrapped int64 and returns the old value. +func (i *Int64) Swap(val int64) (old int64) { + return atomic.SwapInt64(&i.v, val) +} + +// MarshalJSON encodes the wrapped int64 into JSON. +func (i *Int64) MarshalJSON() ([]byte, error) { + return json.Marshal(i.Load()) +} + +// UnmarshalJSON decodes JSON into the wrapped int64. +func (i *Int64) UnmarshalJSON(b []byte) error { + var v int64 + if err := json.Unmarshal(b, &v); err != nil { + return err + } + i.Store(v) + return nil +} + +// String encodes the wrapped value as a string. +func (i *Int64) String() string { + v := i.Load() + return strconv.FormatInt(int64(v), 10) +} diff --git a/vendor/go.uber.org/atomic/nocmp.go b/vendor/go.uber.org/atomic/nocmp.go new file mode 100644 index 00000000..54b74174 --- /dev/null +++ b/vendor/go.uber.org/atomic/nocmp.go @@ -0,0 +1,35 @@ +// Copyright (c) 2020 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +// nocmp is an uncomparable struct. Embed this inside another struct to make +// it uncomparable. +// +// type Foo struct { +// nocmp +// // ... +// } +// +// This DOES NOT: +// +// - Disallow shallow copies of structs +// - Disallow comparison of pointers to uncomparable structs +type nocmp [0]func() diff --git a/vendor/go.uber.org/atomic/pointer_go118.go b/vendor/go.uber.org/atomic/pointer_go118.go new file mode 100644 index 00000000..1fb6c03b --- /dev/null +++ b/vendor/go.uber.org/atomic/pointer_go118.go @@ -0,0 +1,31 @@ +// Copyright (c) 2022 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +//go:build go1.18 +// +build go1.18 + +package atomic + +import "fmt" + +// String returns a human readable representation of a Pointer's underlying value. +func (p *Pointer[T]) String() string { + return fmt.Sprint(p.Load()) +} diff --git a/vendor/go.uber.org/atomic/pointer_go118_pre119.go b/vendor/go.uber.org/atomic/pointer_go118_pre119.go new file mode 100644 index 00000000..e0f47dba --- /dev/null +++ b/vendor/go.uber.org/atomic/pointer_go118_pre119.go @@ -0,0 +1,60 @@ +// Copyright (c) 2022 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +//go:build go1.18 && !go1.19 +// +build go1.18,!go1.19 + +package atomic + +import "unsafe" + +type Pointer[T any] struct { + _ nocmp // disallow non-atomic comparison + p UnsafePointer +} + +// NewPointer creates a new Pointer. +func NewPointer[T any](v *T) *Pointer[T] { + var p Pointer[T] + if v != nil { + p.p.Store(unsafe.Pointer(v)) + } + return &p +} + +// Load atomically loads the wrapped value. +func (p *Pointer[T]) Load() *T { + return (*T)(p.p.Load()) +} + +// Store atomically stores the passed value. +func (p *Pointer[T]) Store(val *T) { + p.p.Store(unsafe.Pointer(val)) +} + +// Swap atomically swaps the wrapped pointer and returns the old value. +func (p *Pointer[T]) Swap(val *T) (old *T) { + return (*T)(p.p.Swap(unsafe.Pointer(val))) +} + +// CompareAndSwap is an atomic compare-and-swap. +func (p *Pointer[T]) CompareAndSwap(old, new *T) (swapped bool) { + return p.p.CompareAndSwap(unsafe.Pointer(old), unsafe.Pointer(new)) +} diff --git a/vendor/go.uber.org/atomic/pointer_go119.go b/vendor/go.uber.org/atomic/pointer_go119.go new file mode 100644 index 00000000..6726f17a --- /dev/null +++ b/vendor/go.uber.org/atomic/pointer_go119.go @@ -0,0 +1,61 @@ +// Copyright (c) 2022 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +//go:build go1.19 +// +build go1.19 + +package atomic + +import "sync/atomic" + +// Pointer is an atomic pointer of type *T. +type Pointer[T any] struct { + _ nocmp // disallow non-atomic comparison + p atomic.Pointer[T] +} + +// NewPointer creates a new Pointer. +func NewPointer[T any](v *T) *Pointer[T] { + var p Pointer[T] + if v != nil { + p.p.Store(v) + } + return &p +} + +// Load atomically loads the wrapped value. +func (p *Pointer[T]) Load() *T { + return p.p.Load() +} + +// Store atomically stores the passed value. +func (p *Pointer[T]) Store(val *T) { + p.p.Store(val) +} + +// Swap atomically swaps the wrapped pointer and returns the old value. +func (p *Pointer[T]) Swap(val *T) (old *T) { + return p.p.Swap(val) +} + +// CompareAndSwap is an atomic compare-and-swap. +func (p *Pointer[T]) CompareAndSwap(old, new *T) (swapped bool) { + return p.p.CompareAndSwap(old, new) +} diff --git a/vendor/go.uber.org/atomic/string.go b/vendor/go.uber.org/atomic/string.go new file mode 100644 index 00000000..061466c5 --- /dev/null +++ b/vendor/go.uber.org/atomic/string.go @@ -0,0 +1,72 @@ +// @generated Code generated by gen-atomicwrapper. + +// Copyright (c) 2020-2023 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +// String is an atomic type-safe wrapper for string values. +type String struct { + _ nocmp // disallow non-atomic comparison + + v Value +} + +var _zeroString string + +// NewString creates a new String. +func NewString(val string) *String { + x := &String{} + if val != _zeroString { + x.Store(val) + } + return x +} + +// Load atomically loads the wrapped string. +func (x *String) Load() string { + return unpackString(x.v.Load()) +} + +// Store atomically stores the passed string. +func (x *String) Store(val string) { + x.v.Store(packString(val)) +} + +// CompareAndSwap is an atomic compare-and-swap for string values. +func (x *String) CompareAndSwap(old, new string) (swapped bool) { + if x.v.CompareAndSwap(packString(old), packString(new)) { + return true + } + + if old == _zeroString { + // If the old value is the empty value, then it's possible the + // underlying Value hasn't been set and is nil, so retry with nil. + return x.v.CompareAndSwap(nil, packString(new)) + } + + return false +} + +// Swap atomically stores the given string and returns the old +// value. +func (x *String) Swap(val string) (old string) { + return unpackString(x.v.Swap(packString(val))) +} diff --git a/vendor/go.uber.org/atomic/string_ext.go b/vendor/go.uber.org/atomic/string_ext.go new file mode 100644 index 00000000..019109c8 --- /dev/null +++ b/vendor/go.uber.org/atomic/string_ext.go @@ -0,0 +1,54 @@ +// Copyright (c) 2020-2023 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +//go:generate bin/gen-atomicwrapper -name=String -type=string -wrapped Value -pack packString -unpack unpackString -compareandswap -swap -file=string.go + +func packString(s string) interface{} { + return s +} + +func unpackString(v interface{}) string { + if s, ok := v.(string); ok { + return s + } + return "" +} + +// String returns the wrapped value. +func (s *String) String() string { + return s.Load() +} + +// MarshalText encodes the wrapped string into a textual form. +// +// This makes it encodable as JSON, YAML, XML, and more. +func (s *String) MarshalText() ([]byte, error) { + return []byte(s.Load()), nil +} + +// UnmarshalText decodes text and replaces the wrapped string with it. +// +// This makes it decodable from JSON, YAML, XML, and more. +func (s *String) UnmarshalText(b []byte) error { + s.Store(string(b)) + return nil +} diff --git a/vendor/go.uber.org/atomic/time.go b/vendor/go.uber.org/atomic/time.go new file mode 100644 index 00000000..cc2a230c --- /dev/null +++ b/vendor/go.uber.org/atomic/time.go @@ -0,0 +1,55 @@ +// @generated Code generated by gen-atomicwrapper. + +// Copyright (c) 2020-2023 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +import ( + "time" +) + +// Time is an atomic type-safe wrapper for time.Time values. +type Time struct { + _ nocmp // disallow non-atomic comparison + + v Value +} + +var _zeroTime time.Time + +// NewTime creates a new Time. +func NewTime(val time.Time) *Time { + x := &Time{} + if val != _zeroTime { + x.Store(val) + } + return x +} + +// Load atomically loads the wrapped time.Time. +func (x *Time) Load() time.Time { + return unpackTime(x.v.Load()) +} + +// Store atomically stores the passed time.Time. +func (x *Time) Store(val time.Time) { + x.v.Store(packTime(val)) +} diff --git a/vendor/go.uber.org/atomic/time_ext.go b/vendor/go.uber.org/atomic/time_ext.go new file mode 100644 index 00000000..1e3dc978 --- /dev/null +++ b/vendor/go.uber.org/atomic/time_ext.go @@ -0,0 +1,36 @@ +// Copyright (c) 2021 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +import "time" + +//go:generate bin/gen-atomicwrapper -name=Time -type=time.Time -wrapped=Value -pack=packTime -unpack=unpackTime -imports time -file=time.go + +func packTime(t time.Time) interface{} { + return t +} + +func unpackTime(v interface{}) time.Time { + if t, ok := v.(time.Time); ok { + return t + } + return time.Time{} +} diff --git a/vendor/go.uber.org/atomic/uint32.go b/vendor/go.uber.org/atomic/uint32.go new file mode 100644 index 00000000..4adc294a --- /dev/null +++ b/vendor/go.uber.org/atomic/uint32.go @@ -0,0 +1,109 @@ +// @generated Code generated by gen-atomicint. + +// Copyright (c) 2020-2023 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +import ( + "encoding/json" + "strconv" + "sync/atomic" +) + +// Uint32 is an atomic wrapper around uint32. +type Uint32 struct { + _ nocmp // disallow non-atomic comparison + + v uint32 +} + +// NewUint32 creates a new Uint32. +func NewUint32(val uint32) *Uint32 { + return &Uint32{v: val} +} + +// Load atomically loads the wrapped value. +func (i *Uint32) Load() uint32 { + return atomic.LoadUint32(&i.v) +} + +// Add atomically adds to the wrapped uint32 and returns the new value. +func (i *Uint32) Add(delta uint32) uint32 { + return atomic.AddUint32(&i.v, delta) +} + +// Sub atomically subtracts from the wrapped uint32 and returns the new value. +func (i *Uint32) Sub(delta uint32) uint32 { + return atomic.AddUint32(&i.v, ^(delta - 1)) +} + +// Inc atomically increments the wrapped uint32 and returns the new value. +func (i *Uint32) Inc() uint32 { + return i.Add(1) +} + +// Dec atomically decrements the wrapped uint32 and returns the new value. +func (i *Uint32) Dec() uint32 { + return i.Sub(1) +} + +// CAS is an atomic compare-and-swap. +// +// Deprecated: Use CompareAndSwap. +func (i *Uint32) CAS(old, new uint32) (swapped bool) { + return i.CompareAndSwap(old, new) +} + +// CompareAndSwap is an atomic compare-and-swap. +func (i *Uint32) CompareAndSwap(old, new uint32) (swapped bool) { + return atomic.CompareAndSwapUint32(&i.v, old, new) +} + +// Store atomically stores the passed value. +func (i *Uint32) Store(val uint32) { + atomic.StoreUint32(&i.v, val) +} + +// Swap atomically swaps the wrapped uint32 and returns the old value. +func (i *Uint32) Swap(val uint32) (old uint32) { + return atomic.SwapUint32(&i.v, val) +} + +// MarshalJSON encodes the wrapped uint32 into JSON. +func (i *Uint32) MarshalJSON() ([]byte, error) { + return json.Marshal(i.Load()) +} + +// UnmarshalJSON decodes JSON into the wrapped uint32. +func (i *Uint32) UnmarshalJSON(b []byte) error { + var v uint32 + if err := json.Unmarshal(b, &v); err != nil { + return err + } + i.Store(v) + return nil +} + +// String encodes the wrapped value as a string. +func (i *Uint32) String() string { + v := i.Load() + return strconv.FormatUint(uint64(v), 10) +} diff --git a/vendor/go.uber.org/atomic/uint64.go b/vendor/go.uber.org/atomic/uint64.go new file mode 100644 index 00000000..0e2eddb3 --- /dev/null +++ b/vendor/go.uber.org/atomic/uint64.go @@ -0,0 +1,109 @@ +// @generated Code generated by gen-atomicint. + +// Copyright (c) 2020-2023 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +import ( + "encoding/json" + "strconv" + "sync/atomic" +) + +// Uint64 is an atomic wrapper around uint64. +type Uint64 struct { + _ nocmp // disallow non-atomic comparison + + v uint64 +} + +// NewUint64 creates a new Uint64. +func NewUint64(val uint64) *Uint64 { + return &Uint64{v: val} +} + +// Load atomically loads the wrapped value. +func (i *Uint64) Load() uint64 { + return atomic.LoadUint64(&i.v) +} + +// Add atomically adds to the wrapped uint64 and returns the new value. +func (i *Uint64) Add(delta uint64) uint64 { + return atomic.AddUint64(&i.v, delta) +} + +// Sub atomically subtracts from the wrapped uint64 and returns the new value. +func (i *Uint64) Sub(delta uint64) uint64 { + return atomic.AddUint64(&i.v, ^(delta - 1)) +} + +// Inc atomically increments the wrapped uint64 and returns the new value. +func (i *Uint64) Inc() uint64 { + return i.Add(1) +} + +// Dec atomically decrements the wrapped uint64 and returns the new value. +func (i *Uint64) Dec() uint64 { + return i.Sub(1) +} + +// CAS is an atomic compare-and-swap. +// +// Deprecated: Use CompareAndSwap. +func (i *Uint64) CAS(old, new uint64) (swapped bool) { + return i.CompareAndSwap(old, new) +} + +// CompareAndSwap is an atomic compare-and-swap. +func (i *Uint64) CompareAndSwap(old, new uint64) (swapped bool) { + return atomic.CompareAndSwapUint64(&i.v, old, new) +} + +// Store atomically stores the passed value. +func (i *Uint64) Store(val uint64) { + atomic.StoreUint64(&i.v, val) +} + +// Swap atomically swaps the wrapped uint64 and returns the old value. +func (i *Uint64) Swap(val uint64) (old uint64) { + return atomic.SwapUint64(&i.v, val) +} + +// MarshalJSON encodes the wrapped uint64 into JSON. +func (i *Uint64) MarshalJSON() ([]byte, error) { + return json.Marshal(i.Load()) +} + +// UnmarshalJSON decodes JSON into the wrapped uint64. +func (i *Uint64) UnmarshalJSON(b []byte) error { + var v uint64 + if err := json.Unmarshal(b, &v); err != nil { + return err + } + i.Store(v) + return nil +} + +// String encodes the wrapped value as a string. +func (i *Uint64) String() string { + v := i.Load() + return strconv.FormatUint(uint64(v), 10) +} diff --git a/vendor/go.uber.org/atomic/uintptr.go b/vendor/go.uber.org/atomic/uintptr.go new file mode 100644 index 00000000..7d5b000d --- /dev/null +++ b/vendor/go.uber.org/atomic/uintptr.go @@ -0,0 +1,109 @@ +// @generated Code generated by gen-atomicint. + +// Copyright (c) 2020-2023 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +import ( + "encoding/json" + "strconv" + "sync/atomic" +) + +// Uintptr is an atomic wrapper around uintptr. +type Uintptr struct { + _ nocmp // disallow non-atomic comparison + + v uintptr +} + +// NewUintptr creates a new Uintptr. +func NewUintptr(val uintptr) *Uintptr { + return &Uintptr{v: val} +} + +// Load atomically loads the wrapped value. +func (i *Uintptr) Load() uintptr { + return atomic.LoadUintptr(&i.v) +} + +// Add atomically adds to the wrapped uintptr and returns the new value. +func (i *Uintptr) Add(delta uintptr) uintptr { + return atomic.AddUintptr(&i.v, delta) +} + +// Sub atomically subtracts from the wrapped uintptr and returns the new value. +func (i *Uintptr) Sub(delta uintptr) uintptr { + return atomic.AddUintptr(&i.v, ^(delta - 1)) +} + +// Inc atomically increments the wrapped uintptr and returns the new value. +func (i *Uintptr) Inc() uintptr { + return i.Add(1) +} + +// Dec atomically decrements the wrapped uintptr and returns the new value. +func (i *Uintptr) Dec() uintptr { + return i.Sub(1) +} + +// CAS is an atomic compare-and-swap. +// +// Deprecated: Use CompareAndSwap. +func (i *Uintptr) CAS(old, new uintptr) (swapped bool) { + return i.CompareAndSwap(old, new) +} + +// CompareAndSwap is an atomic compare-and-swap. +func (i *Uintptr) CompareAndSwap(old, new uintptr) (swapped bool) { + return atomic.CompareAndSwapUintptr(&i.v, old, new) +} + +// Store atomically stores the passed value. +func (i *Uintptr) Store(val uintptr) { + atomic.StoreUintptr(&i.v, val) +} + +// Swap atomically swaps the wrapped uintptr and returns the old value. +func (i *Uintptr) Swap(val uintptr) (old uintptr) { + return atomic.SwapUintptr(&i.v, val) +} + +// MarshalJSON encodes the wrapped uintptr into JSON. +func (i *Uintptr) MarshalJSON() ([]byte, error) { + return json.Marshal(i.Load()) +} + +// UnmarshalJSON decodes JSON into the wrapped uintptr. +func (i *Uintptr) UnmarshalJSON(b []byte) error { + var v uintptr + if err := json.Unmarshal(b, &v); err != nil { + return err + } + i.Store(v) + return nil +} + +// String encodes the wrapped value as a string. +func (i *Uintptr) String() string { + v := i.Load() + return strconv.FormatUint(uint64(v), 10) +} diff --git a/vendor/go.uber.org/atomic/unsafe_pointer.go b/vendor/go.uber.org/atomic/unsafe_pointer.go new file mode 100644 index 00000000..34868baf --- /dev/null +++ b/vendor/go.uber.org/atomic/unsafe_pointer.go @@ -0,0 +1,65 @@ +// Copyright (c) 2021-2022 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +import ( + "sync/atomic" + "unsafe" +) + +// UnsafePointer is an atomic wrapper around unsafe.Pointer. +type UnsafePointer struct { + _ nocmp // disallow non-atomic comparison + + v unsafe.Pointer +} + +// NewUnsafePointer creates a new UnsafePointer. +func NewUnsafePointer(val unsafe.Pointer) *UnsafePointer { + return &UnsafePointer{v: val} +} + +// Load atomically loads the wrapped value. +func (p *UnsafePointer) Load() unsafe.Pointer { + return atomic.LoadPointer(&p.v) +} + +// Store atomically stores the passed value. +func (p *UnsafePointer) Store(val unsafe.Pointer) { + atomic.StorePointer(&p.v, val) +} + +// Swap atomically swaps the wrapped unsafe.Pointer and returns the old value. +func (p *UnsafePointer) Swap(val unsafe.Pointer) (old unsafe.Pointer) { + return atomic.SwapPointer(&p.v, val) +} + +// CAS is an atomic compare-and-swap. +// +// Deprecated: Use CompareAndSwap +func (p *UnsafePointer) CAS(old, new unsafe.Pointer) (swapped bool) { + return p.CompareAndSwap(old, new) +} + +// CompareAndSwap is an atomic compare-and-swap. +func (p *UnsafePointer) CompareAndSwap(old, new unsafe.Pointer) (swapped bool) { + return atomic.CompareAndSwapPointer(&p.v, old, new) +} diff --git a/vendor/go.uber.org/atomic/value.go b/vendor/go.uber.org/atomic/value.go new file mode 100644 index 00000000..52caedb9 --- /dev/null +++ b/vendor/go.uber.org/atomic/value.go @@ -0,0 +1,31 @@ +// Copyright (c) 2020 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package atomic + +import "sync/atomic" + +// Value shadows the type of the same name from sync/atomic +// https://godoc.org/sync/atomic#Value +type Value struct { + _ nocmp // disallow non-atomic comparison + + atomic.Value +} diff --git a/vendor/modules.txt b/vendor/modules.txt index be338f5a..0c561b9a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -110,8 +110,8 @@ github.com/pelletier/go-toml/v2/unstable # github.com/pkg/errors v0.9.1 ## explicit github.com/pkg/errors -# github.com/redis/go-redis/v9 v9.17.3 -## explicit; go 1.18 +# github.com/redis/go-redis/v9 v9.18.0 +## explicit; go 1.21 github.com/redis/go-redis/v9 github.com/redis/go-redis/v9/auth github.com/redis/go-redis/v9/internal @@ -120,9 +120,11 @@ github.com/redis/go-redis/v9/internal/hashtag github.com/redis/go-redis/v9/internal/hscan github.com/redis/go-redis/v9/internal/interfaces github.com/redis/go-redis/v9/internal/maintnotifications/logs +github.com/redis/go-redis/v9/internal/otel github.com/redis/go-redis/v9/internal/pool github.com/redis/go-redis/v9/internal/proto github.com/redis/go-redis/v9/internal/rand +github.com/redis/go-redis/v9/internal/routing github.com/redis/go-redis/v9/internal/util github.com/redis/go-redis/v9/maintnotifications github.com/redis/go-redis/v9/push @@ -186,6 +188,7 @@ github.com/vmihailenco/tagparser/v2/internal github.com/vmihailenco/tagparser/v2/internal/parser # go.uber.org/atomic v1.11.0 ## explicit; go 1.18 +go.uber.org/atomic # go.uber.org/ratelimit v0.3.1 ## explicit; go 1.20 go.uber.org/ratelimit