redis

package
v0.0.0-...-06bcc1c Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMaxRetryExceeded indicates redis transaction failed after all the retries
	ErrMaxRetryExceeded = errors.New("[Redis transaction] Max retry exceeded")
	// ErrAlreadyExists indicates the key already exists when do redis SETNX
	ErrAlreadyExists = errors.New("[Redis setnx] Already exists")
	// ErrBadCmdType indicates command type is not correct
	// e.g. SET should be StringCmd
	ErrBadCmdType = errors.New("[Redis cmd] Bad cmd type")
	// ErrKeyNotExitsts indicates no key found
	// When do update, we need to ensure the key exists, just like the behavior of etcd client
	ErrKeyNotExitsts = errors.New("[Redis exists] Key not exists")
)

Functions

This section is empty.

Types

type KNotifyMessage

type KNotifyMessage struct {
	Key    string
	Action string
}

KNotifyMessage is received when using KNotify

type Rediaron

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

Rediaron is a store implemented by redis

func New

func New(config types.Config, _ *testing.T) (*Rediaron, error)

New creates a new Rediaron instance from config Only redis address and db is used db is used to separate data, by default db 0 will be used TODO mock redis for testing

func (*Rediaron) AddNode

func (r *Rediaron) AddNode(ctx context.Context, opts *types.AddNodeOptions) (*types.Node, error)

AddNode save it to etcd storage path in etcd is `/pod/nodes/:podname/:nodename` node->pod path in etcd is `/node/pod/:nodename` func (m *Rediaron) AddNode(ctx context.Context, name, endpoint, podname, ca, cert, key string, cpu, share int, memory, storage int64, labels map[string]string, numa types.NUMA, numaMemory types.NUMAMemory, volume types.VolumeMap) (*types.Node, error) {

func (*Rediaron) AddPod

func (r *Rediaron) AddPod(ctx context.Context, name, desc string) (*types.Pod, error)

AddPod adds a pod to core

func (*Rediaron) AddWorkload

func (r *Rediaron) AddWorkload(ctx context.Context, workload *types.Workload, processing *types.Processing) error

AddWorkload add a workload mainly record its relationship on pod and node actually if we already know its node, we will know its pod but we still store it storage path in etcd is `/workload/:workloadid`

func (*Rediaron) BatchCreate

func (r *Rediaron) BatchCreate(ctx context.Context, data map[string]string) error

BatchCreate is wrapper to adapt etcd batch create

func (*Rediaron) BatchCreateAndDecr

func (r *Rediaron) BatchCreateAndDecr(ctx context.Context, data map[string]string, decrKey string) (err error)

BatchCreateAndDecr decr processing and add workload

func (*Rediaron) BatchDelete

func (r *Rediaron) BatchDelete(ctx context.Context, keys []string) error

BatchDelete is wrapper to adapt etcd batch delete

func (*Rediaron) BatchPut

func (r *Rediaron) BatchPut(ctx context.Context, data map[string]string) error

BatchPut is wrapper to adapt etcd batch replace

func (*Rediaron) BatchUpdate

func (r *Rediaron) BatchUpdate(ctx context.Context, data map[string]string) error

BatchUpdate is wrapper to adapt etcd batch update

func (*Rediaron) BindStatus

func (r *Rediaron) BindStatus(ctx context.Context, entityKey, statusKey, statusValue string, ttl int64) error

BindStatus is wrapper to adapt etcd bind status

func (*Rediaron) CreateLock

func (r *Rediaron) CreateLock(key string, ttl time.Duration) (lock.DistributedLock, error)

CreateLock creates a redis based lock

func (*Rediaron) CreateProcessing

func (r *Rediaron) CreateProcessing(ctx context.Context, processing *types.Processing, count int) error

CreateProcessing save processing status in etcd

func (*Rediaron) DeleteProcessing

func (r *Rediaron) DeleteProcessing(ctx context.Context, processing *types.Processing) error

DeleteProcessing delete processing status in etcd

func (*Rediaron) GetAllPods

func (r *Rediaron) GetAllPods(ctx context.Context) ([]*types.Pod, error)

GetAllPods list all pods in core

func (*Rediaron) GetDeployStatus

func (r *Rediaron) GetDeployStatus(ctx context.Context, appname, entryname string) (map[string]int, error)

GetDeployStatus .

func (*Rediaron) GetMulti

func (r *Rediaron) GetMulti(ctx context.Context, keys []string) (map[string]string, error)

GetMulti is a wrapper

func (*Rediaron) GetNode

func (r *Rediaron) GetNode(ctx context.Context, nodename string) (*types.Node, error)

GetNode get node by name

func (*Rediaron) GetNodeStatus

func (r *Rediaron) GetNodeStatus(ctx context.Context, nodename string) (*types.NodeStatus, error)

GetNodeStatus returns status for a node

func (*Rediaron) GetNodes

func (r *Rediaron) GetNodes(ctx context.Context, nodenames []string) ([]*types.Node, error)

GetNodes get nodes

func (*Rediaron) GetNodesByPod

func (r *Rediaron) GetNodesByPod(ctx context.Context, nodeFilter *types.NodeFilter, opts ...store.Option) ([]*types.Node, error)

GetNodesByPod get all nodes bound to pod here we use podname instead of pod instance

func (*Rediaron) GetOne

func (r *Rediaron) GetOne(ctx context.Context, key string) (string, error)

GetOne is a wrapper

func (*Rediaron) GetPod

func (r *Rediaron) GetPod(ctx context.Context, name string) (*types.Pod, error)

GetPod gets a pod by name

func (*Rediaron) GetWorkload

func (r *Rediaron) GetWorkload(ctx context.Context, ID string) (*types.Workload, error)

GetWorkload get a workload workload if must be in full length, or we can't find it in etcd storage path in etcd is `/workload/:workloadid`

func (*Rediaron) GetWorkloadStatus

func (r *Rediaron) GetWorkloadStatus(ctx context.Context, ID string) (*types.StatusMeta, error)

GetWorkloadStatus get workload status

func (*Rediaron) GetWorkloads

func (r *Rediaron) GetWorkloads(ctx context.Context, IDs []string) (workloads []*types.Workload, err error)

GetWorkloads get many workloads

func (*Rediaron) KNotify

func (r *Rediaron) KNotify(ctx context.Context, pattern string) chan *KNotifyMessage

KNotify is like `watch` in etcd knotify comes from inotify, when a key is changed, notification will be published

func (*Rediaron) ListNodeWorkloads

func (r *Rediaron) ListNodeWorkloads(ctx context.Context, nodename string, labels map[string]string) ([]*types.Workload, error)

ListNodeWorkloads list workloads belong to one node

func (*Rediaron) ListWorkloads

func (r *Rediaron) ListWorkloads(ctx context.Context, appname, entrypoint, nodename string, limit int64, labels map[string]string) ([]*types.Workload, error)

ListWorkloads list workloads

func (*Rediaron) LoadNodeCert

func (r *Rediaron) LoadNodeCert(ctx context.Context, node *types.Node) (err error)

func (*Rediaron) NodeStatusStream

func (r *Rediaron) NodeStatusStream(ctx context.Context) chan *types.NodeStatus

NodeStatusStream returns a stream of node status it tells you if status of a node is changed, either PUT or DELETE PUT -> Alive: true DELETE -> Alive: false

func (*Rediaron) RegisterService

func (r *Rediaron) RegisterService(ctx context.Context, serviceAddress string, expire time.Duration) (<-chan struct{}, func(), error)

RegisterService put /services/{address}

func (*Rediaron) RemoveNode

func (r *Rediaron) RemoveNode(ctx context.Context, node *types.Node) error

RemoveNode delete a node

func (*Rediaron) RemovePod

func (r *Rediaron) RemovePod(ctx context.Context, podname string) error

RemovePod removes a pod by name

func (*Rediaron) RemoveWorkload

func (r *Rediaron) RemoveWorkload(ctx context.Context, workload *types.Workload) error

RemoveWorkload remove a workload workload ID must be in full length

func (*Rediaron) ServiceStatusStream

func (r *Rediaron) ServiceStatusStream(ctx context.Context) (chan []string, error)

ServiceStatusStream watches /services/ --prefix

func (*Rediaron) SetNodeStatus

func (r *Rediaron) SetNodeStatus(ctx context.Context, node *types.Node, ttl int64) error

SetNodeStatus sets status for a node, value will expire after ttl seconds ttl < 0 means delete node status this is heartbeat of node

func (*Rediaron) SetWorkloadStatus

func (r *Rediaron) SetWorkloadStatus(ctx context.Context, status *types.StatusMeta, ttl int64) error

SetWorkloadStatus set workload status

func (*Rediaron) StartEphemeral

func (r *Rediaron) StartEphemeral(ctx context.Context, path string, heartbeat time.Duration) (<-chan struct{}, func(), error)

StartEphemeral starts an empheral kv pair.

func (*Rediaron) TerminateEmbededStorage

func (r *Rediaron) TerminateEmbededStorage()

TerminateEmbededStorage terminates embedded store in order to implement Store interface we can't use embedded redis, it doesn't support keyspace notification never call this except running unittests

func (*Rediaron) UpdateNodes

func (r *Rediaron) UpdateNodes(ctx context.Context, nodes ...*types.Node) error

UpdateNodes .

func (*Rediaron) UpdateWorkload

func (r *Rediaron) UpdateWorkload(ctx context.Context, workload *types.Workload) error

UpdateWorkload update a workload

func (*Rediaron) WorkloadStatusStream

func (r *Rediaron) WorkloadStatusStream(ctx context.Context, appname, entrypoint, nodename string, labels map[string]string) chan *types.WorkloadStatus

WorkloadStatusStream watch deployed status

Jump to

Keyboard shortcuts

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