storage_interface.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package fiber
  2. import (
  3. "context"
  4. "time"
  5. )
  6. // Storage interface for communicating with different database/key-value
  7. // providers
  8. type Storage interface {
  9. // GetWithContext gets the value for the given key with a context.
  10. // `nil, nil` is returned when the key does not exist
  11. GetWithContext(ctx context.Context, key string) ([]byte, error)
  12. // Get gets the value for the given key.
  13. // `nil, nil` is returned when the key does not exist
  14. Get(key string) ([]byte, error)
  15. // SetWithContext stores the given value for the given key
  16. // with an expiration value, 0 means no expiration.
  17. // Empty key or value will be ignored without an error.
  18. SetWithContext(ctx context.Context, key string, val []byte, exp time.Duration) error
  19. // Set stores the given value for the given key along
  20. // with an expiration value, 0 means no expiration.
  21. // Empty key or value will be ignored without an error.
  22. Set(key string, val []byte, exp time.Duration) error
  23. // DeleteWithContext deletes the value for the given key with a context.
  24. // It returns no error if the storage does not contain the key,
  25. DeleteWithContext(ctx context.Context, key string) error
  26. // Delete deletes the value for the given key.
  27. // It returns no error if the storage does not contain the key,
  28. Delete(key string) error
  29. // ResetWithContext resets the storage and deletes all keys with a context.
  30. ResetWithContext(ctx context.Context) error
  31. // Reset resets the storage and delete all keys.
  32. Reset() error
  33. // Close closes the storage and will stop any running garbage
  34. // collectors and open connections.
  35. Close() error
  36. }