Documentation
¶
Overview ¶
This package allows you to init a redis client via go-redis.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClientHealthCheck ¶
func ClientHealthCheck[T RedisClient[U], U RedisError](cli T) func(ctx context.Context) error
ClientHealthCheck returns a health check function for redis.Client that can be used in health endpoint.
Example ¶
Using standard net/http package. We can also simply pass healthCheck as a CheckFn in gocom/transport/http/health/v2.
ctx := context.Background() cli := redis.NewClient(&redis.Options{ Addr: "localhost:6379", }) healthCheck := redisinit.ClientHealthCheck(cli) mux := http.NewServeMux() mux.HandleFunc("/sys/health", func(rw http.ResponseWriter, _ *http.Request) { if err := healthCheck(ctx); err != nil { rw.WriteHeader(http.StatusServiceUnavailable) } }) req, _ := http.NewRequestWithContext(ctx, http.MethodGet, "/sys/health", nil) nr := httptest.NewRecorder() mux.ServeHTTP(nr, req) rr := nr.Result() defer rr.Body.Close() fmt.Println(rr.StatusCode)
Types ¶
type RedisClient ¶
type RedisClient[T RedisError] interface { *redis.Client Ping(context.Context) T }
type RedisError ¶
Click to show internal directories.
Click to hide internal directories.