1
0
mirror of https://github.com/redis/go-redis.git synced 2025-09-07 07:47:24 +03:00
Commit Graph

139 Commits

Author SHA1 Message Date
Nedyalko Dyakov
22da2b590e address comments 2025-08-19 16:38:15 +03:00
Nedyalko Dyakov
ded98eccb1 address comments 2025-08-19 15:56:48 +03:00
Nedyalko Dyakov
5649ffb314 feat(hitless): Introduce handlers for hitless upgrades
This commit includes all the work on hitless upgrades with the addition
of:

- Pubsub Pool
- Examples
- Refactor of push
- Refactor of pool (using atomics for most things)
- Introducing of hooks in pool
2025-08-18 22:14:06 +03:00
Nedyalko Dyakov
36f9f58c67 Merge branch 'master' into ndyakov/CAE-1088-resp3-notification-handlers 2025-08-18 22:11:06 +03:00
cxljs
e07f55bed1 chore(buffers): Set the default read/write buffer size of Redis connection to 32KiB (#3483)
* update README.md

Signed-off-by: Xiaolong Chen <fukua95@gmail.com>

* typo: 0.5MiB -> 256KiB

Signed-off-by: Xiaolong Chen <fukua95@gmail.com>

* Set the default read/write buffer size of Redis connection to 32KiB

Signed-off-by: Xiaolong Chen <fukua95@gmail.com>

---------

Signed-off-by: Xiaolong Chen <fukua95@gmail.com>
2025-08-18 20:04:55 +03:00
Nedyalko Dyakov
422779ba9f Merge remote-tracking branch 'origin/master' into ndyakov/CAE-1088-resp3-notification-handlers 2025-08-12 19:38:11 +03:00
ofekshenawa
436979f5c7 feat(options): Clean failing timeout implementation (#3472)
* Fix hard code of failing timeout

1. if not set failing time limit, default is 15 seconds.

* feat: Complete configurable FailingTimeoutSeconds implementation

---------

Co-authored-by: Shino Wu <shino_wu@trendmicro.com>
2025-08-12 14:08:28 +03:00
Nedyalko Dyakov
94cfffa417 fix(options): Add buffer sizes to failover. Update README (#3468)
* fix(options): Add buffer sizes to failover. Update README

* fix(spellcheck): add KiB in wordlist

* fix(comment): fix defaul value in comment

* fixes #3465
2025-08-11 16:01:24 +03:00
Nedyalko Dyakov
5767a31a80 Merge branch 'master' into ndyakov/CAE-1088-resp3-notification-handlers 2025-08-04 10:56:25 +03:00
ofekshenawa
1eed165f9d feat(proto): add configurable buffer sizes for Redis connections (#3453)
* add configurable buffer sizes for Redis connections

* add MiB to wordlist

* Add description for buffer size parameter
2025-08-04 09:16:54 +03:00
Nedyalko Dyakov
84123b1331 refactor(push): completly change the package structure 2025-07-05 02:52:40 +03:00
Nedyalko Dyakov
1606de8b73 feat: implement strongly typed HandlerContext interface
Convert HandlerContext from struct to interface with strongly typed getters
for different client types. This provides better type safety and a cleaner
API for push notification handlers while maintaining flexibility.

Key Changes:

1. HandlerContext Interface Design:
   - Converted HandlerContext from struct to interface
   - Added strongly typed getters for different client types
   - GetClusterClient() returns ClusterClientInterface
   - GetSentinelClient() returns SentinelClientInterface
   - GetFailoverClient() returns FailoverClientInterface
   - GetRegularClient() returns RegularClientInterface
   - GetPubSub() returns PubSubInterface

2. Client Type Interfaces:
   - Defined ClusterClientInterface for cluster client access
   - Defined SentinelClientInterface for sentinel client access
   - Defined FailoverClientInterface for failover client access
   - Defined RegularClientInterface for regular client access
   - Defined PubSubInterface for pub/sub access
   - Each interface provides String() method for basic operations

3. Concrete Implementation:
   - Created handlerContext struct implementing HandlerContext interface
   - Added NewHandlerContext constructor function
   - Implemented type-safe getters with interface casting
   - Returns nil for incorrect client types (type safety)

4. Updated All Usage:
   - Updated Handler interface to use HandlerContext interface
   - Updated ProcessorInterface to use HandlerContext interface
   - Updated all processor implementations (Processor, VoidProcessor)
   - Updated all handler context creation sites
   - Updated test handlers and test context creation

5. Helper Methods:
   - Updated pushNotificationHandlerContext() in baseClient
   - Updated pushNotificationHandlerContext() in PubSub
   - Consistent context creation across all client types
   - Proper parameter passing for different connection types

6. Type Safety Benefits:
   - Handlers can safely cast to specific client types
   - Compile-time checking for client type access
   - Clear API for accessing different client capabilities
   - No runtime panics from incorrect type assertions

7. API Usage Example:
   ```go
   func (h *MyHandler) HandlePushNotification(
       ctx context.Context,
       handlerCtx HandlerContext,
       notification []interface{},
   ) bool {
       // Strongly typed access
       if clusterClient := handlerCtx.GetClusterClient(); clusterClient != nil {
           // Handle cluster-specific logic
       }
       if sentinelClient := handlerCtx.GetSentinelClient(); sentinelClient != nil {
           // Handle sentinel-specific logic
       }
       return true
   }
   ```

8. Backward Compatibility:
   - Interface maintains same functionality as original struct
   - All existing handler patterns continue to work
   - No breaking changes to handler implementations
   - Smooth migration path for existing code

Benefits:
- Strong type safety for client access in handlers
- Clear API with explicit client type getters
- Compile-time checking prevents runtime errors
- Flexible interface allows future extensions
- Better separation of concerns between client types
- Enhanced developer experience with IntelliSense support

This enhancement provides handlers with strongly typed access to different
Redis client types while maintaining the flexibility and context information
needed for sophisticated push notification handling, particularly important
for hitless upgrades and cluster management operations.
2025-07-04 19:53:19 +03:00
Nedyalko Dyakov
47dd490a8a feat: enhance push notification handlers with context information 2025-07-04 18:16:15 +03:00
Nedyalko Dyakov
f7948b5c5c fix: address pr review 2025-06-27 18:26:15 +03:00
Nedyalko Dyakov
fdfcf94300 feat: add VoidPushNotificationProcessor for disabled push notifications
- Add VoidPushNotificationProcessor that reads and discards push notifications
- Create PushNotificationProcessorInterface for consistent behavior
- Always provide a processor (real or void) instead of nil
- VoidPushNotificationProcessor properly cleans RESP3 push notifications from buffer
- Remove all nil checks throughout codebase for cleaner, safer code
- Update tests to expect VoidPushNotificationProcessor when disabled

Benefits:
- Eliminates nil pointer risks throughout the codebase
- Follows null object pattern for safer operation
- Properly handles RESP3 push notifications even when disabled
- Consistent interface regardless of push notification settings
- Cleaner code without defensive nil checks everywhere
2025-06-27 01:36:35 +03:00
Nedyalko Dyakov
d7fbe18214 feat: fix connection health check interference with push notifications
- Add PushNotificationProcessor field to pool.Conn for connection-level processing
- Modify connection pool Put() and isHealthyConn() to handle push notifications
- Process pending push notifications before discarding connections
- Pass push notification processor to connections during creation
- Update connection pool options to include push notification processor
- Add comprehensive test for connection health check integration

This prevents connections with buffered push notification data from being
incorrectly discarded by the connection health check, ensuring push
notifications are properly processed and connections are reused.
2025-06-27 01:36:20 +03:00
Nedyalko Dyakov
e6e2cead66 feat: remove global handlers and enable push notifications by default
- Remove all global push notification handler functionality
- Simplify registry to support only single handler per notification type
- Enable push notifications by default for RESP3 connections
- Update comprehensive test suite to remove global handler tests
- Update demo to show multiple specific handlers instead of global handlers
- Always respect custom processors regardless of PushNotifications flag

Push notifications are now automatically enabled for RESP3 and each
notification type has a single dedicated handler for predictable behavior.
2025-06-27 01:36:17 +03:00
Nedyalko Dyakov
b02eed63b2 feat: add general push notification system
- Add PushNotificationRegistry for managing notification handlers
- Add PushNotificationProcessor for processing RESP3 push notifications
- Add client methods for registering push notification handlers
- Add PubSub integration for handling generic push notifications
- Add comprehensive test suite with 100% coverage
- Add push notification demo example

This system allows handling any arbitrary RESP3 push notification
with registered handlers, not just specific notification types.
2025-06-27 01:36:08 +03:00
Nedyalko Dyakov
86d418f940 feat: Introducing StreamingCredentialsProvider for token based authentication (#3320)
* wip

* update documentation

* add streamingcredentialsprovider in options

* fix: put back option in pool creation

* add package level comment

* Initial re authentication implementation

Introduces the StreamingCredentialsProvider as the CredentialsProvider
with the highest priority.

TODO: needs to be tested

* Change function type name

Change CancelProviderFunc to UnsubscribeFunc

* add tests

* fix race in tests

* fix example tests

* wip, hooks refactor

* fix build

* update README.md

* update wordlist

* update README.md

* refactor(auth): early returns in cred listener

* fix(doctest): simulate some delay

* feat(conn): add close hook on conn

* fix(tests): simulate start/stop in mock credentials provider

* fix(auth): don't double close the conn

* docs(README): mark streaming credentials provider as experimental

* fix(auth): streamline auth err proccess

* fix(auth): check err on close conn

* chore(entraid): use the repo under redis org
2025-05-27 16:25:20 +03:00
fukua95
28a3c97409 chore: set the default value for the options.protocol in the init() of options (#3387)
* chore: set the default value for the `options.protocol` in the `init()` of `options`

Signed-off-by: fukua95 <fukua95@gmail.com>

* add a test

Signed-off-by: fukua95 <fukua95@gmail.com>

---------

Signed-off-by: fukua95 <fukua95@gmail.com>
2025-05-27 14:53:41 +03:00
ofekshenawa
2f0a9b720a migrate golangci-lint config to v2 format (#3354)
* migrate golangci-lint config to v2 format

* chore: skip CI on migration [skip ci]

* Bump golangci version

* Address several golangci-lint/staticcheck warnings

* change staticchecks settings
2025-04-29 12:53:06 +03:00
LINKIWI
9762559c75 Bound connection pool background dials to configured dial timeout (#3089) 2025-03-24 15:45:43 +02:00
Nedyalko Dyakov
d236865b0c fix: handle network error on SETINFO (#3295) (CVE-2025-29923)
* fix: handle network error on SETINFO

This fix addresses potential out of order responses as described in `CVE-2025-29923`

* fix: deprecate DisableIndentity and introduce DisableIdentity

Both options will work before V10. In v10 DisableIndentity will be dropped. The preferred flag to use is `DisableIdentity`.
2025-03-19 19:02:36 +02:00
Nedyalko Dyakov
d0f921357d fix: add unstableresp3 to cluster client (#3266)
* fix: add unstableresp3 to cluster client

* propagate unstableresp3

* proper test that will ignore error, but fail if client panics

* add separate test for clusterclient constructor
2025-02-07 12:09:49 +02:00
Julien Riou
3d4310ae96 feat(options): add skip_verify param (#3216)
* feat(options): Add skip_verify param

When parsing a URL, add a "skip_verify" query param to disable TLS certificate
verification.

Inspired by various Go drivers:

* ClickHouse: https://github.com/ClickHouse/clickhouse-go/blob/v2.30.0/clickhouse_options.go#L259
* MongoDB: https://github.com/mongodb/mongo-go-driver/blob/v2.0.0/x/mongo/driver/connstring/connstring.go#L609
* MySQL: https://github.com/go-sql-driver/mysql/blob/v1.8.1/dsn.go#L175

Signed-off-by: Julien Riou <julien@riou.xyz>

* docs(options): Add skip_verify to ParseURL

Signed-off-by: Julien Riou <julien@riou.xyz>

---------

Signed-off-by: Julien Riou <julien@riou.xyz>
Co-authored-by: Nedyalko Dyakov <nedyalko.dyakov@gmail.com>
2025-02-04 11:34:08 +02:00
ofekshenawa
04005cbdc7 Support Resp 3 Redis Search Unstable Mode (#3098)
* Updated module version that points to retracted package version (#3074)

* Updated module version that points to retracted package version

* Updated testing image to latest

* support raw parsing for problematic Redis Search types

* Add UnstableResp3SearchModule to client options

* Add tests for Resp3 Search unstable mode

* Add tests for Resp3 Search unstable mode

* Add readme note

* Add words to spellcheck

* Add UnstableResp3SearchModule check to assertStableCommand

* Fix assertStableCommand logic

* remove go.mod changes

* Check panic occur on tests

* rename method

* update errors

* Rename flag to UnstableResp3

---------

Co-authored-by: Vladyslav Vildanov <117659936+vladvildanov@users.noreply.github.com>
Co-authored-by: vladvildanov <divinez122@outlook.com>
2024-09-12 11:26:10 +03:00
Monkey
2d8fa02ac2 fix: fix #2681 (#2998)
Signed-off-by: monkey92t <golang@88.com>
2024-05-29 10:55:28 +08:00
高木同学
f7f34feddf Optimize docs useless imports and typo (#2970) 2024-04-14 22:59:09 +08:00
kindknow
6960bcc08d chore: fix some comments (#2967)
Signed-off-by: kindknow <iturf@sina.com>
Co-authored-by: Monkey <golang@88.com>
2024-04-14 01:15:23 +08:00
John
683f4fa6a6 fix misuses of a vs an (#2936)
Signed-off-by: hishope <csqiye@126.com>
Co-authored-by: ofekshenawa <104765379+ofekshenawa@users.noreply.github.com>
Co-authored-by: Monkey <golang@88.com>
2024-04-04 09:16:30 +08:00
ofekshenawa
a32be3d93d Add Suffix support to default client set info (#2852)
* Add Suffix support to defualt client set info

* Change ClientNameSuffix to IdentitySuffix

* add tests
2024-01-04 14:40:14 +02:00
Tiago Peczenyj
a5fe17472a Option types must propagage missing fields (#2726)
* must propagage missing fields

Signed-off-by: Tiago Peczenyj <tpeczenyj@weborama.com>

* remove credentials provider from ring

---------

Signed-off-by: Tiago Peczenyj <tpeczenyj@weborama.com>
Co-authored-by: ofekshenawa <104765379+ofekshenawa@users.noreply.github.com>
2023-10-30 14:36:44 +02:00
chenjie199234
fd13da4fea fix missing fields in different Options (#2757)
* fix missing fields in different Options

* fix missing fields in different Options

---------

Co-authored-by: chenjie199234 <chenjie199234@gmail.com>
Co-authored-by: ofekshenawa <104765379+ofekshenawa@users.noreply.github.com>
2023-10-30 14:35:51 +02:00
Nikolay Vorobev
e23ea028bd Added MaxActiveConns (#2646)
* Added the ability to set a connection growth limit when there are not enough connections in the pool using MaxActiveConns

* fix comment

* fix

* fix

---------

Co-authored-by: ofekshenawa <104765379+ofekshenawa@users.noreply.github.com>
2023-09-20 14:55:23 +03:00
ofekshenawa
0b6be62b71 Identify client on connect (#2708)
* Update CLIENT-SETINFO to support suffixes

* Update CLIENT-SETINFO

* fix acl log test

* add setinfo option to cluster

* change to DisableIndentity

* change to DisableIndentity
2023-09-20 10:33:09 +03:00
ljun20160606
391798880c feat: add protocol option (#2598) 2023-05-16 22:02:22 +08:00
fengyun.rui
f1c2e3261e docs: update doc of redis option (#2567) 2023-04-28 09:47:01 +03:00
Vladimir Mihailenco
97b491aace chore: update import path 2023-01-23 08:48:54 +02:00
monkey92t
d42dd1007c docs: add a description of the hook
Signed-off-by: monkey92t <golang@88.com>
2023-01-07 16:30:56 +08:00
monkey92t
a872c35b1a feat: add ClientName option
Signed-off-by: monkey92t <golang@88.com>
2022-12-28 22:14:52 +08:00
Vladimir Mihailenco
1278a8094f chore: sync the doc comment 2022-11-09 14:57:10 +02:00
Vladimir Mihailenco
0dff3d1461 feat: add OpenTelemetry metrics instrumentation 2022-10-12 11:09:41 +03:00
Vladimir Mihailenco
58f7149e38 feat: add ContextTimeoutEnabled to respect context timeouts and deadlines 2022-10-11 10:22:42 +03:00
Stephanie Hingtgen
6327c52e60 Add ParseURL function for cluster mode (#1924)
* feat: add ParseClusterURL to allow for parsing of redis cluster urls into cluster options
2022-10-06 13:33:37 +03:00
Vladimir Mihailenco
a65f5edea0 chore: rename DefaultDialer to NewDialer 2022-10-06 10:25:00 +03:00
Vladimir Mihailenco
a9287a16d6 Merge pull request #1997 from nkcmr/feature/nick/default-dialer
feat: extract dialer to `DefaultDialer` to allow wrapping
2022-10-06 10:23:38 +03:00
Vladimir Mihailenco
bac50ce2e9 chore: allow to disable timeouts 2022-10-05 10:36:12 +03:00
jianghang
2123e08437 fix(internal/pool): call SetDeadline even if timeout is zero 2022-08-04 11:22:11 +08:00
Vladimir Mihailenco
f6a8adc50c fix: remove conn reaper from the pool and uptrace option names 2022-07-28 15:17:59 +03:00
Vladimir Mihailenco
a18fad5bd3 chore: v9 2022-06-04 17:42:06 +03:00