1
0
mirror of https://github.com/redis/go-redis.git synced 2025-09-05 20:24:00 +03:00

Merge branch 'master' into ndyakov/CAE-1088-resp3-notification-handlers

This commit is contained in:
Nedyalko Dyakov
2025-08-18 22:11:06 +03:00
committed by GitHub
17 changed files with 135 additions and 40 deletions

View File

@@ -2412,6 +2412,77 @@ var _ = Describe("Commands", func() {
Expect(args).To(Equal(expectedArgs))
})
It("should IncrByFloat with edge cases", func() {
// Test with negative increment
set := client.Set(ctx, "key", "10.5", 0)
Expect(set.Err()).NotTo(HaveOccurred())
incrByFloat := client.IncrByFloat(ctx, "key", -2.3)
Expect(incrByFloat.Err()).NotTo(HaveOccurred())
Expect(incrByFloat.Val()).To(BeNumerically("~", 8.2, 0.0001))
// Test with zero increment (should return current value)
incrByFloat = client.IncrByFloat(ctx, "key", 0.0)
Expect(incrByFloat.Err()).NotTo(HaveOccurred())
Expect(incrByFloat.Val()).To(BeNumerically("~", 8.2, 0.0001))
// Test with very small increment (precision test)
incrByFloat = client.IncrByFloat(ctx, "key", 0.0001)
Expect(incrByFloat.Err()).NotTo(HaveOccurred())
Expect(incrByFloat.Val()).To(BeNumerically("~", 8.2001, 0.00001))
// Test with non-existent key (should start from 0)
incrByFloat = client.IncrByFloat(ctx, "nonexistent", 5.5)
Expect(incrByFloat.Err()).NotTo(HaveOccurred())
Expect(incrByFloat.Val()).To(Equal(5.5))
// Test with integer value stored as string
set = client.Set(ctx, "intkey", "42", 0)
Expect(set.Err()).NotTo(HaveOccurred())
incrByFloat = client.IncrByFloat(ctx, "intkey", 0.5)
Expect(incrByFloat.Err()).NotTo(HaveOccurred())
Expect(incrByFloat.Val()).To(Equal(42.5))
// Test with scientific notation
set = client.Set(ctx, "scikey", "1.5e2", 0)
Expect(set.Err()).NotTo(HaveOccurred())
incrByFloat = client.IncrByFloat(ctx, "scikey", 5.0)
Expect(incrByFloat.Err()).NotTo(HaveOccurred())
Expect(incrByFloat.Val()).To(Equal(155.0))
// Test with negative scientific notation
incrByFloat = client.IncrByFloat(ctx, "scikey", -1.5e1)
Expect(incrByFloat.Err()).NotTo(HaveOccurred())
Expect(incrByFloat.Val()).To(Equal(140.0))
// Test error case: non-numeric value
set = client.Set(ctx, "stringkey", "notanumber", 0)
Expect(set.Err()).NotTo(HaveOccurred())
incrByFloat = client.IncrByFloat(ctx, "stringkey", 1.0)
Expect(incrByFloat.Err()).To(HaveOccurred())
Expect(incrByFloat.Err().Error()).To(ContainSubstring("value is not a valid float"))
// Test with very large numbers
set = client.Set(ctx, "largekey", "1.7976931348623157e+308", 0)
Expect(set.Err()).NotTo(HaveOccurred())
// This should work as it's within float64 range
incrByFloat = client.IncrByFloat(ctx, "largekey", -1.0e+308)
Expect(incrByFloat.Err()).NotTo(HaveOccurred())
Expect(incrByFloat.Val()).To(BeNumerically("~", 7.976931348623157e+307, 1e+300))
// Test with very small numbers (near zero)
set = client.Set(ctx, "smallkey", "1e-10", 0)
Expect(set.Err()).NotTo(HaveOccurred())
incrByFloat = client.IncrByFloat(ctx, "smallkey", 1e-10)
Expect(incrByFloat.Err()).NotTo(HaveOccurred())
Expect(incrByFloat.Val()).To(BeNumerically("~", 2e-10, 1e-15))
})
})
Describe("hashes", func() {