rs

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2025 License: MIT Imports: 3 Imported by: 0

README

RS

rs is a simple and convenient wrapper around the go-redis, providing an easy way to connect to a Redis server in your Go applications. This library abstracts the connection setup and allows you to focus on using Redis without dealing with boilerplate code.

Installation

go get github.com/gosuit/rs

Features

• Easy configuration using environment variables or YAML files.

• Simplified client creation with automatic connection testing.

• Compatible with Redis v9.

Usage

package main

import (
    "context"
    "log"

    "github.com/gosuit/rs"
)

func main() {
    ctx := context.Background()

    // Create a configuration
    cfg := &rs.Config{
        Host:     "localhost",
        Port:     6379,
        DBNumber: 0,
        Password: "password",
    }

    // Connect to Redis
    client, err := rs.New(ctx, cfg)
    if err != nil {
        log.Fatalf("Could not connect to Redis: %v", err)
    }

    log.Println("Connected to Redis successfully!")

    // Use client...
}

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue for any enhancements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Documentation

Index

Constants

View Source
const (
	Nil = redis.Nil
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client = redis.Client

func New

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

ConnectToRedis returns a client to the Redis Server specified by Options.

type Config

type Config struct {
	Host     string `confy:"host" yaml:"host" json:"host" toml:"host" env:"REDIS_HOST"      env-default:"localhost"`
	Port     int    `confy:"port" yaml:"port" json:"port" toml:"port" env:"REDIS_PORT"      env-default:"6379"`
	DBNumber int    `confy:"db"   yaml:"db"   json:"db"   toml:"db"   env:"REDIS_DB_NUMBER" env-default:"0"`
	Password string `confy:"password" env:"REDIS_PASSWORD"`
}

Config is type for database connection

Jump to

Keyboard shortcuts

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