Skip to content

GO: Lazy connect implementation#4374

Merged
affonsov merged 3 commits intomainfrom
go/affonsov-lazy-connect
Jul 25, 2025
Merged

GO: Lazy connect implementation#4374
affonsov merged 3 commits intomainfrom
go/affonsov-lazy-connect

Conversation

@affonsov
Copy link
Copy Markdown
Collaborator

@affonsov affonsov commented Jul 15, 2025

Overview

This PR implements lazy connection functionality for the Valkey GLIDE Go client, allowing clients to defer connection establishment until the first operation is executed.

Key Features

  • Deferred Connection: Clients with lazy connect enabled only establish connections when the first operation is executed
  • Backward Compatibility: Lazy connect is disabled by default, maintaining existing behavior
  • Full Support: Available for both standalone and cluster client configurations
  • Testing: Includes unit tests and integration tests validating the lazy connection behavior

Testing

  • New unit tests verify configuration and protobuf conversion
  • Integration tests confirm lazy connection behavior in both standalone and cluster modes
  • Connection count monitoring ensures connections are established only when needed

Changes Made

Configuration Updates (go/config/config.go)

  • Added lazyConnect field to baseClientConfiguration struct
  • Implemented WithLazyConnect() method for both ClientConfiguration and ClusterClientConfiguration

Unit Test (go/config/config_test.go)

  • Added TestConfig_LazyConnect() test function covering:
    • Lazy connect enabled for both standalone and cluster configurations
    • Default behavior verification (lazy connect disabled by default)

Integration Testing Infrastructure

  • New cluster management utilities

    • Port from (python/tests/utils/cluster.py) to (go/integTest/cluster.go`):
    • ValkeyCluster struct for managing test cluster instances
    • Support for both TLS and non-TLS configurations
    • Flexible cluster creation with configurable shard/replica counts
    • Integration with existing cluster manager Python scripts
    • Proper cleanup and resource management
  • Connection testing (go/integTest/connection_test.go):

    • TestLazyConnectionEstablishesOnFirstCommand() - test validating lazy connection behavior
    • Helper functions for client count monitoring and connection tracking
    • Support for both standalone and cluster mode testing
    • Verification that connections are only established after the first command
  • Test suite enhancements (go/integTest/glide_test_suite_test.go):

    • createClient() helper function for flexible client creation
    • Support for lazy connect configuration in test clients
    • Unified client creation interface for both standalone and cluster modes

Issue link

This Pull Request is linked to issue (URL): #4350

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one issue.
  • Commit message has a detailed description of what changed and why.
  • Tests are added or updated.
  • CHANGELOG.md and documentation files are updated.
  • Destination branch is correct - main or release
  • Create merge commit if merging release branch into main, squash otherwise.

Copy link
Copy Markdown

@Yury-Fridlyand Yury-Fridlyand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add changelog

Copy link
Copy Markdown
Collaborator

@jamesx-improving jamesx-improving left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. All comments nit.

affonsov added 3 commits July 24, 2025 14:23
Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
@affonsov affonsov force-pushed the go/affonsov-lazy-connect branch from 92584d5 to cef5987 Compare July 24, 2025 21:24
@affonsov affonsov merged commit 8d99de9 into main Jul 25, 2025
29 of 30 checks passed
@affonsov affonsov deleted the go/affonsov-lazy-connect branch July 29, 2025 16:18
alexr-bq pushed a commit that referenced this pull request Sep 3, 2025
* GO: Lazy connect implementation

Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>

---------

Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
Signed-off-by: Alex Rehnby-Martin <alex.rehnby-martin@improving.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go 🏃 golang wrapper

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants