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

OdyseeTeam / odysee-api / 15026270896

14 May 2025 04:39PM UTC coverage: 26.421% (+0.07%) from 26.356%
15026270896

push

github

anbsky
Fix linter issues

4 of 6 new or added lines in 3 files covered. (66.67%)

207 existing lines in 7 files now uncovered.

4282 of 16207 relevant lines covered (26.42%)

166.65 hits per line

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

82.46
/pkg/sturdycache/sturdycache.go
1
package sturdycache
2

3
import (
4
        "context"
5
        "math/rand/v2"
6
        "time"
7

8
        "github.com/eko/gocache/lib/v4/cache"
9
        "github.com/eko/gocache/lib/v4/store"
10
        redis_store "github.com/eko/gocache/store/redis/v4"
11
        "github.com/redis/go-redis/v9"
12
)
13

14
const ReplicatedCacheType = "redis"
15

16
type ReplicatedCache struct {
17
        masterCache   *cache.Cache[any]
18
        replicaCaches []*cache.Cache[any]
19
        readCaches    []*cache.Cache[any]
20
}
21

22
// NewReplicatedCache creates a new gocache store instance for redis master-replica setups.
23
// Requires one master server address and one or more replica addresses.
24
func NewReplicatedCache(
25
        masterAddr string,
26
        replicaAddrs []string,
27
        password string,
28
) (*ReplicatedCache, error) {
16✔
29

16✔
30
        masterClient := redis.NewClient(&redis.Options{
16✔
31
                Addr:         masterAddr,
16✔
32
                Password:     password,
16✔
33
                DB:           0,
16✔
34
                PoolSize:     200,
16✔
35
                MinIdleConns: 10,
16✔
36
        })
16✔
37

16✔
38
        masterStore := redis_store.NewRedis(masterClient)
16✔
39
        masterCache := cache.New[any](masterStore)
16✔
40

16✔
41
        replicaCaches := []*cache.Cache[any]{}
16✔
42

16✔
43
        for _, addr := range replicaAddrs {
64✔
44
                replicaClient := redis.NewClient(&redis.Options{
48✔
45
                        Addr:         addr,
48✔
46
                        Password:     password,
48✔
47
                        DB:           0,
48✔
48
                        PoolSize:     200,
48✔
49
                        MinIdleConns: 10,
48✔
50
                })
48✔
51

48✔
52
                replicaStore := redis_store.NewRedis(replicaClient)
48✔
53
                replicaCaches = append(replicaCaches, cache.New[any](replicaStore))
48✔
54
        }
48✔
55

56
        baseStore := &ReplicatedCache{
16✔
57
                masterCache:   masterCache,
16✔
58
                replicaCaches: replicaCaches,
16✔
59
                readCaches:    append(replicaCaches, masterCache),
16✔
60
        }
16✔
61

16✔
62
        return baseStore, nil
16✔
63
}
64

65
// Set writes to master.
66
func (rc *ReplicatedCache) Set(ctx context.Context, key any, value any, options ...store.Option) error {
26✔
67
        return rc.masterCache.Set(ctx, key, value, options...)
26✔
68
}
26✔
69

70
// Get reads from master and replica caches.
71
func (rc *ReplicatedCache) Get(ctx context.Context, key any) (any, error) {
16✔
72
        // #nosec G404
16✔
73
        return rc.readCaches[rand.IntN(len(rc.readCaches))].Get(ctx, key)
16✔
74
}
16✔
75

76
// Get reads from master and replica caches.
77
func (rc *ReplicatedCache) GetWithTTL(ctx context.Context, key any) (any, time.Duration, error) {
×
NEW
78
        // #nosec G404
×
NEW
79
        return rc.readCaches[rand.IntN(len(rc.readCaches))].GetWithTTL(ctx, key)
×
UNCOV
80
}
×
81

82
// Invalidate master cache entries for given options.
83
func (rc *ReplicatedCache) Invalidate(ctx context.Context, options ...store.InvalidateOption) error {
2✔
84
        return rc.masterCache.Invalidate(ctx, options...)
2✔
85
}
2✔
86

87
// Delete from master cache.
88
func (rc *ReplicatedCache) Delete(ctx context.Context, key any) error {
×
89
        return rc.masterCache.Delete(ctx, key)
×
90
}
×
91

92
// Clear master cache.
93
func (rc *ReplicatedCache) Clear(ctx context.Context) error {
2✔
94
        return rc.masterCache.Clear(ctx)
2✔
95
}
2✔
96

97
// GetType returns cache type name.
98
func (rc *ReplicatedCache) GetType() string {
×
99
        return ReplicatedCacheType
×
100
}
×
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