From 0944f9917e36eef4dc95df9a943b3dd710111c19 Mon Sep 17 00:00:00 2001
From: Brian Ketelsen <bketelsen@gmail.com>
Date: Thu, 15 May 2025 12:25:04 -0400
Subject: [PATCH] rename redis

---
 cache/{rediscache => redis}/options.go      | 18 +++++++++---------
 cache/{rediscache => redis}/options_test.go | 12 ++++++------
 cache/{rediscache => redis}/redis.go        |  8 ++++----
 cache/{rediscache => redis}/redis_test.go   |  2 +-
 cmd/cmd.go                                  |  4 ++--
 5 files changed, 22 insertions(+), 22 deletions(-)
 rename cache/{rediscache => redis}/options.go (57%)
 rename cache/{rediscache => redis}/options_test.go (92%)
 rename cache/{rediscache => redis}/redis.go (90%)
 rename cache/{rediscache => redis}/redis_test.go (98%)

diff --git a/cache/rediscache/options.go b/cache/redis/options.go
similarity index 57%
rename from cache/rediscache/options.go
rename to cache/redis/options.go
index b89d0bfe..deeba793 100644
--- a/cache/rediscache/options.go
+++ b/cache/redis/options.go
@@ -1,16 +1,16 @@
-package rediscache
+package redis
 
 import (
 	"context"
 
-	"github.com/go-redis/redis/v8"
+	rclient "github.com/go-redis/redis/v8"
 	"go-micro.dev/v5/cache"
 )
 
 type redisOptionsContextKey struct{}
 
 // WithRedisOptions sets advanced options for redis.
-func WithRedisOptions(options redis.UniversalOptions) cache.Option {
+func WithRedisOptions(options rclient.UniversalOptions) cache.Option {
 	return func(o *cache.Options) {
 		if o.Context == nil {
 			o.Context = context.Background()
@@ -20,29 +20,29 @@ func WithRedisOptions(options redis.UniversalOptions) cache.Option {
 	}
 }
 
-func newUniversalClient(options cache.Options) redis.UniversalClient {
+func newUniversalClient(options cache.Options) rclient.UniversalClient {
 	if options.Context == nil {
 		options.Context = context.Background()
 	}
 
-	opts, ok := options.Context.Value(redisOptionsContextKey{}).(redis.UniversalOptions)
+	opts, ok := options.Context.Value(redisOptionsContextKey{}).(rclient.UniversalOptions)
 	if !ok {
 		addr := "redis://127.0.0.1:6379"
 		if len(options.Address) > 0 {
 			addr = options.Address
 		}
 
-		redisOptions, err := redis.ParseURL(addr)
+		redisOptions, err := rclient.ParseURL(addr)
 		if err != nil {
-			redisOptions = &redis.Options{Addr: addr}
+			redisOptions = &rclient.Options{Addr: addr}
 		}
 
-		return redis.NewClient(redisOptions)
+		return rclient.NewClient(redisOptions)
 	}
 
 	if len(opts.Addrs) == 0 && len(options.Address) > 0 {
 		opts.Addrs = []string{options.Address}
 	}
 
-	return redis.NewUniversalClient(&opts)
+	return rclient.NewUniversalClient(&opts)
 }
diff --git a/cache/rediscache/options_test.go b/cache/redis/options_test.go
similarity index 92%
rename from cache/rediscache/options_test.go
rename to cache/redis/options_test.go
index dc300f94..0eeca878 100644
--- a/cache/rediscache/options_test.go
+++ b/cache/redis/options_test.go
@@ -1,11 +1,11 @@
-package rediscache
+package redis
 
 import (
 	"context"
 	"reflect"
 	"testing"
 
-	"github.com/go-redis/redis/v8"
+	rclient "github.com/go-redis/redis/v8"
 	"go-micro.dev/v5/cache"
 )
 
@@ -60,7 +60,7 @@ func Test_newUniversalClient(t *testing.T) {
 			options: cache.Options{
 				Context: context.WithValue(
 					context.TODO(), redisOptionsContextKey{},
-					redis.UniversalOptions{MasterName: "master-name"}),
+					rclient.UniversalOptions{MasterName: "master-name"}),
 			}},
 			want: wantValues{
 				username: "",
@@ -71,7 +71,7 @@ func Test_newUniversalClient(t *testing.T) {
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			univClient := newUniversalClient(tt.fields.options)
-			client, ok := univClient.(*redis.Client)
+			client, ok := univClient.(*rclient.Client)
 			if !ok {
 				t.Errorf("newUniversalClient() expect a *redis.Client")
 				return
@@ -109,7 +109,7 @@ func Test_newUniversalClientCluster(t *testing.T) {
 				Address: "127.0.0.1:6379", // <- ignored
 				Context: context.WithValue(
 					context.TODO(), redisOptionsContextKey{},
-					redis.UniversalOptions{Addrs: []string{"127.0.0.1:6381", "127.0.0.1:6382"}}),
+					rclient.UniversalOptions{Addrs: []string{"127.0.0.1:6381", "127.0.0.1:6382"}}),
 			}},
 			want: wantValues{
 				username: "",
@@ -120,7 +120,7 @@ func Test_newUniversalClientCluster(t *testing.T) {
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			univClient := newUniversalClient(tt.fields.options)
-			client, ok := univClient.(*redis.ClusterClient)
+			client, ok := univClient.(*rclient.ClusterClient)
 			if !ok {
 				t.Errorf("newUniversalClient() expect a *redis.ClusterClient")
 				return
diff --git a/cache/rediscache/redis.go b/cache/redis/redis.go
similarity index 90%
rename from cache/rediscache/redis.go
rename to cache/redis/redis.go
index d82bd08e..350f9029 100644
--- a/cache/rediscache/redis.go
+++ b/cache/redis/redis.go
@@ -1,10 +1,10 @@
-package rediscache
+package redis
 
 import (
 	"context"
 	"time"
 
-	"github.com/go-redis/redis/v8"
+	rclient "github.com/go-redis/redis/v8"
 	"go-micro.dev/v5/cache"
 )
 
@@ -19,12 +19,12 @@ func NewRedisCache(opts ...cache.Option) cache.Cache {
 
 type redisCache struct {
 	opts   cache.Options
-	client redis.UniversalClient
+	client rclient.UniversalClient
 }
 
 func (c *redisCache) Get(ctx context.Context, key string) (interface{}, time.Time, error) {
 	val, err := c.client.Get(ctx, key).Bytes()
-	if err != nil && err == redis.Nil {
+	if err != nil && err == rclient.Nil {
 		return nil, time.Time{}, cache.ErrKeyNotFound
 	} else if err != nil {
 		return nil, time.Time{}, err
diff --git a/cache/rediscache/redis_test.go b/cache/redis/redis_test.go
similarity index 98%
rename from cache/rediscache/redis_test.go
rename to cache/redis/redis_test.go
index abc54fe0..e6c0f78d 100644
--- a/cache/rediscache/redis_test.go
+++ b/cache/redis/redis_test.go
@@ -1,4 +1,4 @@
-package rediscache
+package redis
 
 import (
 	"context"
diff --git a/cmd/cmd.go b/cmd/cmd.go
index 35b9052f..7ec3425a 100644
--- a/cmd/cmd.go
+++ b/cmd/cmd.go
@@ -14,7 +14,7 @@ import (
 
 	"go-micro.dev/v5/broker"
 	"go-micro.dev/v5/cache"
-	rediscache "go-micro.dev/v5/cache/rediscache"
+	"go-micro.dev/v5/cache/redis"
 	"go-micro.dev/v5/client"
 	"go-micro.dev/v5/config"
 	"go-micro.dev/v5/debug/profile"
@@ -276,7 +276,7 @@ var (
 	DefaultConfigs = map[string]func(...config.Option) (config.Config, error){}
 
 	DefaultCaches = map[string]func(...cache.Option) cache.Cache{
-		"redis": rediscache.NewRedisCache,
+		"redis": redis.NewRedisCache,
 	}
 )