summaryrefslogtreecommitdiff
path: root/plugins/kv/interface.go
blob: 3512fd73998d05a256298ea945d0053ea6e2717e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package kv

// Item represents general storage item
import (
	"context"
)

type Item struct {
	// Key of item
	Key string
	// Value of item
	Value string
	// live until time provided by TTL in RFC 3339 format
	TTL string
}

// Storage represents single abstract storage.
type Storage interface {
	// Has checks if value exists.
	Has(ctx context.Context, keys ...string) (map[string]bool, error)

	// Get loads value content into a byte slice.
	Get(ctx context.Context, key string) ([]byte, error)

	// MGet loads content of multiple values
	// If there are no values for keys, key will no be in the map
	MGet(ctx context.Context, keys ...string) (map[string]interface{}, error)

	// Set used to upload item to KV with TTL
	// 0 value in TTL means no TTL
	Set(ctx context.Context, items ...Item) error

	// MExpire sets the TTL for multiply keys
	MExpire(ctx context.Context, items ...Item) error

	// TTL return the rest time to live for provided keys
	// Not supported for the memcached and boltdb
	TTL(ctx context.Context, keys ...string) (map[string]interface{}, error)

	// Delete one or multiple keys.
	Delete(ctx context.Context, keys ...string) error

	// Close closes the storage and underlying resources.
	Close() error
}