redis

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const B64JSONPrefix = "ey"

B64JSONPrefix stand for `{"` in base64.

View Source
const (
	HashSha256 = "sha256"
)

Variables

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.

Functions

func HashKey

func HashKey(in string) string

HashKey return hash the give string and return.

func HashStr

func HashStr(in string) string

HashStr return hash the give string and return.

func InitInstance

func InitInstance(ctx context.Context, opts *Options) error

InitInstance initialize the redis cluster client.

func TokenHashAlgo

func TokenHashAlgo(token string) string

TokenHashAlgo ...

func TokenOrg

func TokenOrg(token string) string

TokenOrg ...

Types

type Option

type Option func(*store)

Option config redis store.

func WithKeyHash

func WithKeyHash() Option

WithKeyHash enables key hashing.

func WithKeyPrefix

func WithKeyPrefix(prefix string) Option

WithKeyPrefix sets the key-prefix.

type Options

type Options struct {
	Addrs          []string      `json:"addrs"           mapstructure:"addrs"`
	Username       string        `json:"username"        mapstructure:"username"`
	Password       string        `json:"password"        mapstructure:"password"`
	Database       int           `json:"database"        mapstructure:"database"`
	MasterName     string        `json:"master-name"     mapstructure:"master-name"`
	EnableCluster  bool          `json:"enable-cluster"  mapstructure:"enable-cluster"`
	PoolSize       int           `json:"pool-size"       mapstructure:"pool-size"`
	DialTimeout    time.Duration `json:"dial-timeout"    mapstructure:"dial-timeout"`
	RequestTimeout time.Duration `json:"request-timeout" mapstructure:"request-timeout"`
	TLS            TLSOptions    `json:"tls"             mapstructure:"tls"`
}

Options defines options for redis cluster.

func NewOptions

func NewOptions() *Options

NewOptions create a new redis options instance.

func (*Options) AddFlags

func (o *Options) AddFlags(fs *pflag.FlagSet)

AddFlags adds flags related to redis storage to the specified FlagSet.

func (*Options) Validate

func (o *Options) Validate() []error

Validate verifies flags passed to Options.

type Store

type Store 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,
		time.Duration,
	) error // Second input string is expected to be a JSON object (user.SessionState)
	SetRawKey(string, string, time.Duration) error
	SetExp(string, time.Duration) error   // Set key expiration
	GetExp(string) (time.Duration, error) // Returns expiry of a key
	GetKeys(string) []string
	DeleteKey(string) bool
	DeleteAllKeys() bool
	DeleteRawKey(string) bool
	GetKeysAndValues() map[string]string
	GetKeysAndValuesWithFilter(string) map[string]string
	DeleteKeys([]string) bool
	Decrement(string)
	IncrememntWithExpire(string, time.Duration) 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)
}

Store is the store interface of redis engine.

func NewStore

func NewStore() Store

NewStore returns a new redis store with the global singleton redis client.

type TLSOptions

type TLSOptions struct {
	Enabled bool `json:"enabled"          mapstructure:"enabled"`
	// CertFile is a file containing a PEM-encoded certificate, and possibly the complete certificate chain
	CertFile string `json:"cert-file"        mapstructure:"cert-file"`
	// KeyFile is a file containing a PEM-encoded private key for the certificate specified by CertFile
	KeyFile string `json:"private-key-file" mapstructure:"private-key-file"`
}

TLSOptions contains configuration for TLS.

Jump to

Keyboard shortcuts

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