1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-29 17:41:15 +03:00
Commit Graph

2691 Commits

Author SHA1 Message Date
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
c33b157015 feat: add protected handler support and rename command to pushNotificationName
- Add protected flag to RegisterHandler methods across all types
- Protected handlers cannot be unregistered, UnregisterHandler returns error
- Rename 'command' parameter to 'pushNotificationName' for clarity
- Update PushNotificationInfo.Command field to Name field
- Add comprehensive test for protected handler functionality
- Update all existing tests to use new protected parameter (false by default)
- Improve error messages to use 'push notification' terminology

Benefits:
- Critical handlers can be protected from accidental unregistration
- Clearer naming reflects that these are notification names, not commands
- Better error handling with informative error messages
- Backward compatible (existing handlers work with protected=false)
2025-06-27 01:36:33 +03:00
79f6df26c3 remove: push-notification-demo 2025-06-27 01:36:31 +03:00
958fb1a760 fix: resolve data race in PushNotificationProcessor
- Add sync.RWMutex to PushNotificationProcessor struct
- Protect enabled field access with read/write locks in IsEnabled() and SetEnabled()
- Use thread-safe IsEnabled() method in ProcessPendingNotifications()
- Fix concurrent access to enabled field that was causing data races

This resolves the race condition between goroutines calling IsEnabled() and
SetEnabled() concurrently, ensuring thread-safe access to the enabled field.
2025-06-27 01:36:28 +03:00
70231ae4e9 refactor: simplify push notification interface
- Remove RegisterPushNotificationHandlerFunc methods from all types
- Remove PushNotificationHandlerFunc type adapter
- Keep only RegisterPushNotificationHandler method for cleaner interface
- Remove unnecessary push notification constants (keep only Redis Cluster ones)
- Update all tests to use simplified interface with direct handler implementations

Benefits:
- Cleaner, simpler API with single registration method
- Reduced code complexity and maintenance burden
- Focus on essential Redis Cluster push notifications only
- Users implement PushNotificationHandler interface directly
- No functional changes, just interface simplification
2025-06-27 01:36:26 +03:00
4747610d01 test: add comprehensive unit tests for 100% coverage
- Add 10 new unit tests covering all previously untested code paths
- Test connection pool integration with push notifications
- Test connection health check integration
- Test Conn type push notification methods
- Test cloned client push notification preservation
- Test PushNotificationInfo structure validation
- Test edge cases and error scenarios
- Test custom processor integration
- Test disabled push notification scenarios

Total coverage now includes:
- 20 existing push notification tests
- 10 new comprehensive coverage tests
- All new code paths from connection pool integration
- All Conn methods and cloning functionality
- Edge cases and error handling scenarios
2025-06-27 01:36:24 +03:00
1331fb9957 fix: remove unused fields and ensure push notifications work in cloned clients
- Remove unused Timestamp and Source fields from PushNotificationInfo
- Add pushProcessor to newConn function to ensure Conn instances have push notifications
- Add push notification methods to Conn type for consistency
- Ensure cloned clients and Conn instances preserve push notification functionality

This fixes issues where:
1. PushNotificationInfo had unused fields causing confusion
2. Conn instances created via client.Conn() lacked push notification support
3. All client types now consistently support push notifications
2025-06-27 01:36:22 +03:00
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
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
1ff0ded0e3 feat: enforce single handler per notification type
- Change PushNotificationRegistry to allow only one handler per command
- RegisterHandler methods now return error if handler already exists
- Update UnregisterHandler to remove handler by command only
- Update all client methods to return errors for duplicate registrations
- Update comprehensive test suite to verify single handler behavior
- Add specific test for duplicate handler error scenarios

This prevents handler conflicts and ensures predictable notification
routing with clear error handling for registration conflicts.
2025-06-27 01:36:15 +03:00
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
0decfdc6ed chore(release): v9.11.0 (#3416)
* chore(release): update version to 9.11.0

* chore(release): Add Release Notes for v9.11.0
extra/rediscensus/v9.11.0 extra/redisprometheus/v9.11.0 extra/rediscmd/v9.11.0 extra/redisotel/v9.11.0 v9.11.0
2025-06-24 14:05:24 +03:00
4ac591c7c4 Set correct cluster slot for scan commands, similarly to Java's Jedis client (#2623)
- At present, the `scan` command is dispatched to a random slot.
- As far as I can tell, the scanX family of commands are not cluster aware (e.g. don't redirect the client to the correct slot).
- You can see [here](869dc0bb66/src/main/java/redis/clients/jedis/ShardedCommandObjects.java (L101)), the Jedis client calling `processKey` on the match argument, and this is what this PR also does.

We've had this patch running in production, and it seems to work well for us.

For further thought:
- Continuing looking at other Redis clients (e.g. Jedis), they outright [reject as invalid](869dc0bb66/src/main/java/redis/clients/jedis/ShardedCommandObjects.java (L98)) any scan command that does not include a hash-tag. Presumably this has the advantage of users not being surprised when their scan produces no results when a random server is picked.
- Perhaps it would be sensible for go-redis to do the same also?

Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>
2025-06-24 13:43:03 +03:00
0383d08a35 feat(client): Add CredentialsProvider field to UniversalOptions (#2927)
* Add CredentialsProvider field to universal client

* fix(options): Add credentials providers to universal options and pass to client options

* chore(ring): Add missing fields in building clientOptions

---------

Co-authored-by: ofekshenawa <104765379+ofekshenawa@users.noreply.github.com>
Co-authored-by: Nedyalko Dyakov <nedyalko.dyakov@gmail.com>
Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>
2025-06-24 13:28:54 +03:00
fa475cbc99 feat(redisotel): add WithCallerEnabled option (#3415)
* feat(redisotel): add WithCaller option

Allow the disabling the collection of the `code.function`, `code.filepath` and `code.lineno` tracing attributes.
When setting `WithCaller(false)` overall performance is increased as the "expensive" `runtime.Callers` and `runtime.(*Frames).Next` calls are no longer needed.

* chore(redisotel): improve docblock language

* chore(redisotel): rename `WithCaller` to `WithCallerEnabled`

---------

Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>
2025-06-24 10:53:35 +03:00
05f42e2327 fix(txpipeline): keyless commands should take the slot of the keyed (#3411)
* fix(txpipeline): keyless commands should take the slot of the keyed commands

* fix(txpipeline): extract only keyed cmds from all cmds

* chore(test): Add tests for keyless cmds and txpipeline

* fix(cmdSlot): Add preferred random slot

* fix(cmdSlot): Add shortlist of keyless cmds

* chore(test): Fix ring test

* fix(keylessCommands): Add list of keyless commands

Add list of keyless Commands based on the Commands output
for redis 8

* chore(txPipeline): refactor slottedCommands impl

* fix(osscluster): typo
2025-06-24 10:34:23 +03:00
884f9970c0 DOC-5229 probabilistic data type examples (#3413)
* DOC-5078 added basic vector set examples

* DOC-5078 formatting and extra comments

* DOC-5078 fixed nondeterministic test

* wip(tests): run doctests for vector sets on redis 8 only

* DOC-5229 added probabilistic data type examples

---------

Co-authored-by: Nedyalko Dyakov <nedyalko.dyakov@gmail.com>
2025-06-23 11:49:36 +03:00
e642856ed3 chore(deps): bump rojopolis/spellcheck-github-actions (#3414)
Bumps [rojopolis/spellcheck-github-actions](https://github.com/rojopolis/spellcheck-github-actions) from 0.49.0 to 0.51.0.
- [Release notes](https://github.com/rojopolis/spellcheck-github-actions/releases)
- [Changelog](https://github.com/rojopolis/spellcheck-github-actions/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rojopolis/spellcheck-github-actions/compare/0.49.0...0.51.0)

---
updated-dependencies:
- dependency-name: rojopolis/spellcheck-github-actions
  dependency-version: 0.51.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-06-23 11:49:12 +03:00
7d97cc1c59 feat: optimize connection pool waitTurn (#3412) 2025-06-20 12:07:14 +03:00
f4358acffc [CAE-1046] fix(loading): cache the loaded flag for slave nodes (#3410)
* fix(loading): cache the loaded flag for slave nodes

* fix(lint): make linter happy
2025-06-18 15:18:51 +03:00
4c635cc563 fix(txpipeline): should return error on multi/exec on multiple slots [CAE-1028] (#3408)
* fix(txpipeline): should return error on multi/exec on multiple slots

* fix(txpipeline): test normal tx pipeline behaviour

* chore(err): Extract crossslot err and add test

* fix(txpipeline): short curcuit the tx if there are no commands

* chore(tests): validate keys are in different slots
2025-06-18 14:18:00 +03:00
68717412c9 chore(ci): update CI redis builds (#3407) 2025-06-16 18:28:58 +03:00
82b00cc520 chore: remove a redundant method (#3401)
Signed-off-by: fukua95 <fukua95@gmail.com>
Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>
2025-06-16 16:55:23 +03:00
e2295c7129 test: refactor TestBasicCredentials using table-driven tests (#3406)
* test: refactor TestBasicCredentials using table-driven tests

* Included additional edge cases:

- Empty passwords
- Special characters
- Long strings
- Unicode characters
2025-06-16 11:23:58 +03:00
eb40ac8328 perf: reduce unnecessary memory allocation (#3399)
Signed-off-by: fukua95 <fukua95@gmail.com>
Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>
2025-06-09 11:59:58 +03:00
0f40ae3ff2 fix: check if the shard exists to avoid returning nil (#3396)
Signed-off-by: fukua95 <fukua95@gmail.com>
2025-06-09 11:06:21 +03:00
858ecda7fd fix: insert entry during iterating over a map (#3398)
Signed-off-by: fukua95 <fukua95@gmail.com>
2025-06-09 11:03:18 +03:00
75e8370a6f chore(release): Update release notes and versions for v9.10.0 (#3395) extra/rediscmd/v9.10.0 extra/redisprometheus/v9.10.0 extra/redisotel/v9.10.0 v9.10.0 extra/rediscensus/v9.10.0 2025-06-06 18:30:30 +03:00
98b224cf7d DOC-5078 vector set examples (#3394) 2025-06-06 16:25:35 +03:00
4e22885ca1 feat: support vectorset (#3375)
* feat: support vectorset

* fix: char encoding error

* use `any` instread of `interface{}`

* update vectorset API

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

* refact: MapStringFloat64Cmd -> VectorInfoSliceCmd

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

* update:

* the type of vector attribute: string -> VectorAttributeMarshaller
* Add a new API VRemAttr
* mark the APIs are experimental

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

* trigger CI again

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

* rename a API: VRemAttr -> VClearAttributes

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

* add test

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

* feat(vectorset): improve VSetAttr API and add comprehensive test suite

- Simplify VSetAttr to accept interface{} with automatic JSON marshalling
- Remove VectorAttributeMarshaller interface for simpler API
- Add comprehensive unit tests for all vectorset commands

---------

Signed-off-by: fukua95 <fukua95@gmail.com>
Co-authored-by: Nedyalko Dyakov <nedyalko.dyakov@gmail.com>
2025-06-05 11:35:45 +03:00
c609828c9b chore(tests): add the missing NewFloatSliceResult for testing (#3393) 2025-06-03 13:27:54 +03:00
a7772e47c0 Update RELEASE-NOTES.md (#3391) 2025-05-28 10:30:31 +03:00
c935f96148 release(go-redis): v9.9.0 (#3390)
* release(go-redis): v9.9.0

- Add release notes
- Update dependencies and version.go

* chore(release-notes) Update release notes
extra/redisprometheus/v9.9.0 v9.9.0 extra/rediscmd/v9.9.0 extra/redisotel/v9.9.0 extra/rediscensus/v9.9.0
2025-05-27 19:00:07 +03:00
cb1968cad6 feat(ring): add GetShardClients and GetShardClientForKey methods to Ring for shard access (#3388)
* feat: expose shard information in redis.Ring

- Add GetShards() method to retrieve a list of active shard clients.
- Add GetShardByKey(key string) method to get the shard client for a specific key.
- These methods enable users to manage Pub/Sub operations more effectively by accessing shard-specific clients.

* rename GetShardClients and GetShardClientForKey

---------

Co-authored-by: DengY11 <212294929@qq.com>
Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>
2025-05-27 18:04:04 +03:00
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
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
66b61c432c chore(deps): bump rojopolis/spellcheck-github-actions (#3389)
Bumps [rojopolis/spellcheck-github-actions](https://github.com/rojopolis/spellcheck-github-actions) from 0.48.0 to 0.49.0.
- [Release notes](https://github.com/rojopolis/spellcheck-github-actions/releases)
- [Changelog](https://github.com/rojopolis/spellcheck-github-actions/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rojopolis/spellcheck-github-actions/compare/0.48.0...0.49.0)

---
updated-dependencies:
- dependency-name: rojopolis/spellcheck-github-actions
  dependency-version: 0.49.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-05-27 14:52:52 +03:00
d7ba255394 fix: prevent routing reads to loading slave nodes (#3370)
Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>
2025-05-21 13:58:21 +03:00
b67455e099 xinfo-groups: support nil lag in XINFO GROUPS (#3369)
* xinfo-groups: support nil lag in XINFO GROUPS

* Add test

* docs: clarify XInfoGroup.Lag field behavior with Nil values

* docs: clarify XInfoGroup.Lag field behavior
2025-05-21 13:57:58 +03:00
03c2c0b088 chore: remove unused param (#3384)
Signed-off-by: fukua95 <fukua95@gmail.com>
2025-05-20 14:11:53 +03:00
c149644da7 Unit test for pool acquisition timeout (#3381)
Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>
2025-05-19 19:46:19 +03:00
bc70b52b42 perf: avoid unnecessary copy operation (#3376)
* optime: reduce unnecessary copy operations

* add a comment

* trigger CI without code changes, because the bug of docker

* add comments
2025-05-19 19:24:37 +03:00
ba26e35a2c Export pool errors for public consumption (#3380) 2025-05-19 19:23:10 +03:00
80c373be46 chore: remove unused param (#3382)
* chore: remove unused param

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

* chore: rename a unused param to `_`

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

---------

Signed-off-by: fukua95 <fukua95@gmail.com>
2025-05-19 19:22:51 +03:00
3af2cc5783 chore: optimize function ReplaceSpaces (#3383)
* chore: optimize function `ReplaceSpaces`

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

* trigger CI again because the bug of docker

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

* trigger CI again because the bug of docker

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

---------

Signed-off-by: fukua95 <fukua95@gmail.com>
2025-05-19 19:21:17 +03:00
43e7fb5eef test(util): add unit tests for Atoi, ParseInt, ParseUint, and ParseFloat (#3377) 2025-05-15 14:53:54 +03:00
6c6dddcf7c feat: add ParseFailoverURL (#3362)
* add ParseFailoverURL for FailoverOptions
* fix 2 warning

Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>
2025-05-15 14:53:40 +03:00
42c32846e6 utils: export ParseFloat and MustParseFloat wrapping internal utils (#3371)
* utils: expose ParseFloat via new public utils package

* add tests for special float values in vector search
2025-05-09 12:24:36 +03:00
f174acba52 ci(redis): update to 8.0.1 (#3372) 2025-05-08 15:32:47 +03:00
8ba559ca5d feat: add connection waiting statistics (#2804)
Co-authored-by: ofekshenawa <104765379+ofekshenawa@users.noreply.github.com>
2025-05-07 15:54:26 +03:00