TestDigestBasic validates that the Digest command returns a uint64 value
(t *testing.T)
| 30 | |
| 31 | // TestDigestBasic validates that the Digest command returns a uint64 value |
| 32 | func 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 |
| 76 | func TestSetIFDEQWithDigest(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…