eko / gocache

☔️ A complete Go cache library that brings you multiple ways of managing your caches
https://vincent.composieux.fr/article/i-wrote-gocache-a-complete-and-extensible-go-cache-library/
MIT License
2.42k stars 192 forks source link

Make rueidis store to be more user-friendly and be more performant #188

Closed rueian closed 1 year ago

rueian commented 1 year ago

Hi @eko, @rwrz,

Following https://github.com/eko/gocache/issues/187, I made some breaking changes in this PR:

  1. Make Get() and GetWithTTL() return go string instead of rueidis.RedisResult to be more user-friendly.
  2. Make Set() only accept go string value, since Get() also returns go string.
  3. Make GetWithTTL() retrive client-side TTL without additional network roundtrip.

And some improvements:

  1. Pipeline SADD and EXPIRE while setting key tags to reduce network roundtrips.
  2. Not to cache SMEMBERS while doing Invalidate(), since it will also be invalidated soon.

I also re-run the BenchmarkRueidisSet:

BEFORE:

goos: darwin
goarch: arm64
pkg: github.com/eko/gocache/store/rueidis/v4
BenchmarkRueidisSet
BenchmarkRueidisSet/1
BenchmarkRueidisSet/1-10       18704         61512 ns/op
BenchmarkRueidisSet/2
BenchmarkRueidisSet/2-10        9661        124730 ns/op
BenchmarkRueidisSet/4
BenchmarkRueidisSet/4-10        4776        247294 ns/op
BenchmarkRueidisSet/8
BenchmarkRueidisSet/8-10        2469        491906 ns/op
BenchmarkRueidisSet/16
BenchmarkRueidisSet/16-10       1213        982676 ns/op
BenchmarkRueidisSet/32
BenchmarkRueidisSet/32-10        607       1964616 ns/op
BenchmarkRueidisSet/64
BenchmarkRueidisSet/64-10        303       3930002 ns/op
BenchmarkRueidisSet/128
BenchmarkRueidisSet/128-10               152       7860255 ns/op
BenchmarkRueidisSet/256
BenchmarkRueidisSet/256-10                74      15707281 ns/op
BenchmarkRueidisSet/512
BenchmarkRueidisSet/512-10                37      31525639 ns/op
BenchmarkRueidisSet/1024
BenchmarkRueidisSet/1024-10               18      63099289 ns/op
PASS

AFTER:

goos: darwin
goarch: arm64
pkg: github.com/eko/gocache/store/rueidis/v4
BenchmarkRueidisSet
BenchmarkRueidisSet/1
BenchmarkRueidisSet/1-10       27085         42312 ns/op
BenchmarkRueidisSet/2
BenchmarkRueidisSet/2-10       14272         84054 ns/op
BenchmarkRueidisSet/4
BenchmarkRueidisSet/4-10        7027        167840 ns/op
BenchmarkRueidisSet/8
BenchmarkRueidisSet/8-10        3525        330211 ns/op
BenchmarkRueidisSet/16
BenchmarkRueidisSet/16-10       1774        660522 ns/op
BenchmarkRueidisSet/32
BenchmarkRueidisSet/32-10        891       1321188 ns/op
BenchmarkRueidisSet/64
BenchmarkRueidisSet/64-10        445       2615865 ns/op
BenchmarkRueidisSet/128
BenchmarkRueidisSet/128-10               224       5278540 ns/op
BenchmarkRueidisSet/256
BenchmarkRueidisSet/256-10               100      10586973 ns/op
BenchmarkRueidisSet/512
BenchmarkRueidisSet/512-10                54      21222888 ns/op
BenchmarkRueidisSet/1024
BenchmarkRueidisSet/1024-10               27      42436995 ns/op
PASS
eko commented 1 year ago

Thank you so much @rueian!