storageredis

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

README

Certmagic TLS cluster support for Redis

This plugin is refactor based on Gamalan's. This plugin utilize go-redis/redis for its client access and redislock for it's locking mechanism. See distlock for the lock algorithm.

This plugin currently work with versions of Caddy that use https://github.com/caddyserver/certmagic and its new storage interface (> 0.11.1)

TODO

  • Add Redis Cluster or Sentinel support (probably need to update the distlock implementation first)

Documentation

Index

Constants

View Source
const (

	// DefaultAESKey needs to be 32 bytes long
	DefaultAESKey = "redistls-01234567890-caddytls-32"

	// DefaultKeyPrefix defines the default prefix in KV store
	DefaultKeyPrefix = "caddytls"

	// DefaultValuePrefix sets a prefix to KV values to check validation
	DefaultValuePrefix = "caddy-storage-redis"

	// DefaultRedisHost define the Redis instance host
	DefaultRedisHost = "127.0.0.1"

	// DefaultRedisPort define the Redis instance port
	DefaultRedisPort = "6379"

	// DefaultRedisPassword define the Redis instance password, if any
	DefaultRedisPassword = ""

	// DefaultRedisTimeout define the Redis wait time in (s)
	DefaultRedisTimeout = 5
)
View Source
const (
	// InactiveLockDuration is when the lock is considered as stale and need to be refreshed
	InactiveLockDuration = 4 * time.Hour

	// LockDuration is lock time duration
	LockDuration = 8 * time.Hour

	// ScanCount is how many scan command might return
	ScanCount int64 = 100
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	Host        string
	Port        string
	DB          int
	Password    string
	Timeout     int
	KeyPrefix   string
	ValuePrefix string
	AESKey      string
	TLSEnabled  bool
	TLSSecure   bool
}

Options is option to set plugin configuration

func GetOptions

func GetOptions() *Options

GetOptions gets default options

func ParseOptions

func ParseOptions(opt *Options) *Options

ParseOptions generate options from env or default

func (*Options) GetAESKeyByte

func (op *Options) GetAESKeyByte() []byte

GetAESKeyByte get aes key as byte

type RedisStorage

type RedisStorage struct {
	Client       *redis.Client
	ClientLocker *redislock.Client
	Options      *Options
	// contains filtered or unexported fields
}

RedisStorage contain Redis client, and plugin option

func NewDefaultRedisStorage

func NewDefaultRedisStorage() (*RedisStorage, error)

NewDefaultRedisStorage creates redis storage with default values

func NewRedisStorage

func NewRedisStorage(opt *Options) (*RedisStorage, error)

NewRedisStorage build RedisStorage

func (*RedisStorage) DecryptStorageData

func (rd *RedisStorage) DecryptStorageData(bytes []byte) (*StorageData, error)

DecryptStorageData decrypt storage data, so we can read it

func (RedisStorage) Delete

func (rd RedisStorage) Delete(key string) error

Delete deletes key.

func (*RedisStorage) EncryptStorageData

func (rd *RedisStorage) EncryptStorageData(data *StorageData) ([]byte, error)

EncryptStorageData encrypt storage data, so it won't be plain data

func (RedisStorage) Exists

func (rd RedisStorage) Exists(key string) bool

Exists returns true if the key exists

func (RedisStorage) List

func (rd RedisStorage) List(prefix string, recursive bool) ([]string, error)

List returns all keys that match prefix.

func (RedisStorage) Load

func (rd RedisStorage) Load(key string) ([]byte, error)

Load retrieves the value at key.

func (RedisStorage) Lock

func (rd RedisStorage) Lock(key string) error

Lock is to lock value

func (RedisStorage) Stat

func (rd RedisStorage) Stat(key string) (certmagic.KeyInfo, error)

Stat returns information about key.

func (RedisStorage) Store

func (rd RedisStorage) Store(key string, value []byte) error

Store values at key

func (RedisStorage) Unlock

func (rd RedisStorage) Unlock(key string) error

Unlock is to unlock value

type StorageData

type StorageData struct {
	Value    []byte    `json:"value"`
	Modified time.Time `json:"modified"`
}

StorageData describe the data that is stored in KV storage

Jump to

Keyboard shortcuts

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