Keys returns all keys stored in the memory storage.
()
| 214 | |
| 215 | // Keys returns all keys stored in the memory storage. |
| 216 | func (s *Storage) Keys() ([][]byte, error) { |
| 217 | s.mux.RLock() |
| 218 | defer s.mux.RUnlock() |
| 219 | |
| 220 | if len(s.db) == 0 { |
| 221 | return nil, nil |
| 222 | } |
| 223 | |
| 224 | ts := utils.Timestamp() |
| 225 | keys := make([][]byte, 0, len(s.db)) |
| 226 | for key, v := range s.db { |
| 227 | // Filter out the expired keys |
| 228 | if v.expiry == 0 || v.expiry > ts { |
| 229 | keys = append(keys, []byte(key)) |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | // Double check if no valid keys were found |
| 234 | if len(keys) == 0 { |
| 235 | return nil, nil |
| 236 | } |
| 237 | |
| 238 | return keys, nil |
| 239 | } |
| 240 | |
| 241 | func wrapContextError(ctx context.Context, op string) error { |
| 242 | if err := ctx.Err(); err != nil { |
no outgoing calls