Skip to content

ose-micro/redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ose-redis

ose-redis is a lightweight Go package for interacting with Redis, built in the ose-micro style.
It provides basic key-value operations with structured logging and OpenTelemetry tracing, making it easy to integrate into microservices.

Go Reference Go Report Card License

Features

  • Simple key-value operations: Set, Get, Del, Exists
  • TTL support for keys
  • OpenTelemetry tracing for all operations
  • Structured logging for errors
  • Easy to extend for Streams, caching, and locking

Installation

go get github.com/ose-micro/ose-redis

Usage

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/ose-micro/ose-logger"
	"github.com/ose-micro/ose-tracer"
	"github.com/ose-micro/ose-redis"
)

func main() {
	// Setup logger and tracer
	log := logger.New()
	tr := tracer.New("app")

	// Initialize Redis client
	client := redis.New(redis.Config{
		Addr: "localhost:6379",
		DB:   0,
	}, log, tr)
	defer client.Close()

	ctx := context.Background()

	// Set a key with TTL
	err := client.Set(ctx, "foo", "bar", 10*time.Second)
	if err != nil {
		log.Error("failed to set key", "error", err)
	}

	// Get a key
	val, err := client.Get(ctx, "foo")
	if err != nil {
		log.Error("failed to get key", "error", err)
	} else {
		fmt.Println("foo:", val)
	}

	// Check if key exists
	exists, _ := client.Exists(ctx, "foo")
	fmt.Println("exists?", exists)

	// Delete a key
	client.Del(ctx, "foo")
}

API

Method Description Parameters Returns
Set Set a key with TTL ctx, key, value, ttl error
Get Get the value of a key ctx, key string, error
Del Delete a key ctx, key error
Exists Check if a key exists ctx, key bool, error
Close Close Redis connection - error

Logging & Tracing

  • All operations are traced using OpenTelemetry spans
  • Errors are logged with structured logger (ose-core)

Testing

The package includes unit tests using redismock to mock Redis interactions. Run tests with:

go test ./...

License

MIT License


If you want, I can also create a short version of the README specifically for GitHub packages + go.dev, highlighting just install, usage, and examples — perfect for onboarding other devs quickly.

Do you want me to do that?

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages