MCPcopy Create free account
hub / github.com/encoder-run/operator / CountLooseRefs

Method CountLooseRefs

pkg/cache/redis/reference.go:113–135  ·  view source on GitHub ↗

CountLooseRefs counts the number of references stored in Redis.

()

Source from the content-addressed store, hash-verified

111
112// CountLooseRefs counts the number of references stored in Redis.
113func (s *ReferenceStorage) CountLooseRefs() (int, error) {
114 var count int
115 var cursor uint64
116 var err error
117
118 // Use the SCAN command to iterate through all keys that match the pattern "ref:*".
119 // We're only interested in counting keys, so we don't need to retrieve their values.
120 for {
121 var keys []string
122 keys, cursor, err = s.client.Scan(ctx, cursor, withNamespace(s.namespacePrefix, referencePrefix, "*"), 0).Result()
123 if err != nil {
124 return 0, err // Return the error if the SCAN command fails.
125 }
126
127 count += len(keys) // Increment the count by the number of keys returned in this batch.
128
129 if cursor == 0 {
130 break // If the cursor returned by SCAN is 0, we've iterated through all keys.
131 }
132 }
133
134 return count, nil
135}
136
137// RemoveReference implements storage.Storer.
138func (s *ReferenceStorage) RemoveReference(ref plumbing.ReferenceName) error {

Callers

nothing calls this directly

Calls 1

withNamespaceFunction · 0.85

Tested by

no test coverage detected