Skip to main content
Version: 2.8.x(Latest)

Introduction

The Redis client is implemented by the gredis component, which adopts a connection pool design at the bottom layer.

tip

To ensure universality and scalability, the gredis component uses the command channel method to execute Redis operations. When you are unsure how to pass parameters for the command channel, you can refer to the parameter passing of the terminal command line. In other words, all operations remain consistent with the parameter passing of command lines.

Usage:

Installation:

go get -u github.com/gogf/gf/contrib/nosql/redis/v2

Reference:

import (
_ "github.com/gogf/gf/contrib/nosql/redis/v2"

// other imported packages.
)

Interface Documentation:

Brief Introduction:

gredis uses a connection pool to manage Redis connections. You can manage the connection pool properties through the Config configuration object or the Set* methods, and obtain pool statistics through the Stats method. gredis uses an interface-based design to decouple the underlying dependency on redis. It implements over 100+ common methods using a community component approach and provides a grouping method for managing interfaces.

warning

The gredis.Redis client object provides a Close method, which is used to close the Redis client (and also the client's connection pool), not the connection object. Developers generally will not use it; non-advanced users should not use it.

Features

gredis has the following notable features:

  • Easy to use, powerful features
  • Unified configuration for components
  • Provides community component implementation of 100+ common methods
  • Supports both single instance and cluster operations
  • Supports all features of Redis services
  • Supports OpenTelemetry observability
  • Supports singleton objects and dynamic object creation
  • Interface design with high flexibility and extensibility

Documentation

📄️ Redis - Examples

Examples of performing basic operations in Redis using the GoFrame framework, including Set/Get, SetEx, HSet/HGetAll, and HMSet/HMGet operations. These code examples demonstrate how to store and retrieve data through the Redis module of the GoFrame framework, suitable for beginners to learn how to implement Redis functions in the GoFrame framework environment. This example also reminds users that HMSET has been deprecated in Redis version 4.0.0 and above; HSET should be used.