redis

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package redis contains the Redis store implementation.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMultipleEndpointsUnsupported is thrown when there are
	// multiple endpoints specified for Redis.
	ErrMultipleEndpointsUnsupported = errors.New("redis: does not support multiple endpoints")

	// ErrTLSUnsupported is thrown when tls config is given.
	ErrTLSUnsupported = errors.New("redis does not support tls")

	// ErrAbortTryLock is thrown when a user stops trying to seek the lock
	// by sending a signal to the stop chan,
	// this is used to verify if the operation succeeded.
	ErrAbortTryLock = errors.New("redis: lock operation aborted")
)

Functions

func New

func New(endpoints []string, options *store.Config) (store.Store, error)

New creates a new Redis client given a list of endpoints and optional tls config.

func Register

func Register()

Register registers Redis to kvdb.

Types

type Codec

type Codec interface {
	Encode(kv *store.KVPair) (string, error)
	Decode(b []byte, kv *store.KVPair) error
}

Codec KVPair persistence interface.

type JSONCodec

type JSONCodec struct{}

JSONCodec is a simple codec to read and write valkeyrie JSON object.

func (JSONCodec) Decode

func (c JSONCodec) Decode(b []byte, kv *store.KVPair) error

Decode a byte slice of valkeyrie JSON object to a KVPair.

func (JSONCodec) Encode

func (c JSONCodec) Encode(kv *store.KVPair) (string, error)

Encode a KVPair to a valkeyrie JSON object.

type RawCodec

type RawCodec struct{}

RawCodec is a simple codec to read and write string.

func (RawCodec) Decode

func (c RawCodec) Decode(b []byte, kv *store.KVPair) error

Decode a byte slice to a KVPair.

func (RawCodec) Encode

func (c RawCodec) Encode(kv *store.KVPair) (string, error)

Encode a KVPair to a string.

type Redis

type Redis struct {
	// contains filtered or unexported fields
}

Redis implements kvdb.Store interface with redis backend.

func (*Redis) AtomicDelete

func (r *Redis) AtomicDelete(ctx context.Context, key string, previous *store.KVPair) (bool, error)

AtomicDelete is an atomic delete operation on a single value the value will be deleted if previous matched the one stored in db.

func (*Redis) AtomicPut

func (r *Redis) AtomicPut(ctx context.Context, key string, value []byte, previous *store.KVPair, options *store.WriteOptions) (bool, *store.KVPair, error)

AtomicPut is an atomic CAS operation on a single value. Pass previous = nil to create a new key. We introduced script on this page, so atomicity is guaranteed.

func (*Redis) Close

func (r *Redis) Close() error

Close the store connection.

func (*Redis) Delete

func (r *Redis) Delete(ctx context.Context, key string) error

Delete the value at the specified key.

func (*Redis) DeleteTree

func (r *Redis) DeleteTree(ctx context.Context, directory string) error

DeleteTree deletes a range of keys under a given directory. glitch: we list all available keys first and then delete them all it costs two operations on redis, so is not atomicity.

func (*Redis) Exists

func (r *Redis) Exists(ctx context.Context, key string, _ *store.ReadOptions) (bool, error)

Exists verify if a Key exists in the store.

func (*Redis) Get

func (r *Redis) Get(ctx context.Context, key string, _ *store.ReadOptions) (*store.KVPair, error)

Get a value given its key.

func (*Redis) List

func (r *Redis) List(ctx context.Context, directory string, _ *store.ReadOptions) ([]*store.KVPair, error)

List the content of a given prefix.

func (*Redis) NewLock

func (r *Redis) NewLock(_ context.Context, key string, options *store.LockOptions) (store.Locker, error)

NewLock creates a lock for a given key. The returned Locker is not held and must be acquired with `.Lock`. The Value is optional.

func (*Redis) Put

func (r *Redis) Put(ctx context.Context, key string, value []byte, options *store.WriteOptions) error

Put a value at the specified key.

func (*Redis) Watch

func (r *Redis) Watch(ctx context.Context, key string, stopCh <-chan struct{}, _ *store.ReadOptions) (<-chan *store.KVPair, error)

Watch for changes on a key. glitch: we use notified-then-retrieve to retrieve *store.KVPair. so the responses may sometimes inaccurate.

func (*Redis) WatchTree

func (r *Redis) WatchTree(ctx context.Context, directory string, stopCh <-chan struct{}, _ *store.ReadOptions) (<-chan []*store.KVPair, error)

WatchTree watches for changes on child nodes under a given directory.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL