StarterRedigo

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

README

starter-redigo

English | 中文

The project has been officially released, welcome to use!

starter-redigo provides a Redis client wrapper based on redigo, making it easy to integrate and use Redis in Go-Spring applications.

Installation

go get github.com/go-spring/starter-redigo

Quick Start

1. Import the starter-redigo Package

Refer to the example.go file.

import _ "github.com/go-spring/starter-redigo"
2. Configure the Redis Instance

Add Redis configuration in your project’s configuration file, for example:

spring.redigo.main.addr=127.0.0.1:6379
3. Inject the Redis Instance

Refer to the example.go file.

import "github.com/gomodule/redigo/redis"

type Service struct {
    Redis *redis.Client `autowire:""`
}
4. Use the Redis Instance

Refer to the example.go file.

str, err := s.Redis.Get(r.Context(), "key").Result()
str, err := s.Redis.Set(r.Context(), "key", "value", 0).Result()

Advanced Features

  • Supports multiple Redis instances: You can define multiple Redis instances in the configuration file and reference them by name in your project.
  • Support Redis extensions: You can extend Redis functionality by implementing the Driver interface — see the example implementation AnotherRedisDriver.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterDriver added in v1.2.7

func RegisterDriver(name string, driver Driver)

RegisterDriver registers a Redis driver with the given name. It panics if the driver name has already been registered.

Types

type Config

type Config struct {
	// Addr is the Redis server address, e.g., "127.0.0.1:6379"
	Addr string `value:"${addr}"`

	// Password is the Redis server password, default is empty.
	Password string `value:"${password:=}"`

	// Driver specifies which Redis driver to use, defaults to DefaultDriver.
	Driver string `value:"${driver:=DefaultDriver}"`
}

Config defines Redis connection configuration.

type DefaultDriver added in v1.2.7

type DefaultDriver struct{}

DefaultDriver is the default implementation of the Driver interface.

func (DefaultDriver) CreateClient added in v1.2.7

func (DefaultDriver) CreateClient(c Config) (*redis.Pool, error)

CreateClient creates a new Redis client based on the provided configuration.

type Driver added in v1.2.7

type Driver interface {
	CreateClient(c Config) (*redis.Pool, error)
}

Driver interface defines how to create a Redis client.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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