mredis

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: Apache-2.0 Imports: 3 Imported by: 7

Documentation

Overview

Package mredis provides a Redis client implementation for Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Host     string // Redis server host
	Port     string // Redis server port
	Password string // Redis server password (optional)
	DB       int    // Redis database number
}

Config holds the configuration settings for the Redis client.

type Service

type Service interface {
	// Set sets the value of a key in Redis.
	Set(ctx context.Context, k string, v interface{}) error

	// HSet sets the values of multiple fields in a hash stored at key in Redis.
	HSet(ctx context.Context, k string, v ...interface{}) error

	// Get returns the value of a key in Redis as a string.
	Get(ctx context.Context, k string) (string, error)

	// HGet returns the value associated with field in the hash stored at key in Redis as a string.
	HGet(ctx context.Context, k string, field string) (string, error)

	// HGetAll returns all fields and values of the hash stored at key in Redis as a map[string]string.
	HGetAll(ctx context.Context, k string) (map[string]string, error)

	// SetEx sets the value of a key in Redis with an expiration duration.
	SetEx(ctx context.Context, k string, v interface{}, d time.Duration) error

	// Del deletes one or more keys in Redis.
	Del(ctx context.Context, k ...string) error

	// Exist checks if a key exists in Redis.
	Exist(ctx context.Context, k string) (bool, error)

	// GetClient returns the Redis client.
	GetClient() *redis.Client
}

Service is the interface that defines the Redis service methods.

func New

func New(cnf *Config) Service

New creates a new Redis client with the provided configuration.

Jump to

Keyboard shortcuts

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