• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

heathcliff26 / valkey-keepalived / 13475691077

22 Feb 2025 06:51PM UTC coverage: 73.026%. First build
13475691077

push

github

heathcliff26
Initial Commit

Signed-off-by: Heathcliff <heathcliff@heathcliff.eu>

222 of 304 new or added lines in 7 files covered. (73.03%)

222 of 304 relevant lines covered (73.03%)

0.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

44.44
/pkg/failover-client/node.go
1
package failoverclient
2

3
import (
4
        "context"
5
        "log/slog"
6

7
        "github.com/valkey-io/valkey-go"
8
)
9

10
type node struct {
11
        address string
12
        port    int64
13
        runID   string
14
        up      bool
15
        client  valkey.Client
16
}
17

18
const failedToConnectToNodeMsg = "Failed to connect to node"
19

20
func (n *node) connect(ctx context.Context, option valkey.ClientOption) error {
1✔
21
        client, err := newValkeyClient(n.address, n.port, option)
1✔
22
        if err != nil {
1✔
NEW
23
                return err
×
NEW
24
        }
×
25

26
        res, err := client.Do(ctx, client.B().Info().Section("server").Build()).ToString()
1✔
27
        if err != nil {
1✔
NEW
28
                client.Close()
×
NEW
29
                return err
×
NEW
30
        }
×
31

32
        n.runID = parseRunIDFromInfo(res)
1✔
33
        n.client = client
1✔
34
        n.up = true
1✔
35

1✔
36
        return nil
1✔
37
}
38

39
func (n *node) ping(ctx context.Context) {
1✔
40
        res, err := n.client.Do(ctx, n.client.B().Ping().Build()).ToString()
1✔
41
        if err != nil || res != "PONG" {
1✔
NEW
42
                if n.up {
×
NEW
43
                        slog.Info("Node is DOWN", slog.String("node", n.address), "err", err, slog.String("res", res))
×
NEW
44
                        n.up = false
×
NEW
45
                }
×
NEW
46
                n.client.Close()
×
NEW
47
                n.client = nil
×
48
        } else if !n.up {
1✔
NEW
49
                n.up = true
×
NEW
50
                slog.Info("Node is UP", slog.String("node", n.address))
×
NEW
51
        }
×
52
}
53

54
func (n *node) master(ctx context.Context) error {
1✔
55
        if n.client == nil {
1✔
NEW
56
                slog.Debug("Node is not up, skipping for update", slog.String("node", n.address))
×
NEW
57
                return nil
×
NEW
58
        }
×
59

60
        return n.client.Do(ctx, n.client.B().Replicaof().No().One().Build()).Error()
1✔
61
}
62

63
func (n *node) slave(ctx context.Context, master string) error {
1✔
64
        if n.client == nil {
1✔
NEW
65
                slog.Debug("Node is not up, skipping for update", slog.String("node", n.address))
×
NEW
66
                return nil
×
NEW
67
        }
×
68

69
        return n.client.Do(ctx, n.client.B().Replicaof().Host(master).Port(n.port).Build()).Error()
1✔
70
}
71

NEW
72
func (n *node) close() {
×
NEW
73
        if n.client != nil {
×
NEW
74
                n.client.Close()
×
NEW
75
                n.client = nil
×
NEW
76
        }
×
77
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc