forked from valkey-io/valkey-glide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_management_commands_test.go
127 lines (103 loc) · 3.43 KB
/
server_management_commands_test.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0
package api
import (
"fmt"
"strconv"
"time"
"github.com/valkey-io/valkey-glide/go/api/options"
)
func ExampleGlideClient_Select() {
var client *GlideClient = getExampleGlideClient() // example helper function
result, err := client.Select(2)
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Println(result)
// Output: OK
}
func ExampleGlideClient_ConfigGet() {
var client *GlideClient = getExampleGlideClient() // example helper function
client.ConfigSet(map[string]string{"timeout": "1000", "maxmemory": "1GB"}) // example configuration
result, err := client.ConfigGet([]string{"timeout", "maxmemory"})
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Println(result)
// Output:
// map[maxmemory:1073741824 timeout:1000]
}
func ExampleGlideClient_ConfigSet() {
var client *GlideClient = getExampleGlideClient() // example helper function
result, err := client.ConfigSet(map[string]string{"timeout": "1000", "maxmemory": "1GB"}) // example configuration
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Println(result)
// Output:
// OK
}
func ExampleGlideClient_DBSize() {
var client *GlideClient = getExampleGlideClient() // example helper function
// Assume flushed client, so no keys are currently stored
client.Set("key", "val")
result, err := client.DBSize()
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Println(result)
// Output:
// 1
}
func ExampleGlideClient_Time() {
var client *GlideClient = getExampleGlideClient() // example helper function
timeMargin := int64(5)
clientTime := time.Now().Unix()
result, err := client.Time()
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
serverTime, _ := strconv.ParseInt(result[0], 10, 64)
fmt.Println((serverTime - clientTime) < timeMargin)
// Output: true
}
func ExampleGlideClusterClient_Time() {
var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function
timeMargin := int64(5)
clientTime := time.Now().Unix()
result, err := client.Time()
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
serverTime, _ := strconv.ParseInt(result[0], 10, 64)
fmt.Println((serverTime - clientTime) < timeMargin)
// Output: true
}
func ExampleGlideClient_Info() {
var client *GlideClient = getExampleGlideClient() // example helper function
response, err := client.Info()
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Printf("response is of type %T\n", response)
// Output: response is of type string
}
func ExampleGlideClient_InfoWithOptions() {
var client *GlideClient = getExampleGlideClient() // example helper function
opts := options.InfoOptions{Sections: []options.Section{options.Server}}
response, err := client.InfoWithOptions(opts)
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Printf("response is of type %T\n", response)
// Output: response is of type string
}
func ExampleGlideClient_LastSave() {
var client *GlideClient = getExampleGlideClient() // example helper function
response, err := client.LastSave()
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Println(response)
// Output:
// 1742239667
}