Documentation ¶
Index ¶
- Constants
- Variables
- func IsReservedKey(key string) bool
- func IsValidBucket(bucket string) bool
- func IsValidKey(key string) bool
- type Codec
- type Decoder
- type Encoder
- type Entrydeprecated
- type GenericEntry
- type KVdeprecated
- type Logger
- type Operation
- type Option
- func WithCodec(c Codec) Option
- func WithDecoder(d Decoder) Option
- func WithEncoder(e Encoder) Option
- func WithHistory(h uint64) Option
- func WithLocalCache() Option
- func WithLogger(log Logger) Option
- func WithMaxBucketSize(s int64) Option
- func WithMaxValueSize(s int32) Option
- func WithMirroredBucket(b string) Option
- func WithPlacementCluster(c string) Option
- func WithReplicas(r uint) Option
- func WithStreamName(n string) Option
- func WithStreamSubjectPrefix(p string) Option
- func WithTTL(ttl time.Duration) Option
- func WithTimeout(t time.Duration) Option
- type PutOption
- type RoKVdeprecated
- type Status
- type Storagedeprecated
- type Watchdeprecated
Constants ¶
const ( // PutOperation represents a PUT of data into the kv bucket PutOperation Operation = "PUT" // DeleteOperation represents a delete of a specific key in a bucket DeleteOperation Operation = "DEL" // ValidKeyPattern is a regular expression key should match, post encoding, to be valid ValidKeyPattern = `\A[-/_=\.a-zA-Z0-9]+\z` // ValidBucketPattern is a regular expression bucket names should match ValidBucketPattern = `\A[a-zA-Z0-9_-]+\z` // ReservedKeyPrefix is a prefix for keys reserved for internal use ReservedKeyPrefix = "_kv" )
const ( // DefaultTimeout is the default timeout used when waiting for the backend, override using WithTimeout() DefaultTimeout = 2 * time.Second // DefaultHistory is how many historical values are kept per key DefaultHistory uint64 = 1 // DefaultMaxBucketSize maximum size for the entire bucket, -1 for unlimited DefaultMaxBucketSize int64 = -1 // DefaultMaxValueSize maximum size for individual values DefaultMaxValueSize int32 = -1 )
Variables ¶
var ( // ErrUnknownKey is returned when a key does not exist ErrUnknownKey = errors.New("unknown key") // ErrInvalidKey is returned for keys that do not match ValidKeyPattern ErrInvalidKey = errors.New("invalid key") // ErrInvalidBucketName is returned when trying to access buckets that do not match ValidBucketPattern ErrInvalidBucketName = errors.New("invalid bucket name") // ErrUnknownBucket is returned when a bucket could not be found ErrUnknownBucket = errors.New("unknown bucket") )
Functions ¶
func IsReservedKey ¶
IsReservedKey determines if key is a reserved key
func IsValidBucket ¶
IsValidBucket determines if bucket is a valid bucket name
Types ¶
type Entry
deprecated
type Entry interface { // Bucket is the bucket the data was loaded from Bucket() string // Key is the key that was retrieved Key() string // Value is the retrieved value Value() []byte // Created is the time the data was received in the bucket Created() time.Time // Sequence is a unique sequence for this value Sequence() uint64 // Delta is distance from the latest value. If history is enabled this is effectively the index of the historical value, 0 for latest, 1 for most recent etc. Delta() uint64 // Operation is the kind of operation this result represents Operation() Operation }
Deprecated: this is now deprecated, please use the KV feature in nats.go
type GenericEntry ¶
type GenericEntry struct { Bucket string `json:"bucket"` Key string `json:"key"` Val []byte `json:"val"` Created int64 `json:"created"` Seq uint64 `json:"seq"` Operation string `json:"operation"` }
GenericEntry is a generic, non implementation specific, representation of a Entry
type KV
deprecated
type KV interface { // Put saves a value into a key Put(key string, val []byte, opts ...PutOption) (seq uint64, err error) // Delete marks the key as deleted, history is retained subject to configured history limit Delete(key string) error // Purge marks the key as deleted and removes history, after this operation 1 historic value is kept - the purge Purge(key string) error // Destroy removes the entire bucket and all data, KV cannot be used after Destroy() error RoKV }
KV is a read-write interface to a single key-value store bucket
Deprecated: this is now deprecated, please use the KV feature in nats.go
type Logger ¶
type Logger interface { Debugf(format string, a ...interface{}) Infof(format string, a ...interface{}) Warnf(format string, a ...interface{}) Errorf(format string, a ...interface{}) }
Logger is a custom logger
type Option ¶
type Option func(o *options) error
Option configures the KV client
func WithCodec ¶
WithCodec sets a value encode/decoder, multiple codecs can be set and will be called in order, programs that read and write values can set this to do bi-directional encoding and decoding
func WithDecoder ¶
WithDecoder sets a value decoder, multiple decoders can be set and will be called in order, programs that just read values can use this to avoid the configuring encoders
func WithEncoder ¶
WithEncoder sets a value encoder, multiple encoders can be set and will be called in order, programs that just write values can use this to avoid the configuring decoders
func WithHistory ¶
WithHistory sets the number of historic values to keep for a key
func WithLocalCache ¶
func WithLocalCache() Option
WithLocalCache creates a local in-memory cache of the entire bucket that's kept up to date in real time using a watch
func WithLogger ¶
WithLogger sets a logger to use, STDOUT logging otherwise
func WithMaxBucketSize ¶
WithMaxBucketSize limits the entire bucket to a specific size
func WithMaxValueSize ¶
WithMaxValueSize is the biggest size value that can be placed in the bucket including some header overhead
func WithMirroredBucket ¶
WithMirroredBucket creates a read replica that mirrors a specified bucket
func WithPlacementCluster ¶
WithPlacementCluster places the bucket in a specific cluster
func WithReplicas ¶
WithReplicas sets the number of replicas to keep for a bucket
func WithStreamName ¶
WithStreamName overrides the usual stream name that is formed as KV_<BUCKET>
func WithStreamSubjectPrefix ¶
WithStreamSubjectPrefix overrides the usual stream subject changing the `kv.*.*` to `<prefix>.*.*`
func WithTimeout ¶
WithTimeout sets the timeout for calls to the storage layer
type PutOption ¶
type PutOption func(o *putOptions)
PutOption is a option passed to put, reserved for future work like put only if last value had sequence x
func OnlyIfLastValueSequence ¶
OnlyIfLastValueSequence the put will only succeed if the last set value for the key had this sequence
type RoKV
deprecated
type RoKV interface { // Get gets a key from the store Get(key string) (Entry, error) // History retrieves historic values for a key History(ctx context.Context, key string) ([]Entry, error) // Watch a key for updates, the same Entry might be delivered more than once, a nil entry means end of available data was reached Watch(ctx context.Context, key string) (Watch, error) // Close releases in-memory resources held by the KV, called automatically if the context used to create it is canceled Close() error // Status retrieves the status of the bucket Status() (Status, error) }
RoKV is a read-only interface to a single key-value store bucket
Deprecated: this is now deprecated, please use the KV feature in nats.go
func NewRoClient
deprecated
type Status ¶
type Status interface { // Bucket the name of the bucket Bucket() string // Values is how many messages are in the bucket, including historical values Values() uint64 // History returns the configured history kept per key History() int64 // TTL is how long the bucket keeps values for TTL() time.Duration // BucketLocation returns the name of the cluster holding the read replica of the data BucketLocation() string // Replicas returns how many times data in the bucket is replicated at storage Replicas() (ok int, failed int) // Keys returns a list of all keys in the bucket - not possible now Keys() ([]string, error) // BackingStore is a backend specific name for the underlying storage - eg. stream name BackingStore() string // MirrorStatus is the status of a read replica, error when not accessing a replica MirrorStatus() (lag int64, active bool, err error) // MaxBucketSize is the configured maximum size of the bucket in bytes MaxBucketSize() int64 // MaxValueSize is the configured maximum size of a single value in bytes MaxValueSize() int32 }
type Watch
deprecated
type Watch interface { // Channel returns a channel to read changes from Channel() chan Entry // Close must be called to dispose of resources, called if the context used to create the watch is canceled Close() error }
Watch observes a bucket and report any changes via NextValue or Channel
Deprecated: this is now deprecated, please use the KV feature in nats.go