MCPcopy
hub / github.com/redis/go-redis / TestDigestBasic

Function TestDigestBasic

digest_test.go:32–73  ·  view source on GitHub ↗

TestDigestBasic validates that the Digest command returns a uint64 value

(t *testing.T)

Source from the content-addressed store, hash-verified

30
31// TestDigestBasic validates that the Digest command returns a uint64 value
32func TestDigestBasic(t *testing.T) {
33 skipIfRedisBelow84(t)
34
35 ctx := context.Background()
36 client := redis.NewClient(&redis.Options{
37 Addr: "localhost:6379",
38 })
39 defer client.Close()
40
41 if err := client.Ping(ctx).Err(); err != nil {
42 t.Skipf("Redis not available: %v", err)
43 }
44
45 client.Del(ctx, "digest-test-key")
46
47 // Set a value
48 err := client.Set(ctx, "digest-test-key", "testvalue", 0).Err()
49 if err != nil {
50 t.Fatalf("Failed to set value: %v", err)
51 }
52
53 // Get digest
54 digestCmd := client.Digest(ctx, "digest-test-key")
55 if err := digestCmd.Err(); err != nil {
56 t.Fatalf("Failed to get digest: %v", err)
57 }
58
59 digest := digestCmd.Val()
60 if digest == 0 {
61 t.Error("Digest should not be zero for non-empty value")
62 }
63
64 t.Logf("Digest for 'testvalue': %d (0x%016x)", digest, digest)
65
66 // Verify same value produces same digest
67 digest2 := client.Digest(ctx, "digest-test-key").Val()
68 if digest != digest2 {
69 t.Errorf("Same value should produce same digest: %d != %d", digest, digest2)
70 }
71
72 client.Del(ctx, "digest-test-key")
73}
74
75// TestSetIFDEQWithDigest validates the SetIFDEQ command works with digests
76func TestSetIFDEQWithDigest(t *testing.T) {

Callers

nothing calls this directly

Calls 9

skipIfRedisBelow84Function · 0.85
CloseMethod · 0.65
ErrMethod · 0.65
PingMethod · 0.65
DelMethod · 0.65
SetMethod · 0.65
DigestMethod · 0.65
ValMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…