redis

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package redis implements the Redis storage.

Index

Constants

View Source
const Name = "redis"

Name of the storage.

Variables

This section is empty.

Functions

func Get added in v0.0.8

func Get() storage.IStorage

Get returns a setup MongoDB, or set it up.

func Set added in v0.0.8

func Set(s storage.IStorage)

Set sets the storage, primarily used for testing.

Types

type Config

type Config = redis.Options

Config is the Redis configuration.

type Redis

type Redis struct {
	*storage.Storage

	// Client is the Redis client.
	Client *redis.Client `json:"-" validate:"required"`

	// Config is the Redis configuration.
	Config *Config `json:"-"`

	// Target allows to set a static target. If it is empty, the target will be
	// dynamic - the one set at the operation (count, create, delete, etc) time.
	// Depending on the storage, target is a collection, a table, a bucket, etc.
	// For ElasticSearch, for example it doesn't have a concept of a database -
	// the target then is the index. Due to different cases of ElasticSearch
	// usage, the target can be static or dynamic - defined at the index time,
	// for example: log-{YYYY}-{MM}. For Redis, it isn't used at all.
	Target string `json:"-" validate:"omitempty,gt=0"`
}

Redis storage definition.

func New

func New(ctx context.Context, cfg *Config) (*Redis, error)

New creates a new Redis storage.

func (*Redis) Count

func (r *Redis) Count(ctx context.Context, target string, prm *count.Count, options ...storage.Func[*count.Count]) (int64, error)

Count returns the number of items in the storage.

func (*Redis) Create added in v0.0.15

func (r *Redis) Create(ctx context.Context, id, target string, v any, prm *create.Create, options ...storage.Func[*create.Create]) (string, error)

Create data.

NOTE: Not all storages returns the ID, neither all storages requires `id` to be set. You are better off setting the ID yourself.

func (*Redis) Delete

func (r *Redis) Delete(ctx context.Context, id, target string, prm *delete.Delete, options ...storage.Func[*delete.Delete]) error

Delete removes data.

func (*Redis) GetClient

func (r *Redis) GetClient() any

GetClient returns the client.

func (*Redis) List

func (r *Redis) List(ctx context.Context, target string, v any, prm *list.List, options ...storage.Func[*list.List]) error

List data.

NOTE: It uses params.List.Search to query the data.

NOTE: Redis does not support the concept of "offset" and "limit" in the same way that a traditional SQL database does.

func (*Redis) Retrieve added in v0.0.15

func (r *Redis) Retrieve(ctx context.Context, id, target string, v any, prm *retrieve.Retrieve, options ...storage.Func[*retrieve.Retrieve]) error

Retrieve data.

func (*Redis) Update

func (r *Redis) Update(ctx context.Context, id, target string, v any, prm *update.Update, options ...storage.Func[*update.Update]) error

Update data.

NOTE: Not truly an update, it's an insert.

type ResponseListKeys

type ResponseListKeys struct {
	Keys []string `json:"keys"`
}

ResponseListKeys is the response from the Redis list SCAN command.

Jump to

Keyboard shortcuts

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