11# Oxia Go client API
22
3- The full GoDoc reference for the Oxia Go Client can be found at https://pkg.go.dev/github.com/streamnative/oxia/oxia
3+ The full GoDoc reference for the Oxia Go client can be found at: https://pkg.go.dev/github.com/streamnative/oxia/oxia .
44
55A simple example on how to write and read records:
66
77``` go
88// import "github.com/streamnative/oxia/oxia"
99
10-
1110client , err := oxia.NewSyncClient (" localhost:6648" )
1211if err != nil {
1312 return err
@@ -36,7 +35,6 @@ Oxia also provides an "async" client API that makes use of channels to track the
3635With the async client API, a single go-routine can submit many concurrent requests. In addition, the Oxia client library
3736will automatically batch the request for better performance.
3837
39-
4038``` go
4139client , err := oxia.NewAsyncClient (" localhost:6648" ,
4240 oxia.WithBatchLinger (10 *time.Millisecond ))
@@ -56,7 +54,6 @@ if res := <-c3; res.Err != nil {
5654}
5755```
5856
59-
6057## Namespaces
6158
6259A client can use a particular Oxia namespace, other than ` default ` , by specifying an option in the client instantiation:
@@ -74,7 +71,6 @@ Client can subscribe to receive a feed of notification with all the events happe
7471Notifications can be used to replicate exactly the state of an oxia namespace or to invalidate a cache.
7572
7673``` go
77-
7874client , err := oxia.NewSyncClient (" localhost:6648" )
7975notifications , err := client.GetNotifications ()
8076if err != nil {
@@ -114,7 +110,7 @@ appropriately with `oxia.WithSessionTimeout()` option when creating the client i
114110
115111Oxia client provides a built-in optional cache that will store the deserialized values.
116112
117- Example:
113+ Example:
118114
119115``` go
120116type myStruct struct {
@@ -134,9 +130,9 @@ value, version, err := cache.Get(context.Background(), "/my-key")
134130fmt.Printf (" A: %s - B: %d \n " , value.A , value.B )
135131
136132// We can also do atomic read-modify-updates through the cache
137- // This will not incur in a read from the server if the value is already
133+ // This will not incur in a read from the server if the value is already
138134// in cache and up to the latest version
139- err = cache.ReadModifyUpdate (context.Background (), " /my-key" ,
135+ err = cache.ReadModifyUpdate (context.Background (), " /my-key" ,
140136 func (existingValue Optional [myStruct ]) (myStruct , error ) {
141137 return myStruct{
142138 A: existingValue.MustGet ().A ,
@@ -149,6 +145,5 @@ err = cache.ReadModifyUpdate(context.Background(), "/my-key",
149145
150146The cache is kept up to date using Oxia notification, to invalidate whenever a record is updated.
151147
152- Change don through the cache are also immediately reflected in the cache. For updates done outside the cache instance,
148+ Change don through the cache are also immediately reflected in the cache. For updates done outside the cache instance,
153149the cache will be eventually consistent, meaning that a cache read could return a stale value for a short amount of time.
154-
0 commit comments