Skip to content

Commit a434c18

Browse files
authored
feat: add support for async redis writes (#13)
This PR introduces a new `Async bool` field to `Config{}` that allows async batching of cache IO in the backend, removing the cache backend (like Redis) being a bottleneck on hotpaths.
1 parent cb1ad8a commit a434c18

File tree

11 files changed

+830
-159
lines changed

11 files changed

+830
-159
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,35 @@ go get -u github.com/zerodha/fastcache/stores/goredis/v9
6363
// Clear the orders group. Multiple groups can be specified like: orders, positions ...
6464
g.DELETE("/orders/:order_id",auth(app.respcache.ClearGroup(handleDeleteMarketwatchItems, short, []string{"orders"})))
6565
```
66+
67+
## Dev Notes
68+
69+
### Running Tests
70+
71+
```shell
72+
go test -v github.com/zerodha/fastcache...
73+
```
74+
75+
### Running Cluster Tests
76+
77+
Cluster tests require testcontainers (and docker) to run redis containers.
78+
79+
Therefore, we have kept the cluster tests in a separate file and
80+
they are tagged with `clustertest`. If you want to run the cluster tests,
81+
you need to have docker installed and running.
82+
83+
84+
85+
86+
After that you can simply run the tests with the following command:
87+
88+
```shell
89+
go test -tags clustertest -v github.com/zerodha/fastcache...
90+
```
91+
92+
We also provide a `redis-cluster-docker-compose.yml` file that can be
93+
used to start a redis cluster for local testing.
94+
95+
```shell
96+
docker-compose -f redis-cluster-docker-compose.yml up -d
97+
```

go.work.sum

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
2+
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
3+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
4+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
5+
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
6+
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
7+
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
8+
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
9+
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
10+
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
11+
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
12+
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
13+
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
14+
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
15+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
16+
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=

stores/goredis/go.mod

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,69 @@ module github.com/zerodha/fastcache/stores/goredis/v9
33
go 1.18
44

55
require (
6-
github.com/alicebob/miniredis v2.5.0+incompatible
6+
github.com/alicebob/miniredis/v2 v2.33.0
77
github.com/redis/go-redis/v9 v9.5.1
88
github.com/stretchr/testify v1.9.0
9+
github.com/testcontainers/testcontainers-go v0.33.0
910
github.com/zerodha/fastcache/v4 v4.0.0
1011
)
1112

1213
require (
13-
github.com/alicebob/gopher-json v0.0.0-20180125190556-5a6b3ba71ee6 // indirect
14+
dario.cat/mergo v1.0.0 // indirect
15+
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
16+
github.com/Microsoft/go-winio v0.6.2 // indirect
17+
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
1418
github.com/andybalholm/brotli v1.0.4 // indirect
19+
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
1520
github.com/cespare/xxhash/v2 v2.2.0 // indirect
21+
github.com/containerd/containerd v1.7.18 // indirect
22+
github.com/containerd/log v0.1.0 // indirect
23+
github.com/containerd/platforms v0.2.1 // indirect
24+
github.com/cpuguy83/dockercfg v0.3.1 // indirect
1625
github.com/davecgh/go-spew v1.1.1 // indirect
1726
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
27+
github.com/distribution/reference v0.6.0 // indirect
28+
github.com/docker/docker v27.1.1+incompatible // indirect
29+
github.com/docker/go-connections v0.5.0 // indirect
30+
github.com/docker/go-units v0.5.0 // indirect
1831
github.com/fasthttp/router v1.4.5 // indirect
19-
github.com/gomodule/redigo v2.0.0+incompatible // indirect
20-
github.com/klauspost/compress v1.15.0 // indirect
32+
github.com/felixge/httpsnoop v1.0.4 // indirect
33+
github.com/go-logr/logr v1.4.1 // indirect
34+
github.com/go-logr/stdr v1.2.2 // indirect
35+
github.com/go-ole/go-ole v1.2.6 // indirect
36+
github.com/gogo/protobuf v1.3.2 // indirect
37+
github.com/google/uuid v1.6.0 // indirect
38+
github.com/klauspost/compress v1.17.4 // indirect
39+
github.com/kr/text v0.2.0 // indirect
40+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
41+
github.com/magiconair/properties v1.8.7 // indirect
42+
github.com/moby/docker-image-spec v1.3.1 // indirect
43+
github.com/moby/patternmatcher v0.6.0 // indirect
44+
github.com/moby/sys/sequential v0.5.0 // indirect
45+
github.com/moby/sys/user v0.1.0 // indirect
46+
github.com/moby/term v0.5.0 // indirect
47+
github.com/morikuni/aec v1.0.0 // indirect
48+
github.com/opencontainers/go-digest v1.0.0 // indirect
49+
github.com/opencontainers/image-spec v1.1.0 // indirect
50+
github.com/pkg/errors v0.9.1 // indirect
2151
github.com/pmezard/go-difflib v1.0.0 // indirect
52+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
2253
github.com/savsgio/gotils v0.0.0-20211223103454-d0aaa54c5899 // indirect
54+
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
55+
github.com/shoenig/go-m1cpu v0.1.6 // indirect
56+
github.com/sirupsen/logrus v1.9.3 // indirect
57+
github.com/tklauser/go-sysconf v0.3.12 // indirect
58+
github.com/tklauser/numcpus v0.6.1 // indirect
2359
github.com/valyala/bytebufferpool v1.0.0 // indirect
2460
github.com/valyala/fasthttp v1.34.0 // indirect
25-
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb // indirect
61+
github.com/yuin/gopher-lua v1.1.1 // indirect
62+
github.com/yusufpapurcu/wmi v1.2.3 // indirect
2663
github.com/zerodha/fastglue v1.7.1 // indirect
64+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
65+
go.opentelemetry.io/otel v1.24.0 // indirect
66+
go.opentelemetry.io/otel/metric v1.24.0 // indirect
67+
go.opentelemetry.io/otel/trace v1.24.0 // indirect
68+
golang.org/x/crypto v0.22.0 // indirect
69+
golang.org/x/sys v0.21.0 // indirect
2770
gopkg.in/yaml.v3 v3.0.1 // indirect
2871
)

0 commit comments

Comments
 (0)