Documentation ¶
Index ¶
- Constants
- func CompressS2(data []byte) []byte
- func CompressSnappy(data []byte) []byte
- func DecodeData[T any](data []byte) (*T, error)
- func DecompressS2(data []byte) ([]byte, error)
- func DecompressSnappy(data []byte) ([]byte, error)
- func EncodeData[T any](data T) ([]byte, error)
- type Config
- type Datastore
- type RedisDatastoreConfig
Constants ¶
View Source
const ( // DefaultTtl is the default time-to-live for all datastore implementations DefaultTtl = (8 * time.Hour) + (30 * time.Minute) // DefaultKeyPrefix is the key prefix used by datastore implementations // when one is not manually configured. DefaultKeyPrefix = "lavamonster" )
Variables ¶
This section is empty.
Functions ¶
func CompressS2 ¶
CompressS2 compresses a byte slice using S2, an "improved" Snappy algorithm.
func CompressSnappy ¶
CompressSnappy compresses a byte slice using standard Snappy compression.
func DecodeData ¶
DecodeData decodes gob-encoded bytes, returning the original data.
func DecompressS2 ¶
DecompressS2 decompresses bytes which were compressed using the S2 Snappy algorithm.
func DecompressSnappy ¶
DecompressSnappy decompresses bytes which were compressed using standard Snappy compression.
func EncodeData ¶
EncodeData encodes arbitrary data using encoding/gob, returning the byte-encoded result of gob.Encode.
Types ¶
type Config ¶
type Config struct { KeyPrefix *string `json:"key_prefix,omitempty" yaml:"key_prefix,omitempty" toml:"KeyPrefix,omitempty"` DefaultTtl *time.Duration `json:"default_ttl,omitempty" yaml:"default_ttl,omitempty" toml:"DefaultTtl,omitempty"` Redis *RedisDatastoreConfig `json:"redis,omitempty" yaml:"redis,omitempty" toml:"Redis,omitempty"` }
type Datastore ¶
type Datastore[T any] interface { // Exists checks if a key currently exists in the datastore. // Should return true if the key exists, false otherwise. // If the underlying datastore implementation returns an error // when checking key existence, Exists should return `false` and the // aforementioned error. Exists(ctx context.Context, key string) (bool, error) // CheckTtl returns the remaining time-to-live of data in the datastore // for the passed key. // If no data is set to the passed key, the zero-value of time.Duration is // returned, as well as false. // If the underlying datastore implementation returns an error, // that error will be returned. CheckTtl(ctx context.Context, key string) (time.Duration, bool, error) // Get returns the data which is stored with the passed key, // as well as a boolean representing whether the key exists // in the datastore at all. Get(ctx context.Context, key string) (*T, bool, error) // Insert inserts data using a given key into the datastore, // returning any error returned by the underlying datastore implementation. Insert(ctx context.Context, key string, data T) error // Delete removes a given key from the datastore, returning any error // returned by the underlying datastore implementation. // Note that this is a "blind" delete: if the passed key does not exist, // no error is returned, and no data is otherwise modified. Delete(ctx context.Context, key string) error // UpdateTtl sets the time-to-live for an object in the datastore which // is stored at the passed key. // If the passed key is unset, false is returned; otherwise, true is returned. UpdateTtl(ctx context.Context, key string, newTtl time.Duration) (bool, error) // DefaultTtl returns the time-to-live value used by default by the datastore // when storing new data. DefaultTtl() time.Duration // SetDefaultTtl sets the default time-to-live used by the datastore // when storing new data. SetDefaultTtl(newTtl time.Duration) // KeyPrefix returns the configured key prefixed used by the datastore. // Key prefixing should be used by all Datastore implementations // to ensure data consistency. KeyPrefix() string // SetKeyPrefix sets the key prefix used by the datastore // when storing new data. // Note that setting a new key prefix will *NOT* update previously stored // keys, essentially making data using the old key prefix inaccessible // to the datastore. SetKeyPrefix(newPrefix string) }
func NewRedisDatastore ¶
NewRedisDatastore wraps NewRedisDatastoreContext, passing a new context.Background() context.
type RedisDatastoreConfig ¶
type RedisDatastoreConfig struct { Host *string `json:"host,omitempty" yaml:"host,omitempty" toml:"Host,omitempty"` Port *int `json:"port,omitempty" yaml:"port,omitempty" toml:"Port,omitempty"` Password *string `json:"password,omitempty" yaml:"password,omitempty" toml:"Password,omitempty"` Prefix *string `json:"prefix,omitempty" yaml:"prefix,omitempty" toml:"Prefix,omitempty"` DefaultTtl *time.Duration `json:"default_ttl,omitempty" yaml:"default_ttl,omitempty" toml:"DefaultTTL,omitempty"` }
Click to show internal directories.
Click to hide internal directories.