/
two.go
39 lines (32 loc) · 1.17 KB
/
two.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import "fmt"
import "github.com/hazelcast/hazelcast-go-client"
/* The routine writes data in Hazelcast and closes down.
* If Hazelcast doesn't close down too, then the data stays
* for "three.go" to use.
*
* We save "Hello World" in various languages
*/
func main() {
// Connect
clientConfig := hazelcast.NewConfig()
clientConfig.NetworkConfig().AddAddress("127.0.0.1:5701")
client, _ := hazelcast.NewClientWithConfig(clientConfig)
// The map is stored on the server but we can access it from the client
mapName := "greetings"
greetings, _ := client.GetMap(mapName)
// 0 if first run, non-zero if Hazelcast has data already
size, _ := greetings.Size()
fmt.Printf("Map '%v' Size before %v\n", greetings.Name(), size)
// Write or overwrite data in the map as if it was stored in the client
greetings.Put("English", "hello world")
greetings.Put("Spanish", "hola mundo")
greetings.Put("Italian", "ciao mondo")
greetings.Put("German", "hallo welt")
greetings.Put("French", "bonjour monde")
// 5 added, so at least 5 on the server side
size, _ = greetings.Size()
fmt.Printf("Map '%v' Size after %v\n", greetings.Name(), size)
// Disconnect
client.Shutdown()
}