ignite-go-client
ignite-go client
Go thin client for Apache Ignite
Requirements
- Go 1.19 or higher.
Installation
go get gitverse.ru/sbertech/ignite-go-client
Usage
Basic usage of the apache ignite go driver starts with creating
using function
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)defer cancel()client, err := ignite.Start(ctx, ignite.WithAddresses("127.0.0.1:10800", "127.0.0.1:10801"))if err != nil { return err}defer func() { _ = client.Close(context.Background())}()
This will create a new ignite client to the ignite cluster on localhost. It is possible
to pass multiple
parameters to method Start that specify various
client options.
Cache creation
Cache can be created or obtained with help of these methods:
gets/creates cache by name.Client.GetOrCreateCache
creates cache by name.Client.CreateCache
gets/creates cache byClient.GetOrCreateCacheWithConfiguration
.CacheConfiguration
creates cache byClient.CreateCacheWithConfiguration
. A list of already created caches can be obtained usingCacheConfiguration
. A cache can be destroyed withClient.CacheNames
.Client.DestroyCache
Cache operations
Here is a basic usage scenario of
:
ctx := context.Background()cache, err := client.GetOrCreateCacheWithConfiguration(ctx, ignite.CreateCacheConfiguration("test", ignite.WithCacheAtomicityMode(ignite.AtomicAtomicityMode), ignite.WithCacheMode(ignite.ReplicatedCacheMode), ignite.WithReadFromBackup(true)))if err != nil { fmt.Printf("Failed to create cache %s \n", err) return}err = cache.Put(ctx, "test", "test")if err != nil { fmt.Printf("Failed to put value %s \n", err) return}contains`` err := cache.ContainsKey(ctx, "test")if err != nil { fmt.Printf("Failed to invoke contains key operation %s \n", err) return}fmt.Printf("Contains key %s? %t\n", "test", contains)>>> Contains key test? true
You can see other operations in
documentation. Currently only limited types are supported: numerical types, string,
uuid, bytes slices. Other types and BinaryObject will be added in later releases.
TTL (ExpiryPolicy) support
You can set ExpiryPolicy to entries by creating special decorator by
.
cache, err := client.GetOrCreateCache(ctx, "cache_name")if err != nil { fmt.Printf("Failed to create cache %s \n"`` err) return}cache = cache.WithExpiryPolicy(1*time.Second, DurationZero, DurationZero)err = cache.Put(ctx, "test", "test")if err != nil { fmt.Printf("Failed to put value %s \n", err) return}<-time.After(1200 * time.Millisecond)contains, err := cache.ContainsKey(ctx, "test")if err != nil { fmt.Printf("Failed to invoke contains key operation %s \n", err) return}fmt.Printf("Contains key %s? %t\n", "test", contains)>>> Contains key test? false
Описание
Тонкий клиент на языке Golang для Apache Ignite и Platform V DataGrid
Языки
Go
- Makefile
- Shell
- Java