github.com/influx6/npkg@v0.8.8/nstorage/nstorage.go (about)

     1  package nstorage
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/influx6/npkg/nerror"
     7  )
     8  
     9  // ErrJustStop can be used to inform the iterator to just stop
    10  var ErrJustStop = nerror.New("stop iterator")
    11  
    12  type EachItem func([]byte, string) error
    13  
    14  type ScanResult struct {
    15  	Finished  bool
    16  	LastIndex int64
    17  	LastKey   string
    18  	Keys      []string
    19  }
    20  
    21  // ByteStore defines a storage interface defining what we expect to
    22  // be provided for storing a byte slice with a underline key.
    23  type ByteStore interface {
    24  	Each(fn EachItem) error
    25  	EachKeyMatch(regexp string) ([]string, error)
    26  	ScanMatch(count int64, lastIndex int64, lastKey string, regexp string) (ScanResult, error)
    27  
    28  	Count() (int64, error)
    29  	Keys() ([]string, error)
    30  	Save(string, []byte) error
    31  	Exists(string) (bool, error)
    32  	Update(string, []byte) error
    33  
    34  	RemoveKeys(...string) error
    35  	Remove(string) ([]byte, error)
    36  
    37  	Get(string) ([]byte, error)
    38  	GetAllKeys(...string) ([][]byte, error)
    39  	GetAnyKeys(...string) ([][]byte, error)
    40  }
    41  
    42  // ExpirableStore composes the ByteStore providing the
    43  // expiration versions of Save and TTL extension.
    44  type ExpirableStore interface {
    45  	ByteStore
    46  
    47  	// TTL should return current expiration value of
    48  	// giving key in millisecond.
    49  	TTL(string) (time.Duration, error)
    50  
    51  	// ExtendTTL should extend expiration by giving duration,
    52  	// by add new duration to the remaining ttl of key.
    53  	//
    54  	// A zero value should persist key.
    55  	ExtendTTL(string, time.Duration) error
    56  
    57  	// ResetTTL should extend reset to giving duration.
    58  	//
    59  	// A zero value should persist key.
    60  	ResetTTL(string, time.Duration) error
    61  
    62  	// SaveTTL save giving key with giving expiration.
    63  	SaveTTL(string, []byte, time.Duration) error
    64  
    65  	// UpdateTTL updates giving key with giving value and use new expiration.
    66  	// It should update key's value and add giving duration
    67  	// to remaining time of key.
    68  	//
    69  	// A zero value should persist key.
    70  	UpdateTTL(string, []byte, time.Duration) error
    71  }