Random choice

    Note

    The article is being updated.

    The YDB SDK uses the random_choice algorithm by default.

    Below are examples of the code for forced setting of the "random choice" balancing algorithm in different YDB SDKs.

    package main
    
    import (
    	"context"
    	"os"
    
    	"github.com/ydb-platform/ydb-go-sdk/v3"
    	"github.com/ydb-platform/ydb-go-sdk/v3/balancers"
    )
    
    func main() {
    	ctx, cancel := context.WithCancel(context.Background())
    	defer cancel()
    	db, err := ydb.Open(ctx,
    		os.Getenv("YDB_CONNECTION_STRING"),
    		ydb.WithBalancer(
    			balancers.RandomChoice(),
    		),
    	)
    	if err != nil {
    		panic(err)
    	}
    	defer func() {
    		_ = db.Close(ctx)
    	}()
    }