CountLooseRefs counts the number of references stored in Redis.
()
| 111 | |
| 112 | // CountLooseRefs counts the number of references stored in Redis. |
| 113 | func (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. |
| 138 | func (s *ReferenceStorage) RemoveReference(ref plumbing.ReferenceName) error { |
nothing calls this directly
no test coverage detected