storage

package
v1.7.0-rc13 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2023 License: MPL-2.0 Imports: 19 Imported by: 41

Documentation

Index

Constants

View Source
const B64JSONPrefix = "ey"

`{"` in base64

Variables

View Source
var (
	HashSha256    = "sha256"
	HashMurmur32  = "murmur32"
	HashMurmur64  = "murmur64"
	HashMurmur128 = "murmur128"
)
View Source
var ErrKeyNotFound = errors.New("key not found")

ErrKeyNotFound is a standard error for when a key is not found in the storage engine

View Source
var ErrRedisIsDown = errors.New("storage: Redis is either down or was not configured")

ErrRedisIsDown is returned when we can't communicate with redis

Functions

func GenerateToken

func GenerateToken(orgID, keyID, hashAlgorithm string) (string, error)

If hashing algorithm is empty, use legacy key generation

func HashKey

func HashKey(in string, hashKey bool) string

func HashStr

func HashStr(in string, withAlg ...string) string

func NewRedisClusterPool

func NewRedisClusterPool(isCache, isAnalytics bool, conf config.Config) redis.UniversalClient

func TokenHashAlgo

func TokenHashAlgo(token string) string

func TokenID

func TokenID(token string) (id string, err error)

TODO: add checks

func TokenOrg

func TokenOrg(token string) string

Types

type AnalyticsHandler

type AnalyticsHandler interface {
	Connect() bool
	AppendToSetPipelined(string, [][]byte)
	GetAndDeleteSet(string) []interface{}
	SetExp(string, int64) error   // Set key expiration
	GetExp(string) (int64, error) // Returns expiry of a key
}

type Handler

type Handler interface {
	GetKey(string) (string, error) // Returned string is expected to be a JSON object (user.SessionState)
	GetMultiKey([]string) ([]string, error)
	GetRawKey(string) (string, error)
	SetKey(string, string, int64) error // Second input string is expected to be a JSON object (user.SessionState)
	SetRawKey(string, string, int64) error
	SetExp(string, int64) error   // Set key expiration
	GetExp(string) (int64, error) // Returns expiry of a key
	GetKeys(string) []string
	DeleteKey(string) bool
	DeleteAllKeys() bool
	DeleteRawKey(string) bool
	Connect() bool
	GetKeysAndValues() map[string]string
	GetKeysAndValuesWithFilter(string) map[string]string
	DeleteKeys([]string) bool
	Decrement(string)
	IncrememntWithExpire(string, int64) int64
	SetRollingWindow(key string, per int64, val string, pipeline bool) (int, []interface{})
	GetRollingWindow(key string, per int64, pipeline bool) (int, []interface{})
	GetSet(string) (map[string]string, error)
	AddToSet(string, string)
	GetAndDeleteSet(string) []interface{}
	RemoveFromSet(string, string)
	DeleteScanMatch(string) bool
	GetKeyPrefix() string
	AddToSortedSet(string, string, float64)
	GetSortedSetRange(string, string, string) ([]string, []float64, error)
	RemoveSortedSetRange(string, string, string) error
	GetListRange(string, int64, int64) ([]string, error)
	RemoveFromList(string, string) error
	AppendToSet(string, string)
	Exists(string) (bool, error)
}

Handler is a standard interface to a storage backend, used by AuthorisationManager to read and write key values to the backend

type MdcbStorage

type MdcbStorage struct {
	CallbackonPullfromRPC *func(key string, val string) error
	// contains filtered or unexported fields
}

func NewMdcbStorage

func NewMdcbStorage(local, rpc Handler, log *logrus.Entry) *MdcbStorage

func (MdcbStorage) AddToSet

func (m MdcbStorage) AddToSet(key string, value string)

func (MdcbStorage) AddToSortedSet

func (m MdcbStorage) AddToSortedSet(string, string, float64)

func (MdcbStorage) AppendToSet

func (m MdcbStorage) AppendToSet(key string, value string)

func (MdcbStorage) Connect

func (m MdcbStorage) Connect() bool

func (MdcbStorage) Decrement

func (m MdcbStorage) Decrement(string)

func (MdcbStorage) DeleteAllKeys

func (m MdcbStorage) DeleteAllKeys() bool

func (MdcbStorage) DeleteKey

func (m MdcbStorage) DeleteKey(key string) bool

func (MdcbStorage) DeleteKeys

func (m MdcbStorage) DeleteKeys([]string) bool

func (MdcbStorage) DeleteRawKey

func (m MdcbStorage) DeleteRawKey(string) bool

func (MdcbStorage) DeleteScanMatch

func (m MdcbStorage) DeleteScanMatch(key string) bool

func (MdcbStorage) Exists

func (m MdcbStorage) Exists(key string) (bool, error)

func (MdcbStorage) GetAndDeleteSet

func (m MdcbStorage) GetAndDeleteSet(string) []interface{}

func (MdcbStorage) GetExp

func (m MdcbStorage) GetExp(string) (int64, error)

func (MdcbStorage) GetKey

func (m MdcbStorage) GetKey(key string) (string, error)

func (MdcbStorage) GetKeyPrefix

func (m MdcbStorage) GetKeyPrefix() string

func (MdcbStorage) GetKeys

func (m MdcbStorage) GetKeys(key string) []string

func (MdcbStorage) GetKeysAndValues

func (m MdcbStorage) GetKeysAndValues() map[string]string

func (MdcbStorage) GetKeysAndValuesWithFilter

func (m MdcbStorage) GetKeysAndValuesWithFilter(key string) map[string]string

func (MdcbStorage) GetListRange

func (m MdcbStorage) GetListRange(key string, from int64, to int64) ([]string, error)

func (MdcbStorage) GetMultiKey

func (m MdcbStorage) GetMultiKey([]string) ([]string, error)

func (MdcbStorage) GetRawKey

func (m MdcbStorage) GetRawKey(string) (string, error)

func (MdcbStorage) GetRollingWindow

func (m MdcbStorage) GetRollingWindow(key string, per int64, pipeline bool) (int, []interface{})

func (MdcbStorage) GetSet

func (m MdcbStorage) GetSet(key string) (map[string]string, error)

func (MdcbStorage) GetSortedSetRange

func (m MdcbStorage) GetSortedSetRange(string, string, string) ([]string, []float64, error)

func (MdcbStorage) IncrememntWithExpire

func (m MdcbStorage) IncrememntWithExpire(string, int64) int64

func (MdcbStorage) RemoveFromList

func (m MdcbStorage) RemoveFromList(key string, value string) error

func (MdcbStorage) RemoveFromSet

func (m MdcbStorage) RemoveFromSet(key string, value string)

func (MdcbStorage) RemoveSortedSetRange

func (m MdcbStorage) RemoveSortedSetRange(string, string, string) error

func (MdcbStorage) SetExp

func (m MdcbStorage) SetExp(string, int64) error

func (MdcbStorage) SetKey

func (m MdcbStorage) SetKey(key string, content string, TTL int64) error

func (MdcbStorage) SetRawKey

func (m MdcbStorage) SetRawKey(string, string, int64) error

func (MdcbStorage) SetRollingWindow

func (m MdcbStorage) SetRollingWindow(key string, per int64, val string, pipeline bool) (int, []interface{})

type RedisCluster

type RedisCluster struct {
	KeyPrefix   string
	HashKeys    bool
	IsCache     bool
	IsAnalytics bool
	// RedisController must be passed from the gateway
	RedisController *RedisController
}

RedisCluster is a storage manager that uses the redis database.

func (*RedisCluster) AddToSet

func (r *RedisCluster) AddToSet(keyName, value string)

func (*RedisCluster) AddToSortedSet

func (r *RedisCluster) AddToSortedSet(keyName, value string, score float64)

AddToSortedSet adds value with given score to sorted set identified by keyName

func (*RedisCluster) AppendToSet

func (r *RedisCluster) AppendToSet(keyName, value string)

func (*RedisCluster) AppendToSetPipelined

func (r *RedisCluster) AppendToSetPipelined(key string, values [][]byte)

func (*RedisCluster) Connect

func (r *RedisCluster) Connect() bool

Connect will establish a connection this is always true because we are dynamically using redis

func (*RedisCluster) ControllerInitiated

func (r *RedisCluster) ControllerInitiated() bool

func (*RedisCluster) Decrement

func (r *RedisCluster) Decrement(keyName string)

Decrement will decrement a key in redis

func (*RedisCluster) DeleteAllKeys

func (r *RedisCluster) DeleteAllKeys() bool

DeleteAllKeys will remove all keys from the database.

func (*RedisCluster) DeleteKey

func (r *RedisCluster) DeleteKey(keyName string) bool

DeleteKey will remove a key from the database

func (*RedisCluster) DeleteKeys

func (r *RedisCluster) DeleteKeys(keys []string) bool

DeleteKeys will remove a group of keys in bulk

func (*RedisCluster) DeleteRawKey

func (r *RedisCluster) DeleteRawKey(keyName string) bool

DeleteKey will remove a key from the database without prefixing, assumes user knows what they are doing

func (*RedisCluster) DeleteScanMatch

func (r *RedisCluster) DeleteScanMatch(pattern string) bool

DeleteKeys will remove a group of keys in bulk

func (*RedisCluster) Exists

func (r *RedisCluster) Exists(keyName string) (bool, error)

Exists check if keyName exists

func (*RedisCluster) GetAndDeleteSet

func (r *RedisCluster) GetAndDeleteSet(keyName string) []interface{}

func (*RedisCluster) GetExp

func (r *RedisCluster) GetExp(keyName string) (int64, error)

func (*RedisCluster) GetKey

func (r *RedisCluster) GetKey(keyName string) (string, error)

GetKey will retrieve a key from the database

func (*RedisCluster) GetKeyPrefix

func (r *RedisCluster) GetKeyPrefix() string

GetPrefix returns storage key prefix

func (*RedisCluster) GetKeyTTL

func (r *RedisCluster) GetKeyTTL(keyName string) (ttl int64, err error)

func (*RedisCluster) GetKeys

func (r *RedisCluster) GetKeys(filter string) []string

GetKeys will return all keys according to the filter (filter is a prefix - e.g. tyk.keys.*)

func (*RedisCluster) GetKeysAndValues

func (r *RedisCluster) GetKeysAndValues() map[string]string

GetKeysAndValues will return all keys and their values - not to be used lightly

func (*RedisCluster) GetKeysAndValuesWithFilter

func (r *RedisCluster) GetKeysAndValuesWithFilter(filter string) map[string]string

GetKeysAndValuesWithFilter will return all keys and their values with a filter

func (*RedisCluster) GetListRange

func (r *RedisCluster) GetListRange(keyName string, from, to int64) ([]string, error)

GetListRange gets range of elements of list identified by keyName

func (*RedisCluster) GetMultiKey

func (r *RedisCluster) GetMultiKey(keys []string) ([]string, error)

GetMultiKey gets multiple keys from the database

func (*RedisCluster) GetRawKey

func (r *RedisCluster) GetRawKey(keyName string) (string, error)

func (RedisCluster) GetRollingWindow

func (r RedisCluster) GetRollingWindow(keyName string, per int64, pipeline bool) (int, []interface{})

func (*RedisCluster) GetSet

func (r *RedisCluster) GetSet(keyName string) (map[string]string, error)

func (*RedisCluster) GetSortedSetRange

func (r *RedisCluster) GetSortedSetRange(keyName, scoreFrom, scoreTo string) ([]string, []float64, error)

GetSortedSetRange gets range of elements of sorted set identified by keyName

func (*RedisCluster) IncrememntWithExpire

func (r *RedisCluster) IncrememntWithExpire(keyName string, expire int64) int64

IncrementWithExpire will increment a key in redis

func (*RedisCluster) IsMemberOfSet

func (r *RedisCluster) IsMemberOfSet(keyName, value string) bool

func (*RedisCluster) Publish

func (r *RedisCluster) Publish(channel, message string) error

func (*RedisCluster) RemoveFromList

func (r *RedisCluster) RemoveFromList(keyName, value string) error

RemoveFromList delete an value from a list idetinfied with the keyName

func (*RedisCluster) RemoveFromSet

func (r *RedisCluster) RemoveFromSet(keyName, value string)

func (*RedisCluster) RemoveSortedSetRange

func (r *RedisCluster) RemoveSortedSetRange(keyName, scoreFrom, scoreTo string) error

RemoveSortedSetRange removes range of elements from sorted set identified by keyName

func (*RedisCluster) SetExp

func (r *RedisCluster) SetExp(keyName string, timeout int64) error

func (*RedisCluster) SetKey

func (r *RedisCluster) SetKey(keyName, session string, timeout int64) error

SetKey will create (or update) a key value in the store

func (*RedisCluster) SetRawKey

func (r *RedisCluster) SetRawKey(keyName, session string, timeout int64) error

func (*RedisCluster) SetRollingWindow

func (r *RedisCluster) SetRollingWindow(keyName string, per int64, value_override string, pipeline bool) (int, []interface{})

SetRollingWindow will append to a sorted set in redis and extract a timed window of values

func (*RedisCluster) StartPubSubHandler

func (r *RedisCluster) StartPubSubHandler(ctx context.Context, channel string, callback func(interface{})) error

StartPubSubHandler will listen for a signal and run the callback for every subscription and message event.

type RedisController

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

func NewRedisController

func NewRedisController(ctx context.Context) *RedisController

func (*RedisController) ConnectToRedis

func (rc *RedisController) ConnectToRedis(ctx context.Context, onReconnect func(), conf *config.Config)

ConnectToRedis starts a go routine that periodically tries to connect to redis.

onReconnect will be called when we have established a successful redis reconnection

func (*RedisController) Connected

func (rc *RedisController) Connected() bool

Connected returns true if we are connected to redis

func (*RedisController) DisableRedis

func (rc *RedisController) DisableRedis(setRedisDown bool)

DisableRedis allows to dynamically enable/disable talking with redisW

func (*RedisController) WaitConnect

func (rc *RedisController) WaitConnect(ctx context.Context) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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