1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2025-05-17 22:22:45 +02:00
Muhammad Arham 1e21a56f99
Update go-redis/redis to v9. (#1847)
* Update go-redis/redis to v9.
- And updated redislock, testify, ginko and gomega have also been updated.
- Renamed the option `IdleTimeout` to `ConnMaxIdleTime` because of 517938a6b0/CHANGELOG.md

* Update CHANGELOG.md

* Dropping dot import of the types since they created aliases now

* fixing some error messages to make tests happy

* updating more error messages that were changed to make tests happy

* reverting error messages

Co-authored-by: Muhammad Arham <marham@i2cinc.com>
2022-10-24 16:41:06 +01:00

74 lines
1.7 KiB
Go

package redis
import (
"context"
"time"
"github.com/go-redis/redis/v9"
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/sessions"
)
// Client is wrapper interface for redis.Client and redis.ClusterClient.
type Client interface {
Get(ctx context.Context, key string) ([]byte, error)
Lock(key string) sessions.Lock
Set(ctx context.Context, key string, value []byte, expiration time.Duration) error
Del(ctx context.Context, key string) error
}
var _ Client = (*client)(nil)
type client struct {
*redis.Client
}
func newClient(c *redis.Client) Client {
return &client{
Client: c,
}
}
func (c *client) Get(ctx context.Context, key string) ([]byte, error) {
return c.Client.Get(ctx, key).Bytes()
}
func (c *client) Set(ctx context.Context, key string, value []byte, expiration time.Duration) error {
return c.Client.Set(ctx, key, value, expiration).Err()
}
func (c *client) Del(ctx context.Context, key string) error {
return c.Client.Del(ctx, key).Err()
}
func (c *client) Lock(key string) sessions.Lock {
return NewLock(c.Client, key)
}
var _ Client = (*clusterClient)(nil)
type clusterClient struct {
*redis.ClusterClient
}
func newClusterClient(c *redis.ClusterClient) Client {
return &clusterClient{
ClusterClient: c,
}
}
func (c *clusterClient) Get(ctx context.Context, key string) ([]byte, error) {
return c.ClusterClient.Get(ctx, key).Bytes()
}
func (c *clusterClient) Set(ctx context.Context, key string, value []byte, expiration time.Duration) error {
return c.ClusterClient.Set(ctx, key, value, expiration).Err()
}
func (c *clusterClient) Del(ctx context.Context, key string) error {
return c.ClusterClient.Del(ctx, key).Err()
}
func (c *clusterClient) Lock(key string) sessions.Lock {
return NewLock(c.ClusterClient, key)
}