db

package
v0.0.0-...-0bad168 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KEY_ALL_CLIENTS        = "all_clients"
	KEY_CLIENT_PREFIX      = "client:"
	KEY_CLIENT_KEY_PREFIX  = "client_key:"
	KEY_CLIENT_KEYS_PREFIX = "client_keys:"
)

Variables

View Source
var PROTO_CODEC = ProtoCodec{}

Functions

This section is empty.

Types

type ClientsRepository

type ClientsRepository interface {
	GetAllClients(ctx context.Context) ([]*asit.Client, error)
	GetClientById(ctx context.Context, id string) (*asit.Client, error)
	SetClient(ctx context.Context, client *asit.Client) error
	RemoveClient(ctx context.Context, clientId string) error

	GetClientKeys(ctx context.Context, clientId string) (*asit.ClientKeys, error)
	AddClientKey(ctx context.Context, clientId string, key string) error
	GetClientByKey(ctx context.Context, key string) (*asit.Client, error)
	RemoveClientKey(ctx context.Context, key string) error
}

type KVClientsRepository

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

func NewKVClientsRepository

func NewKVClientsRepository(store Storage) *KVClientsRepository

func (*KVClientsRepository) AddClientKey

func (r *KVClientsRepository) AddClientKey(ctx context.Context, clientId string, key string) error

func (*KVClientsRepository) GetAllClients

func (r *KVClientsRepository) GetAllClients(ctx context.Context) ([]*asit.Client, error)

func (*KVClientsRepository) GetClientById

func (r *KVClientsRepository) GetClientById(ctx context.Context, id string) (*asit.Client, error)

func (*KVClientsRepository) GetClientByKey

func (r *KVClientsRepository) GetClientByKey(ctx context.Context, key string) (*asit.Client, error)

func (*KVClientsRepository) GetClientKeys

func (r *KVClientsRepository) GetClientKeys(ctx context.Context, clientId string) (*asit.ClientKeys, error)

func (*KVClientsRepository) RemoveClient

func (r *KVClientsRepository) RemoveClient(ctx context.Context, clientId string) error

func (*KVClientsRepository) RemoveClientKey

func (r *KVClientsRepository) RemoveClientKey(ctx context.Context, key string) error

func (*KVClientsRepository) SetClient

func (r *KVClientsRepository) SetClient(ctx context.Context, client *asit.Client) error

type NonUniqueClientKeyError

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

func (*NonUniqueClientKeyError) Error

func (e *NonUniqueClientKeyError) Error() string

type NotFoundClientByIdError

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

func (*NotFoundClientByIdError) Error

func (e *NotFoundClientByIdError) Error() string

type ProtoCodec

type ProtoCodec struct{}

func (ProtoCodec) Marshal

func (c ProtoCodec) Marshal(v proto.Message) ([]byte, error)

func (ProtoCodec) Unmarshal

func (c ProtoCodec) Unmarshal(data []byte, v proto.Message) error

Unmarshal decodes a gob value into a Go value.

type RedisStorage

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

func NewRedisStorage

func NewRedisStorage(client redis.UniversalClient, codec StorageCodec) *RedisStorage

func (*RedisStorage) Close

func (s *RedisStorage) Close() error

func (*RedisStorage) Delete

func (s *RedisStorage) Delete(ctx context.Context, k ...string) error

func (*RedisStorage) Get

func (s *RedisStorage) Get(ctx context.Context, k string, v proto.Message) (found bool, err error)

func (*RedisStorage) Set

func (s *RedisStorage) Set(ctx context.Context, k string, v proto.Message) error

func (*RedisStorage) SetAndDeleteAtomically

func (s *RedisStorage) SetAndDeleteAtomically(ctx context.Context, lockedSets []SetValueCommand, lockedDeleteKeys []string, unlockedSets func() []SetValueUnlockedCommand, unlockedDeleteKeys func() []string) error

type SetValueCommand

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

Storage is an abstraction for different key-value store implementations. A store must be able to store, retrieve and delete key-value pairs, with the key being a string and the value being any Go interface{}.

type SetValueUnlockedCommand

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

type Storage

type Storage interface {
	// Set stores the given value for the given key.
	// The implementation automatically marshalls the value.
	// The marshalling format depends on the implementation. It can be JSON, gob etc.
	// The key must not be "" and the value must not be nil.
	Set(ctx context.Context, k string, v proto.Message) error

	// Updates multiple values specified by SetValueCommand, deleteKeys and afterRemovalKeysSupplier atomically
	// Deletes keys sepcified in deleteKeys
	// If keys used lockedSets and lockedDeleteKeys not changed during update, rocesses all commands provided by the unlockedSets func
	// Not that unlockedSets will be processed even if values with the same keys changed/set/removed during the lockedSets, lockedDeleteKeys processing
	SetAndDeleteAtomically(ctx context.Context, lockedSets []SetValueCommand, lockedDeleteKeys []string, unlockedSets func() []SetValueUnlockedCommand, unlockedDeleteKeys func() []string) error

	// Get retrieves the value for the given key.
	// The implementation automatically unmarshalls the value.
	// The unmarshalling source depends on the implementation. It can be JSON, gob etc.
	// The automatic unmarshalling requires a pointer to an object of the correct type
	// being passed as parameter.
	// In case of a struct the Get method will populate the fields of the object
	// that the passed pointer points to with the values of the retrieved object's values.
	// If no value is found it returns (false, nil).
	// The key must not be "" and the pointer must not be nil.
	Get(ctx context.Context, k string, v proto.Message) (found bool, err error)

	// Delete deletes the stored value for the given key.
	// Deleting a non-existing key-value pair does NOT lead to an error.
	// The key must not be "".
	Delete(ctx context.Context, k ...string) error

	// Close must be called when the work with the key-value store is done.
	// Most (if not all) implementations are meant to be used long-lived,
	// so only call Close() at the very end.
	// Depending on the store implementation it might do one or more of the following:
	// Make sure all pending updates make their way to disk,
	// finish open transactions,
	// close the file handle to an embedded DB,
	// close the connection to the DB server,
	// release any open resources,
	// etc.
	// Some implementUniversalation might not need the store to be closed,
	// but as long as you work with the gokv.Store interface you never know which implementation
	// is passed to your method, so you should always call it.
	Close() error
}

type StorageCodec

type StorageCodec interface {
	Marshal(v proto.Message) ([]byte, error)
	Unmarshal(data []byte, v proto.Message) error
}

Jump to

Keyboard shortcuts

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