redis

package
v1.5.9 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: MIT Imports: 7 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v1.5.5

type Config struct {
	// Host is the host of the Redis server
	Host string
	// Port is the port of the Redis server
	Port int
	// Username is the username for the Redis server
	Username string
	// Password is the password for the Redis server
	Password string
	// DB is the database to use
	DB int

	// URI is the URI of the Redis server
	// such as redis://:password@host:port/db
	URI string

	// Prefix is the prefix to use for all keys
	Prefix string
}

Config is the configuration for Redis

type Redis

type Redis struct {
	sync.RWMutex
	Core   *goredis.Client
	Ctx    context.Context
	Config *Config
}

Redis is a Key-Value Store in Redis

func New

func New(cfg *Config) (*Redis, error)

New returns a new MemoryKV.

func (*Redis) Clear

func (m *Redis) Clear() error

Clear removes all elements from the kv.

func (*Redis) Delete

func (m *Redis) Delete(key string) error

Delete deletes the value for the given key.

func (*Redis) ForEach

func (m *Redis) ForEach(f func(string, interface{}))

ForEach calls the given function for each key-value pair in the kv.

func (*Redis) Get

func (m *Redis) Get(key string, value any) error

Get returns the value for the given key.

func (*Redis) Has

func (m *Redis) Has(key string) bool

Has returns true if the given key exists in the kv.

func (*Redis) Keys

func (m *Redis) Keys() []string

Keys returns the keys of the kv.

func (*Redis) Set

func (m *Redis) Set(key string, value any, maxAge ...time.Duration) error

Set sets the value for the given key. If maxAge is greater than 0, then the value will be expired after maxAge miliseconds.

func (*Redis) Size

func (m *Redis) Size() int

Size returns the number of elements in the kv.

Jump to

Keyboard shortcuts

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