Skip to content

Commit bb66bdd

Browse files
authored
Merge branch 'master' into failover-readonly
2 parents 0ed1576 + ff4d63e commit bb66bdd

File tree

12 files changed

+124
-30
lines changed

12 files changed

+124
-30
lines changed

.github/actions/run-tests/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ runs:
2525
2626
# Mapping of redis version to redis testing containers
2727
declare -A redis_version_mapping=(
28-
["8.2.x"]="8.2"
28+
["8.2.x"]="8.2.1-pre"
2929
["8.0.x"]="8.0.2"
3030
["7.4.x"]="rs-7.4.0-v5"
3131
["7.2.x"]="rs-7.2.0-v17"

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
4545
# Mapping of redis version to redis testing containers
4646
declare -A redis_version_mapping=(
47-
["8.2.x"]="8.2"
47+
["8.2.x"]="8.2.1-pre"
4848
["8.0.x"]="8.0.2"
4949
["7.4.x"]="rs-7.4.0-v5"
5050
)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ func main() {
301301
302302
### Buffer Size Configuration
303303
304-
go-redis uses 0.5MiB read and write buffers by default for optimal performance. For high-throughput applications or large pipelines, you can customize buffer sizes:
304+
go-redis uses 32KiB read and write buffers by default for optimal performance. For high-throughput applications or large pipelines, you can customize buffer sizes:
305305
306306
```go
307307
rdb := redis.NewClient(&redis.Options{
@@ -376,7 +376,7 @@ You can find further details in the [query dialect documentation](https://redis.
376376
377377
#### Custom buffer sizes
378378
Prior to v9.12, the buffer size was the default go value of 4096 bytes. Starting from v9.12,
379-
go-redis uses 256KiB read and write buffers by default for optimal performance.
379+
go-redis uses 32KiB read and write buffers by default for optimal performance.
380380
For high-throughput applications or large pipelines, you can customize buffer sizes:
381381
382382
```go

commands_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,6 +2412,77 @@ var _ = Describe("Commands", func() {
24122412

24132413
Expect(args).To(Equal(expectedArgs))
24142414
})
2415+
2416+
It("should IncrByFloat with edge cases", func() {
2417+
// Test with negative increment
2418+
set := client.Set(ctx, "key", "10.5", 0)
2419+
Expect(set.Err()).NotTo(HaveOccurred())
2420+
2421+
incrByFloat := client.IncrByFloat(ctx, "key", -2.3)
2422+
Expect(incrByFloat.Err()).NotTo(HaveOccurred())
2423+
Expect(incrByFloat.Val()).To(BeNumerically("~", 8.2, 0.0001))
2424+
2425+
// Test with zero increment (should return current value)
2426+
incrByFloat = client.IncrByFloat(ctx, "key", 0.0)
2427+
Expect(incrByFloat.Err()).NotTo(HaveOccurred())
2428+
Expect(incrByFloat.Val()).To(BeNumerically("~", 8.2, 0.0001))
2429+
2430+
// Test with very small increment (precision test)
2431+
incrByFloat = client.IncrByFloat(ctx, "key", 0.0001)
2432+
Expect(incrByFloat.Err()).NotTo(HaveOccurred())
2433+
Expect(incrByFloat.Val()).To(BeNumerically("~", 8.2001, 0.00001))
2434+
2435+
// Test with non-existent key (should start from 0)
2436+
incrByFloat = client.IncrByFloat(ctx, "nonexistent", 5.5)
2437+
Expect(incrByFloat.Err()).NotTo(HaveOccurred())
2438+
Expect(incrByFloat.Val()).To(Equal(5.5))
2439+
2440+
// Test with integer value stored as string
2441+
set = client.Set(ctx, "intkey", "42", 0)
2442+
Expect(set.Err()).NotTo(HaveOccurred())
2443+
2444+
incrByFloat = client.IncrByFloat(ctx, "intkey", 0.5)
2445+
Expect(incrByFloat.Err()).NotTo(HaveOccurred())
2446+
Expect(incrByFloat.Val()).To(Equal(42.5))
2447+
2448+
// Test with scientific notation
2449+
set = client.Set(ctx, "scikey", "1.5e2", 0)
2450+
Expect(set.Err()).NotTo(HaveOccurred())
2451+
2452+
incrByFloat = client.IncrByFloat(ctx, "scikey", 5.0)
2453+
Expect(incrByFloat.Err()).NotTo(HaveOccurred())
2454+
Expect(incrByFloat.Val()).To(Equal(155.0))
2455+
2456+
// Test with negative scientific notation
2457+
incrByFloat = client.IncrByFloat(ctx, "scikey", -1.5e1)
2458+
Expect(incrByFloat.Err()).NotTo(HaveOccurred())
2459+
Expect(incrByFloat.Val()).To(Equal(140.0))
2460+
2461+
// Test error case: non-numeric value
2462+
set = client.Set(ctx, "stringkey", "notanumber", 0)
2463+
Expect(set.Err()).NotTo(HaveOccurred())
2464+
2465+
incrByFloat = client.IncrByFloat(ctx, "stringkey", 1.0)
2466+
Expect(incrByFloat.Err()).To(HaveOccurred())
2467+
Expect(incrByFloat.Err().Error()).To(ContainSubstring("value is not a valid float"))
2468+
2469+
// Test with very large numbers
2470+
set = client.Set(ctx, "largekey", "1.7976931348623157e+308", 0)
2471+
Expect(set.Err()).NotTo(HaveOccurred())
2472+
2473+
// This should work as it's within float64 range
2474+
incrByFloat = client.IncrByFloat(ctx, "largekey", -1.0e+308)
2475+
Expect(incrByFloat.Err()).NotTo(HaveOccurred())
2476+
Expect(incrByFloat.Val()).To(BeNumerically("~", 7.976931348623157e+307, 1e+300))
2477+
2478+
// Test with very small numbers (near zero)
2479+
set = client.Set(ctx, "smallkey", "1e-10", 0)
2480+
Expect(set.Err()).NotTo(HaveOccurred())
2481+
2482+
incrByFloat = client.IncrByFloat(ctx, "smallkey", 1e-10)
2483+
Expect(incrByFloat.Err()).NotTo(HaveOccurred())
2484+
Expect(incrByFloat.Val()).To(BeNumerically("~", 2e-10, 1e-15))
2485+
})
24152486
})
24162487

24172488
Describe("hashes", func() {

internal/pool/buffer_size_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ var _ = Describe("Buffer Size Configuration", func() {
3434
Expect(err).NotTo(HaveOccurred())
3535
defer connPool.CloseConn(cn)
3636

37-
// Check that default buffer sizes are used (256KiB)
37+
// Check that default buffer sizes are used (32KiB)
3838
writerBufSize := getWriterBufSizeUnsafe(cn)
3939
readerBufSize := getReaderBufSizeUnsafe(cn)
4040

41-
Expect(writerBufSize).To(Equal(proto.DefaultBufferSize)) // Default 256KiB buffer size
42-
Expect(readerBufSize).To(Equal(proto.DefaultBufferSize)) // Default 256KiB buffer size
41+
Expect(writerBufSize).To(Equal(proto.DefaultBufferSize)) // Default 32KiB buffer size
42+
Expect(readerBufSize).To(Equal(proto.DefaultBufferSize)) // Default 32KiB buffer size
4343
})
4444

4545
It("should use custom buffer sizes when specified", func() {
@@ -79,28 +79,28 @@ var _ = Describe("Buffer Size Configuration", func() {
7979
Expect(err).NotTo(HaveOccurred())
8080
defer connPool.CloseConn(cn)
8181

82-
// Check that default buffer sizes are used (256KiB)
82+
// Check that default buffer sizes are used (32KiB)
8383
writerBufSize := getWriterBufSizeUnsafe(cn)
8484
readerBufSize := getReaderBufSizeUnsafe(cn)
8585

86-
Expect(writerBufSize).To(Equal(proto.DefaultBufferSize)) // Default 256KiB buffer size
87-
Expect(readerBufSize).To(Equal(proto.DefaultBufferSize)) // Default 256KiB buffer size
86+
Expect(writerBufSize).To(Equal(proto.DefaultBufferSize)) // Default 32KiB buffer size
87+
Expect(readerBufSize).To(Equal(proto.DefaultBufferSize)) // Default 32KiB buffer size
8888
})
8989

90-
It("should use 256KiB default buffer sizes for standalone NewConn", func() {
91-
// Test that NewConn (without pool) also uses 256KiB buffers
90+
It("should use 32KiB default buffer sizes for standalone NewConn", func() {
91+
// Test that NewConn (without pool) also uses 32KiB buffers
9292
netConn := newDummyConn()
9393
cn := pool.NewConn(netConn)
9494
defer cn.Close()
9595

9696
writerBufSize := getWriterBufSizeUnsafe(cn)
9797
readerBufSize := getReaderBufSizeUnsafe(cn)
9898

99-
Expect(writerBufSize).To(Equal(proto.DefaultBufferSize)) // Default 256KiB buffer size
100-
Expect(readerBufSize).To(Equal(proto.DefaultBufferSize)) // Default 256KiB buffer size
99+
Expect(writerBufSize).To(Equal(proto.DefaultBufferSize)) // Default 32KiB buffer size
100+
Expect(readerBufSize).To(Equal(proto.DefaultBufferSize)) // Default 32KiB buffer size
101101
})
102102

103-
It("should use 256KiB defaults even when pool is created directly without buffer sizes", func() {
103+
It("should use 32KiB defaults even when pool is created directly without buffer sizes", func() {
104104
// Test the scenario where someone creates a pool directly (like in tests)
105105
// without setting ReadBufferSize and WriteBufferSize
106106
connPool = pool.NewConnPool(&pool.Options{
@@ -114,12 +114,12 @@ var _ = Describe("Buffer Size Configuration", func() {
114114
Expect(err).NotTo(HaveOccurred())
115115
defer connPool.CloseConn(cn)
116116

117-
// Should still get 256KiB defaults because NewConnPool sets them
117+
// Should still get 32KiB defaults because NewConnPool sets them
118118
writerBufSize := getWriterBufSizeUnsafe(cn)
119119
readerBufSize := getReaderBufSizeUnsafe(cn)
120120

121-
Expect(writerBufSize).To(Equal(proto.DefaultBufferSize)) // Default 256KiB buffer size
122-
Expect(readerBufSize).To(Equal(proto.DefaultBufferSize)) // Default 256KiB buffer size
121+
Expect(writerBufSize).To(Equal(proto.DefaultBufferSize)) // Default 32KiB buffer size
122+
Expect(readerBufSize).To(Equal(proto.DefaultBufferSize)) // Default 32KiB buffer size
123123
})
124124
})
125125

internal/pool/conn.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ func NewConnWithBufferSize(netConn net.Conn, readBufSize, writeBufSize int) *Con
3737
createdAt: time.Now(),
3838
}
3939

40-
// Use specified buffer sizes, or fall back to 0.5MiB defaults if 0
40+
// Use specified buffer sizes, or fall back to 32KiB defaults if 0
4141
if readBufSize > 0 {
4242
cn.rd = proto.NewReaderSize(netConn, readBufSize)
4343
} else {
44-
cn.rd = proto.NewReader(netConn) // Uses 0.5MiB default
44+
cn.rd = proto.NewReader(netConn) // Uses 32KiB default
4545
}
4646

4747
if writeBufSize > 0 {

internal/proto/reader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
"github.com/redis/go-redis/v9/internal/util"
1313
)
1414

15-
// DefaultBufferSize is the default size for read/write buffers (256 KiB).
16-
const DefaultBufferSize = 256 * 1024
15+
// DefaultBufferSize is the default size for read/write buffers (32 KiB).
16+
const DefaultBufferSize = 32 * 1024
1717

1818
// redis resp protocol data type.
1919
const (

options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ type Options struct {
135135
// Larger buffers can improve performance for commands that return large responses.
136136
// Smaller buffers can improve memory usage for larger pools.
137137
//
138-
// default: 256KiB (262144 bytes)
138+
// default: 32KiB (32768 bytes)
139139
ReadBufferSize int
140140

141141
// WriteBufferSize is the size of the bufio.Writer buffer for each connection.
142142
// Larger buffers can improve performance for large pipelines and commands with many arguments.
143143
// Smaller buffers can improve memory usage for larger pools.
144144
//
145-
// default: 256KiB (262144 bytes)
145+
// default: 32KiB (32768 bytes)
146146
WriteBufferSize int
147147

148148
// PoolFIFO type of connection pool.

osscluster.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ type ClusterOptions struct {
9696
// Larger buffers can improve performance for commands that return large responses.
9797
// Smaller buffers can improve memory usage for larger pools.
9898
//
99-
// default: 256KiB (262144 bytes)
99+
// default: 32KiB (32768 bytes)
100100
ReadBufferSize int
101101

102102
// WriteBufferSize is the size of the bufio.Writer buffer for each connection.
103103
// Larger buffers can improve performance for large pipelines and commands with many arguments.
104104
// Smaller buffers can improve memory usage for larger pools.
105105
//
106-
// default: 256KiB (262144 bytes)
106+
// default: 32KiB (32768 bytes)
107107
WriteBufferSize int
108108

109109
TLSConfig *tls.Config

ring.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ type RingOptions struct {
128128
// Larger buffers can improve performance for commands that return large responses.
129129
// Smaller buffers can improve memory usage for larger pools.
130130
//
131-
// default: 256KiB (262144 bytes)
131+
// default: 32KiB (32768 bytes)
132132
ReadBufferSize int
133133

134134
// WriteBufferSize is the size of the bufio.Writer buffer for each connection.
135135
// Larger buffers can improve performance for large pipelines and commands with many arguments.
136136
// Smaller buffers can improve memory usage for larger pools.
137137
//
138-
// default: 256KiB (262144 bytes)
138+
// default: 32KiB (32768 bytes)
139139
WriteBufferSize int
140140

141141
TLSConfig *tls.Config

0 commit comments

Comments
 (0)