This directory contains various examples on how to use the Coherence Go client.
git clone github.com/coherence/coherence-go-client
cd coherence-go-client/examples
go get github.com/oracle/coherence-go-client/v2@latest
Before running any of the examples, you must ensure a Coherence cluster is available. For local development, we recommend using the Coherence CE Docker image; it contains everything necessary for the client to operate correctly.
docker run -d -p 1408:1408 -p 30000:30000 ghcr.io/oracle/coherence-ce:24.09
- Basic operations using primitives and structs
- Using near caches
- Querying data
- Aggregating data
- Mutating data using entry processors
- Listening for map events
- Listening for map lifecycle events
- Listening for session lifecycle events
- Adding indexes
- Working with Queues
- Basic REST server
These examples shows how to carry out basic operations against a NamedMap or NamedCache.
This examples runs Put()
, Get()
, Remove()
operations against a NamedMap or NamedCache with key in and value string.
Source code: basic/crud/main.go
go run basic/crud/main.go
Source code: basic/struct/main.go
go run basic/struct/main.go
Source code: basic/struct_keys/main.go
go run basic/struct_keys/main.go
Source code: basic/contains/main.go
go run basic/contains/main.go
This example uses a NamedCache
and issues PutWithExpiry
to expire a value after a certain time.
Source code: basic/expiry/main.go
go run basic/expiry/main.go
This example uses a NamedCache
that has been created using coherence.WithExpiry
option, which
will expire all cache entries after the specified time without the need to use PutWithExpiry
.
Source code: basic/expiry_cache/main.go
go run basic/expiry_cache/main.go
These example shows how to specify a near-cache for either NamedMap or NamedCache which will cache data accessed via Get() operations on the Go client for fast subsequent local access. Near caches can specify time-to-live (TTL) for entries in a cache as well as number of entries or size of entryes. Any updates of data from the back-end will update the data in the near cache or any data removals will invalidate the near cache.
Source code: basic/near_cache/ttl/main.go
go run basic/near_cache/ttl/main.go
Source code: basic/near_cache/high_units/main.go
go run basic/near_cache/high_units/main.go
Source code: basic/near_cache/memory/main.go
go run basic/near_cache/memory/main.go
These examples shows how to query data operations against a NamedMap or NamedCache.
Source code: querying/keys/main.go
go run querying/keys/main.go
Source code: querying/filters/main.go
go run querying/filters/main.go
Note: When using open-ended queries, Coherence internally pages data to ensure that you are not returning all data in one large dataset. Care should still be taken to minimize occurrences of these queries on large caches.
Source code: querying/main.go
go run querying/main.go
This example shows how to carry out various aggregations against a NamedMap or NamedCache.
Source code: aggregators/main.go
go run aggregators/main.go
This example shows how to run entry processors against a or NamedMap or NamedCache with a key of int and value of Person struct.
Source code: processors/standard/main.go
go run processors/standard/main.go
This example shows how to run the same entry processors but use the utility functions to ignore the values returned.
Source code: processors/blind/main.go
go run processors/blind/main.go
These examples show how to listen for events on a NamedMap or NamedCache.
Source code: events/cache/all/main.go
go run events/cache/all/main.go
Source code: events/cache/insert/main.go
go run events/cache/insert/main.go
Source code: events/cache/update/main.go
go run events/cache/update/main.go
Source code: events/cache/delete/main.go
go run events/cache/delete/main.go
Source code: events/cache/filters/main.go
go run events/cache/filters/main.go
Source code: events/cache/key/main.go
go run events/cache/key/main.go
Source code: events/lifecycle/truncated/main.go
go run events/lifecycle/truncated/main.go
Source code: events/lifecycle/destroyed/main.go
go run events/lifecycle/destroyed/main.go
Source code: events/lifecycle/released/main.go
go run events/lifecycle/released/main.go
Source code: events/lifecycle/all/main.go
go run events/lifecycle/all/main.go
Source code: events/session/all/main.go
go run events/session/all/main.go
This example shows how to add a remove indexes on a NamedMap or NamedCache to help query or aggregation performance.
Source code: indexes/main.go
go run indexes/main.go
This example shows how to work with both standard (NamedQueue) and blocking (NamesBlockingQueue).
Note: This feature is currently only available when using Coherence server version CE 24.04 and above.
Source code: queues/standard/main.go
go run queues/standard/main.go
This example show how to use a Dequeue or double-ended queue. To run this example there are three programs:
Source code: queues/dequeue/main.go
go run queues/dequeue/main.go
This example show how to listen for events on queues.
Source code: queues/events/main.go
go run queues/events/main.go
This example starts a listener on port localhost:17268 which provides a basic REST API providing POST, GET, PUT and DELETE operations against a NamedMap.
Source code: rest/main.go
go run rest/main.go