Categorygithub.com/doutivity/research-online-redis-go
modulepackage
0.0.0-20240331223523-bd7e63814a49
Repository: https://github.com/doutivity/research-online-redis-go.git
Documentation: pkg.go.dev

# README

Efficiently store online with Redis and Go

Support Ukraine 🇺🇦

Databases

NameStarsLanguage
Redis64300+C
KeyDB10100+C++
DragonflyDB23300+C++
Garnet7900+C#

Data structure usage examples

Hash

docker exec research-online-redis-1 redis-cli monitor
docker exec research-online-redis-go-app go test ./... -v -run=TestRedisHashOnlineStorage -count=1
flushall
hset "h:online:main" "10000001" "1679800725"
hset "h:online:main" "10000002" "1679800730"
hset "h:online:main" "10000003" "1679800735"
hlen "h:online:main"
rename "h:online:main" "h:online:tmp"
hgetall "h:online:tmp"

Sorted Set

docker exec research-online-redis-1 redis-cli monitor
docker exec research-online-redis-go-app go test ./... -v -run=TestRedisSortedSetOnlineStorage -count=1
flushall
zadd "z:online:main" "1679800725" "10000001"
zadd "z:online:main" "1679800730" "10000002"
zadd "z:online:main" "1679800735" "10000003"
zcard "z:online:main"
rename "z:online:main" "z:online:tmp"
zrange "z:online:tmp" "0" "-1" "withscores"

Set

docker exec research-online-redis-1 redis-cli monitor
docker exec research-online-redis-go-app go test ./... -v -run=TestRedisSetOnlineStorage -count=1
flushall
sadd "s:online:main:1679800725" "10000001"
sadd "s:online:main:1679800730" "10000002"
sadd "s:online:main:1679800735" "10000003"
keys "s:online:main:*"
scard "s:online:main:1679800730"
scard "s:online:main:1679800725"
scard "s:online:main:1679800735"
keys "s:online:main:*"
rename "s:online:main:1679800730" "s:online:tmp"
smembers "s:online:tmp"
rename "s:online:main:1679800725" "s:online:tmp"
smembers "s:online:tmp"
rename "s:online:main:1679800735" "s:online:tmp"
smembers "s:online:tmp"

Testing

make env-up
make test
make env-down
=== RUN   TestGoOnlineStorage
--- PASS: TestGoOnlineStorage (0.00s)
=== RUN   TestRedisHashOnlineStorage
--- PASS: TestRedisHashOnlineStorage (0.00s)
=== RUN   TestKeydbHashOnlineStorage
--- PASS: TestKeydbHashOnlineStorage (0.00s)
=== RUN   TestDragonflydbHashOnlineStorage
--- PASS: TestDragonflydbHashOnlineStorage (0.00s)
=== RUN   TestGarnetHashOnlineStorage
--- PASS: TestGarnetHashOnlineStorage (0.00s)
=== RUN   TestRedisPing
--- PASS: TestRedisPing (0.00s)
=== RUN   TestKeydbPing
--- PASS: TestKeydbPing (0.00s)
=== RUN   TestDragonflydbPing
--- PASS: TestDragonflydbPing (0.00s)
=== RUN   TestRedisSetOnlineStorage
--- PASS: TestRedisSetOnlineStorage (0.00s)
=== RUN   TestKeydbSetOnlineStorage
--- PASS: TestKeydbSetOnlineStorage (0.00s)
=== RUN   TestDragonflydbSetOnlineStorage
--- PASS: TestDragonflydbSetOnlineStorage (0.01s)
=== RUN   TestGarnetSetOnlineStorage
--- PASS: TestGarnetSetOnlineStorage (0.11s)
=== RUN   TestRedisSortedSetOnlineStorage
--- PASS: TestRedisSortedSetOnlineStorage (0.00s)
=== RUN   TestKeydbSortedSetOnlineStorage
--- PASS: TestKeydbSortedSetOnlineStorage (0.00s)
=== RUN   TestDragonflydbSortedSetOnlineStorage
--- PASS: TestDragonflydbSortedSetOnlineStorage (0.02s)
=== RUN   TestGarnetSortedSetOnlineStorage
--- PASS: TestGarnetSortedSetOnlineStorage (0.00s)
PASS
ok  	github.com/doutivity/research-online-redis-go	0.154s

Benchmark

make bench
# MODE=sequence go test ./... -v -bench='Go'                         -benchmem -benchtime=1000000x -count=5 | tee ./output/bench-go-1000000x-sequence.txt
# MODE=sequence go test ./... -v -bench='Redis(Hash|SortedSet|Set)'  -benchmem -benchtime=1000000x -count=5 | tee ./output/bench-redis-1000000x-sequence.txt
# MODE=sequence go test ./... -v -bench='Keydb(Hash|SortedSet|Set)'  -benchmem -benchtime=1000000x -count=5 | tee ./output/bench-keydb-1000000x-sequence.txt
# MODE=sequence go test ./... -v -bench='Dragonflydb(SortedSet|Set)' -benchmem -benchtime=1000000x -count=5 | tee ./output/bench-dragonflydb-1000000x-sequence.txt
# MODE=parallel go test ./... -v -bench='Go'                         -benchmem -benchtime=1000000x -count=5 | tee ./output/bench-go-1000000x-parallel.txt
# MODE=parallel go test ./... -v -bench='Redis(Hash|SortedSet|Set)'  -benchmem -benchtime=1000000x -count=5 | tee ./output/bench-redis-1000000x-parallel.txt
# MODE=parallel go test ./... -v -bench='Keydb(Hash|SortedSet|Set)'  -benchmem -benchtime=1000000x -count=5 | tee ./output/bench-keydb-1000000x-parallel.txt
# MODE=parallel go test ./... -v -bench='Dragonflydb(SortedSet|Set)' -benchmem -benchtime=1000000x -count=5 | tee ./output/bench-dragonflydb-1000000x-parallel.txt
# benchstat ./output/bench-go-1000000x-sequence.txt
# benchstat ./output/bench-redis-1000000x-sequence.txt
# benchstat ./output/bench-keydb-1000000x-sequence.txt
# benchstat ./output/bench-dragonflydb-1000000x-sequence.txt
# benchstat ./output/bench-go-1000000x-parallel.txt
# benchstat ./output/bench-redis-1000000x-parallel.txt
# benchstat ./output/bench-keydb-1000000x-parallel.txt
# benchstat ./output/bench-dragonflydb-1000000x-parallel.txt
Database nameData structuresequence time/opparallel time/op
Gomap[int]int515ns ± 9%696ns ± 8%
RedisHash33.5µs ± 6%13.9µs ±24%
KeyDBHash36.9µs ± 2%14.5µs ±23%
DragonflyDBHash44.0µs ± 2%13.6µs ±12%
RedisSorted Set34.4µs ± 1%13.5µs ± 6%
KeyDBSorted Set38.6µs ± 1%14.1µs ± 2%
DragonflyDBSorted Set52.9µs ±15%16.3µs ± 8%
RedisSet32.6µs ± 1%12.4µs ± 2%
KeyDBSet36.7µs ± 1%13.7µs ± 3%
DragonflyDBSet45.9µs ± 4%14.4µs ±16%

Used memory

make bench-redis-memory-1m
make bench-keydb-memory-1m
make bench-dragonflydb-memory-1m
# ...
make bench-redis-memory-25m
make bench-keydb-memory-25m
make bench-dragonflydb-memory-25m
# docker exec research-online-redis-1 redis-cli flushall
# docker exec -e MODE=parallel research-online-redis-go-app go test ./... -v -run=$^ -bench='Redis(Hash)' -benchmem -benchtime=25000000x -count=1
# docker exec research-online-redis-1 redis-cli info memory | tee ./output/redis-memory-hash-25m.txt
#
# docker exec research-online-redis-1 redis-cli flushall
# docker exec -e MODE=parallel research-online-redis-go-app go test ./... -v -run=$^ -bench='Redis(SortedSet)' -benchmem -benchtime=25000000x -count=1
# docker exec research-online-redis-1 redis-cli info memory | tee ./output/redis-memory-sorted-set-25m.txt
#
# docker exec research-online-redis-1 redis-cli flushall
# docker exec -e MODE=parallel research-online-redis-go-app go test ./... -v -run=$^ -bench='Redis(Set)' -benchmem -benchtime=25000000x -count=1
# docker exec research-online-redis-1 redis-cli info memory | tee ./output/redis-memory-set-25m.txt
Database nameData structureUsersMemory
RedisHash1 000 00062.64 MB
KeyDBHash1 000 00063.49 MB
DragonflyDBHash1 000 00061.51 MB
RedisHash10 000 000727.20 MB
KeyDBHash10 000 000728.14 MB
DragonflyDBHash10 000 000622.59 MB
RedisHash25 000 0001592.14 MB
KeyDBHash25 000 0001593.27 MB
DragonflyDBHash25 000 0001481.70 MB
RedisSorted Set1 000 00091.09 MB
KeyDBSorted Set1 000 00091.93 MB
DragonflyDBSorted Set1 000 000107.87 MB
RedisSorted Set10 000 0001011.78 MB
KeyDBSorted Set10 000 0001012.64 MB
DragonflyDBSorted Set10 000 0001161.64 MB
RedisSorted Set25 000 0002303.58 MB
KeyDBSorted Set25 000 0002304.70 MB
DragonflyDBSorted Set25 000 0002675.25 MB
RedisSet1 000 00048.14 MB
KeyDBSet1 000 00049.02 MB
DragonflyDBSet1 000 00032.60 MB
RedisSet10 000 000469.57 MB
KeyDBSet10 000 000471.44 MB
DragonflyDBSet10 000 000297.01 MB
RedisSet25 000 0001169.33 MB
KeyDBSet25 000 0001175.45 MB
DragonflyDBSet25 000 000unknown, cause store less then expected, 15276400 from 25000000

Batch insert 10k rows x 10k times benchmark

make bench-redis-memory-10k-batch-10k
make bench-keydb-memory-10k-batch-10k
make bench-dragonflydb-memory-10k-batch-10k
# docker exec research-online-redis-1 redis-cli flushall
# docker exec -e MODE=parallel -e BATCH=10000 research-online-redis-go-app go test ./... -v -run=$$^ -bench='Redis(Hash)' -benchmem -benchtime=10000x -count=1
# docker exec research-online-redis-1 redis-cli info memory | tee ./output/redis-memory-hash-10k-batch-10k.txt
#
# docker exec research-online-redis-1 redis-cli flushall
# docker exec -e MODE=parallel -e BATCH=10000 research-online-redis-go-app go test ./... -v -run=$$^ -bench='Redis(SortedSet)' -benchmem -benchtime=10000x -count=1
# docker exec research-online-redis-1 redis-cli info memory | tee ./output/redis-memory-sorted-set-10k-batch-10k.txt
#
# docker exec research-online-redis-1 redis-cli flushall
# docker exec -e MODE=parallel -e BATCH=10000 research-online-redis-go-app go test ./... -v -run=$$^ -bench='Redis(Set)' -benchmem -benchtime=10000x -count=1
# docker exec research-online-redis-1 redis-cli info memory | tee ./output/redis-memory-set-10k-batch-10k.txt
#
# docker exec research-online-redis-1 redis-cli flushall
Database nameData structureparallel time/op
RedisHash8232276 ns/op
KeyDBHash21357358 ns/op
DragonflyDBHash6716157 ns/op
RedisSorted Set12016807 ns/op
KeyDBSorted Set15114051 ns/op
DragonflyDBSorted Set9535106 ns/op
RedisSet3187424 ns/op
KeyDBSet3233770 ns/op
DragonflyDBSetunknown, cause store less then expected, 15622200 from 100000000
Database nameData structureMemory
RedisHash6.72 GB
KeyDBHash6.22 GB
DragonflyDBHash5.77 GB
RedisSorted Set9.00 GB
KeyDBSorted Set9.00 GB
DragonflyDBSorted Set10.44 GB
RedisSet4.58 GB
KeyDBSet4.59 GB
DragonflyDBSetunknown, cause store less then expected, 15622200 from 100000000

Star history of Redis vs KeyDB vs DragonflyDB

Star History Chart

Versions

docker pull redis:latest
docker pull eqalpha/keydb:latest
docker pull docker.dragonflydb.io/dragonflydb/dragonfly
docker pull ghcr.io/microsoft/garnet
docker image inspect redis:latest --format '{{.RepoDigests}} {{.Size}}'
docker image inspect eqalpha/keydb:latest --format '{{.RepoDigests}} {{.Size}}'
docker image inspect docker.dragonflydb.io/dragonflydb/dragonfly --format '{{.RepoDigests}} {{.Size}}'
docker image inspect ghcr.io/microsoft/garnet --format '{{.RepoDigests}} {{.Size}}'
Database nameDocker image sizeDocker image
Redis131.32 MBsha256:3134997edb04277814aa51a4175a588d45eb4299272f8eff2307bbf8b39e4d43
KeyDB130.39 MBsha256:6537505c42355ca1f571276bddf83f5b750f760f07b2a185a676481791e388ac
DragonflyDB106.65 MBsha256:48d7f1679a895702262808c83689df94b14d40c07401fad90723ad164d271150
Garnet196.50 MBsha256:0da3da0cd45d8a7084d670b7b1a96748cea40917ed054fc98840ce6e4036b97b

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author

# Type aliases

No description provided by the author