Skip to content

Commit e159e0e

Browse files
committed
fix(tests): fix client configuration
1 parent 162f6ea commit e159e0e

File tree

6 files changed

+88
-28
lines changed

6 files changed

+88
-28
lines changed

examples/entraid/clientcert/main.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,20 @@ func main() {
4444
}
4545

4646
// Create Redis client with streaming credentials provider
47-
redisClient := redis.NewClusterClient(&redis.ClusterOptions{
48-
Addrs: []string{cfg.Endpoints["standalone-entraid-acl"].Endpoints[0]},
49-
StreamingCredentialsProvider: cp,
50-
})
47+
opts, err := redis.ParseURL(cfg.Endpoints["standalone-entraid-acl"].Endpoints[0])
48+
if err != nil {
49+
log.Fatalf("Failed to parse Redis URL: %v", err)
50+
}
51+
opts.StreamingCredentialsProvider = cp
52+
redisClient := redis.NewClient(opts)
5153

5254
// Create second Redis client for cluster
55+
clusterOpts, err := redis.ParseURL(cfg.Endpoints["cluster-entraid-acl"].Endpoints[0])
56+
if err != nil {
57+
log.Fatalf("Failed to parse Redis URL: %v", err)
58+
}
5359
clusterClient := redis.NewClusterClient(&redis.ClusterOptions{
54-
Addrs: cfg.Endpoints["cluster-entraid-acl"].Endpoints,
60+
Addrs: []string{clusterOpts.Addr},
5561
StreamingCredentialsProvider: cp,
5662
})
5763

examples/entraid/clientsecret/main.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,24 @@ func main() {
4141
}
4242

4343
// Create Redis client with streaming credentials provider
44-
redisClient := redis.NewClusterClient(&redis.ClusterOptions{
45-
Addrs: []string{cfg.Endpoints["standalone-entraid-acl"].Endpoints[0]},
46-
StreamingCredentialsProvider: cp,
47-
})
44+
opts, err := redis.ParseURL(cfg.Endpoints["standalone-entraid-acl"].Endpoints[0])
45+
if err != nil {
46+
log.Fatalf("Failed to parse Redis URL: %v", err)
47+
}
48+
opts.StreamingCredentialsProvider = cp
49+
redisClient := redis.NewClient(opts)
4850

4951
// Create second Redis client for cluster
52+
clusterOpts, err := redis.ParseURL(cfg.Endpoints["cluster-entraid-acl"].Endpoints[0])
53+
if err != nil {
54+
log.Fatalf("Failed to parse Redis URL: %v", err)
55+
}
5056
clusterClient := redis.NewClusterClient(&redis.ClusterOptions{
51-
Addrs: cfg.Endpoints["cluster-entraid-acl"].Endpoints,
57+
Addrs: []string{clusterOpts.Addr},
5258
StreamingCredentialsProvider: cp,
5359
})
5460

61+
5562
// Test the connection
5663
pong, err := redisClient.Ping(ctx).Result()
5764
if err != nil {

examples/entraid/config/config.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@ func LoadConfig(configPath string) (*EntraidConfig, error) {
4343
}
4444

4545
file, err := os.Open(configPath)
46+
if err != nil {
47+
file, err = os.Open("endpoints.json")
48+
}
49+
4650
if err == nil {
4751
defer file.Close()
4852
decoder := json.NewDecoder(file)
49-
err = decoder.Decode(config)
53+
err = decoder.Decode(&config.Endpoints)
5054
if err != nil {
5155
return nil, err
5256
}

examples/entraid/defaultcredentials/main.go

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"log"
7+
"os"
78

89
"config"
910

@@ -16,7 +17,7 @@ func main() {
1617
ctx := context.Background()
1718

1819
// Load configuration
19-
cfg, err := config.LoadConfig("")
20+
cfg, err := config.LoadConfig(os.Getenv("REDIS_ENDPOINTS_CONFIG_PATH"))
2021
if err != nil {
2122
log.Fatalf("Failed to load config: %v", err)
2223
}
@@ -37,18 +38,35 @@ func main() {
3738
}
3839

3940
// Create Redis client with streaming credentials provider
40-
redisClient := redis.NewClusterClient(&redis.ClusterOptions{
41-
DisableIdentity: true,
42-
Addrs: []string{cfg.Endpoints["standalone-entraid-acl"].Endpoints[0]},
41+
opts, err := redis.ParseURL(cfg.Endpoints["standalone-entraid-acl"].Endpoints[0])
42+
if err != nil {
43+
log.Fatalf("Failed to parse Redis URL: %v", err)
44+
}
45+
opts.StreamingCredentialsProvider = cp
46+
redisClient := redis.NewClient(opts)
47+
48+
// Create second Redis client for cluster
49+
clusterOpts, err := redis.ParseURL(cfg.Endpoints["cluster-entraid-acl"].Endpoints[0])
50+
if err != nil {
51+
log.Fatalf("Failed to parse Redis URL: %v", err)
52+
}
53+
clusterClient := redis.NewClusterClient(&redis.ClusterOptions{
54+
Addrs: []string{clusterOpts.Addr},
4355
StreamingCredentialsProvider: cp,
4456
})
4557

46-
// Test the connection
4758
pong, err := redisClient.Ping(ctx).Result()
4859
if err != nil {
4960
log.Fatalf("Failed to ping Redis: %v", err)
5061
}
51-
fmt.Printf("Successfully connected to Redis: %s\n", pong)
62+
fmt.Printf("Successfully connected to Redis standalone: %s\n", pong)
63+
64+
// Test cluster connection
65+
clusterPong, err := clusterClient.Ping(ctx).Result()
66+
if err != nil {
67+
log.Fatalf("Failed to ping Redis cluster: %v", err)
68+
}
69+
fmt.Printf("Successfully connected to Redis cluster: %s\n", clusterPong)
5270

5371
// Set a test key
5472
err = redisClient.Set(ctx, "test-key", "test-value", 0).Err()
@@ -61,5 +79,18 @@ func main() {
6179
if err != nil {
6280
log.Fatalf("Failed to get test key: %v", err)
6381
}
64-
fmt.Printf("Retrieved value: %s\n", val)
82+
fmt.Printf("Retrieved value from standalone: %s\n", val)
83+
84+
// Set a test key in cluster
85+
err = clusterClient.Set(ctx, "test-key", "test-value", 0).Err()
86+
if err != nil {
87+
log.Fatalf("Failed to set test key in cluster: %v", err)
88+
}
89+
90+
// Get the test key from cluster
91+
clusterVal, err := clusterClient.Get(ctx, "test-key").Result()
92+
if err != nil {
93+
log.Fatalf("Failed to get test key from cluster: %v", err)
94+
}
95+
fmt.Printf("Retrieved value from cluster: %s\n", clusterVal)
6596
}

examples/entraid/managedidentity_system/main.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,20 @@ func main() {
3535
}
3636

3737
// Create Redis client with streaming credentials provider
38-
redisClient := redis.NewClusterClient(&redis.ClusterOptions{
39-
Addrs: []string{cfg.Endpoints["standalone-entraid-acl"].Endpoints[0]},
40-
StreamingCredentialsProvider: cp,
41-
})
38+
opts, err := redis.ParseURL(cfg.Endpoints["standalone-entraid-acl"].Endpoints[0])
39+
if err != nil {
40+
log.Fatalf("Failed to parse Redis URL: %v", err)
41+
}
42+
opts.StreamingCredentialsProvider = cp
43+
redisClient := redis.NewClient(opts)
4244

4345
// Create second Redis client for cluster
46+
clusterOpts, err := redis.ParseURL(cfg.Endpoints["cluster-entraid-acl"].Endpoints[0])
47+
if err != nil {
48+
log.Fatalf("Failed to parse Redis URL: %v", err)
49+
}
4450
clusterClient := redis.NewClusterClient(&redis.ClusterOptions{
45-
Addrs: cfg.Endpoints["cluster-entraid-acl"].Endpoints,
51+
Addrs: []string{clusterOpts.Addr},
4652
StreamingCredentialsProvider: cp,
4753
})
4854

examples/entraid/managedidentity_user/main.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,20 @@ func main() {
3838
}
3939

4040
// Create Redis client with streaming credentials provider
41-
redisClient := redis.NewClusterClient(&redis.ClusterOptions{
42-
Addrs: []string{cfg.Endpoints["standalone-entraid-acl"].Endpoints[0]},
43-
StreamingCredentialsProvider: cp,
44-
})
41+
opts, err := redis.ParseURL(cfg.Endpoints["standalone-entraid-acl"].Endpoints[0])
42+
if err != nil {
43+
log.Fatalf("Failed to parse Redis URL: %v", err)
44+
}
45+
opts.StreamingCredentialsProvider = cp
46+
redisClient := redis.NewClient(opts)
4547

4648
// Create second Redis client for cluster
49+
clusterOpts, err := redis.ParseURL(cfg.Endpoints["cluster-entraid-acl"].Endpoints[0])
50+
if err != nil {
51+
log.Fatalf("Failed to parse Redis URL: %v", err)
52+
}
4753
clusterClient := redis.NewClusterClient(&redis.ClusterOptions{
48-
Addrs: cfg.Endpoints["cluster-entraid-acl"].Endpoints,
54+
Addrs: []string{clusterOpts.Addr},
4955
StreamingCredentialsProvider: cp,
5056
})
5157

0 commit comments

Comments
 (0)