Skip to content

Commit

Permalink
Refactor storage. it more simple now
Browse files Browse the repository at this point in the history
  • Loading branch information
diiyw committed Aug 12, 2024
1 parent 6f66847 commit 7f3631d
Show file tree
Hide file tree
Showing 30 changed files with 870 additions and 1,435 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ Nodis is a Redis implementation using the Golang programming language. This impl

- **Fast and Embeddable**: The Golang-based implementation is designed to be fast and easily embeddable within your applications.
- **Low Memory Usage**: The system only stores hot data in memory, minimizing the overall memory footprint.
- **Snapshot and WAL for Data Storage**: This Redis implementation supports snapshot and write-ahead logging (WAL) mechanisms for reliable data storage.
- **Custom Data Storage Backends**: You can integrate custom data storage backends, such as Amazon S3, browser-based storage, and more.
- **Custom Data Storage Backends**: You can integrate custom data storage backends, such as Amazon S3,sqlite, browser-based storage, and more.
- **Browser Support with WebAssembly**: Starting from version 1.2.0, this Redis implementation can run directly in the browser using WebAssembly.
- **Remote Change Monitoring**: From version 1.2.0 onwards, the system supports watching for changes from remote sources.
- **Redis Protocol Compatibility**: As of version 1.5.0, this Redis implementation fully supports the original Redis protocol, ensuring seamless integration with existing Redis clients.
Expand Down
50 changes: 10 additions & 40 deletions bench/nodis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import (
)

func BenchmarkSet(b *testing.B) {
n := nodis.Open(&nodis.Options{
Path: "../testdata/set",
FileSize: nodis.FileSizeGB,
})
n := nodis.Open(&nodis.Options{})
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
Expand All @@ -21,10 +18,7 @@ func BenchmarkSet(b *testing.B) {
}

func BenchmarkGet(b *testing.B) {
n := nodis.Open(&nodis.Options{
Path: "../testdata/get",
FileSize: nodis.FileSizeGB,
})
n := nodis.Open(&nodis.Options{})
for i := 0; i < 100000; i++ {
id := strconv.Itoa(i)
n.Set(id, []byte("value"+id), false)
Expand All @@ -38,10 +32,7 @@ func BenchmarkGet(b *testing.B) {
}

func BenchmarkLPush(b *testing.B) {
n := nodis.Open(&nodis.Options{
Path: "../testdata/lPush",
FileSize: nodis.FileSizeGB,
})
n := nodis.Open(&nodis.Options{})
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
Expand All @@ -51,10 +42,7 @@ func BenchmarkLPush(b *testing.B) {
}

func BenchmarkLPop(b *testing.B) {
n := nodis.Open(&nodis.Options{
Path: "../testdata/lPop",
FileSize: nodis.FileSizeGB,
})
n := nodis.Open(&nodis.Options{})
for i := 0; i < 100000; i++ {
id := strconv.Itoa(i)
n.LPush("test", []byte("value"+id))
Expand All @@ -67,10 +55,7 @@ func BenchmarkLPop(b *testing.B) {
}

func BenchmarkSAdd(b *testing.B) {
n := nodis.Open(&nodis.Options{
Path: "../testdata/sAdd",
FileSize: nodis.FileSizeGB,
})
n := nodis.Open(&nodis.Options{})
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
Expand All @@ -80,10 +65,7 @@ func BenchmarkSAdd(b *testing.B) {
}

func BenchmarkSMembers(b *testing.B) {
n := nodis.Open(&nodis.Options{
Path: "../testdata/sMembers",
FileSize: nodis.FileSizeGB,
})
n := nodis.Open(&nodis.Options{})
for i := 0; i < 100000; i++ {
id := strconv.Itoa(i)
n.SAdd(id, "value"+id)
Expand All @@ -97,10 +79,7 @@ func BenchmarkSMembers(b *testing.B) {
}

func BenchmarkZAdd(b *testing.B) {
n := nodis.Open(&nodis.Options{
Path: "../testdata/zAdd",
FileSize: nodis.FileSizeGB,
})
n := nodis.Open(&nodis.Options{})
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
Expand All @@ -110,10 +89,7 @@ func BenchmarkZAdd(b *testing.B) {
}

func BenchmarkZRank(b *testing.B) {
n := nodis.Open(&nodis.Options{
Path: "../testdata/zRank",
FileSize: nodis.FileSizeGB,
})
n := nodis.Open(&nodis.Options{})
for i := 0; i < 100000; i++ {
id := strconv.Itoa(i)
n.ZAdd(id, "value"+id, float64(i))
Expand All @@ -127,10 +103,7 @@ func BenchmarkZRank(b *testing.B) {
}

func BenchmarkHSet(b *testing.B) {
n := nodis.Open(&nodis.Options{
Path: "../testdata/hSet",
FileSize: nodis.FileSizeGB,
})
n := nodis.Open(&nodis.Options{})
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
Expand All @@ -140,10 +113,7 @@ func BenchmarkHSet(b *testing.B) {
}

func BenchmarkHGet(b *testing.B) {
n := nodis.Open(&nodis.Options{
Path: "../testdata/hGet",
FileSize: nodis.FileSizeGB,
})
n := nodis.Open(&nodis.Options{})
for i := 0; i < 100000; i++ {
id := strconv.Itoa(i)
n.HSet(id, "field"+id, []byte("value"+id))
Expand Down
2 changes: 0 additions & 2 deletions cmd/nodis-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"github.com/diiyw/nodis/fs"
"net"
"os"

Expand All @@ -20,7 +19,6 @@ func main() {
}
}
opt := nodis.DefaultOptions
opt.Filesystem = &fs.Disk{}
n := nodis.Open(opt)
if err := n.Serve(addr); err != nil {
fmt.Printf("Serve() = %v", err)
Expand Down
10 changes: 10 additions & 0 deletions ds/ds.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
package ds

type Key struct {
Name string
Expiration int64
}

// NewKey returns a new key.
func NewKey(name string, expiration int64) *Key {
return &Key{Name: name, Expiration: expiration}
}

type Value interface {
Type() ValueType
GetValue() []byte
Expand Down
70 changes: 0 additions & 70 deletions entry.go

This file was deleted.

58 changes: 0 additions & 58 deletions entry_test.go

This file was deleted.

29 changes: 29 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,32 @@ require (
github.com/tidwall/btree v1.7.0
google.golang.org/protobuf v1.34.2
)

require (
github.com/DataDog/zstd v1.4.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cockroachdb/errors v1.11.3 // indirect
github.com/cockroachdb/fifo v0.0.0-20240606204812-0bbfbd93a7ce // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/pebble v1.1.1 // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/getsentry/sentry-go v0.27.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.12.0 // indirect
github.com/prometheus/client_model v0.2.1-0.20210607210712-147c58e9608a // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
)
Loading

0 comments on commit 7f3631d

Please sign in to comment.