Skip to content

konradreiche/go-redis-prefix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🏷️ go-redis-prefix

ci codecov

A package that provides a Redis hook to automatically prefix keys during testing. This helps prevent key collisions when running tests in parallel or across multiple packages that interact with the same Redis instance.

Installation

go get github.com/konradreiche/go-redis-prefix@latest

Usage

import (
	"testing"

	"github.com/konradreiche/go-redis-prefix/redisprefixtest"
	"github.com/redis/go-redis/v9"
)

func TestRedis(t *testing.T) {
	client := redis.NewClient(&redis.Options{
		Addr: "localhost:6379",
	})
	client.AddHook(redisprefixtest.New(t))

    // Your test code here...
}

Limitations

  • Multi-Key Commands: The hook does not support automatic prefixing for multi-key commands. You must handle these cases manually or avoid using multi-key commands in tests.
  • Key Position: The hook assumes that the key is the command's second argument. This is true for most commands, but some have keys in different positions.

About

🏷️ Provides a Redis hook to automatically prefix keys during testing

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages