redis

package
Version: v0.0.0-...-dafc56b Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2020 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Overview

Package redis implements a communication interface with the redis server running on the BitBoxBase.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseRedisKey

type BaseRedisKey string

BaseRedisKey is a string representing a Redis key used in the BitBoxBase.

const (
	BaseHostname          BaseRedisKey = "base:hostname"
	TorEnabled            BaseRedisKey = "tor:base:enabled"
	MiddlewareOnion       BaseRedisKey = "tor:bbbmiddleware:onion"
	BitcoindListen        BaseRedisKey = "bitcoind:listen"
	BaseVersion           BaseRedisKey = "base:version"
	BitcoindVersion       BaseRedisKey = "bitcoind:version"
	LightningdVersion     BaseRedisKey = "lightningd:version"
	ElectrsVersion        BaseRedisKey = "electrs:version"
	MiddlewarePasswordSet BaseRedisKey = "middleware:passwordSetup"
	MiddlewareAuth        BaseRedisKey = "middleware:auth"
	BaseSetupDone         BaseRedisKey = "base:setup"
	BaseSSHDPasswordLogin BaseRedisKey = "base:sshd:passwordlogin"
	BitcoindIBDClearnet   BaseRedisKey = "bitcoind:ibd-clearnet"
)

BitBoxBase redis keys for configuration options.

type Client

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

Client is a redis client

func NewClient

func NewClient(port string) (client Client)

NewClient returns a new redis client. It does not ensure that the client has connectivity.

func (Client) AddToSortedSet

func (c Client) AddToSortedSet(key BaseRedisKey, score int, element string) error

AddToSortedSet adds a element to a redis sorted set. The interger score defines the position in the sorted set.

Note: Redis supports double precision for scores, but that's not implemented here yet. Additionally Redis supports multiple insertions in one call. That's not implemented here either.

func (Client) ConvertErrorToErrorResponse

func (c Client) ConvertErrorToErrorResponse(err error) rpcmessages.ErrorResponse

ConvertErrorToErrorResponse converts an error returned by Redis to an ErrorResponse

func (Client) GetBool

func (c Client) GetBool(key BaseRedisKey) (val bool, err error)

GetBool gets a boolean value for a given key. Internally checks if the value for the given key is set to 1. If so, then true is returned, else false.

func (Client) GetInt

func (c Client) GetInt(key BaseRedisKey) (val int, err error)

GetInt gets an integer value for a given key.

func (Client) GetString

func (c Client) GetString(key BaseRedisKey) (val string, err error)

GetString gets a string for a given key.

func (Client) GetTopFromSortedSet

func (c Client) GetTopFromSortedSet(key BaseRedisKey) (string, error)

GetTopFromSortedSet gets the element with the hightest score from a Redis sorted set.

func (Client) RemoveFromSortedSet

func (c Client) RemoveFromSortedSet(key BaseRedisKey, element string) error

RemoveFromSortedSet removes an element from a Redis sorted set if present.

func (Client) SetString

func (c Client) SetString(key BaseRedisKey, value string) error

SetString sets a string for a given key.

type MockClient

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

MockClient is a mock redis client

func NewMockClient

func NewMockClient(port string) (mockClient *MockClient)

NewMockClient returns a new redis client. It does not ensure that the client has connectivity.

func (*MockClient) AddToSortedSet

func (mc *MockClient) AddToSortedSet(key BaseRedisKey, score int, element string) error

AddToSortedSet is a dummy that does nothing but printing the arguments.

func (*MockClient) ConvertErrorToErrorResponse

func (mc *MockClient) ConvertErrorToErrorResponse(err error) rpcmessages.ErrorResponse

ConvertErrorToErrorResponse converts an error returned by Redis to an ErrorResponse

func (*MockClient) GetBool

func (mc *MockClient) GetBool(key BaseRedisKey) (val bool, err error)

GetBool gets a boolean value for a given key. Internally checks if the value for the given key is set to 1. If so, then true is returned, else false. GetInt gets an integer value for a given key.

func (*MockClient) GetInt

func (mc *MockClient) GetInt(key BaseRedisKey) (val int, err error)

GetInt gets an integer value for a given key.

func (*MockClient) GetString

func (mc *MockClient) GetString(key BaseRedisKey) (val string, err error)

GetString gets an string for a given key.

func (*MockClient) GetTopFromSortedSet

func (mc *MockClient) GetTopFromSortedSet(key BaseRedisKey) (string, error)

GetTopFromSortedSet is a dummy that does nothing but printing the arguments.

func (*MockClient) RemoveFromSortedSet

func (mc *MockClient) RemoveFromSortedSet(key BaseRedisKey, element string) error

RemoveFromSortedSet is a dummy that does nothing but printing the arguments.

func (*MockClient) SetString

func (mc *MockClient) SetString(key BaseRedisKey, value string) error

SetString sets a mock value to given key.

type Redis

type Redis interface {
	ConvertErrorToErrorResponse(error) rpcmessages.ErrorResponse
	GetBool(key BaseRedisKey) (bool, error)
	GetInt(BaseRedisKey) (int, error)
	GetString(BaseRedisKey) (string, error)
	SetString(BaseRedisKey, string) error
	AddToSortedSet(BaseRedisKey, int, string) error
	RemoveFromSortedSet(BaseRedisKey, string) error
	GetTopFromSortedSet(BaseRedisKey) (string, error)
}

Redis is an interface representing a redis Client

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL