Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix v1.6 problems #22

Merged
merged 6 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions base/ticker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

// Ticker
type Ticker struct {
ticker *time.Timer
ticker *time.Ticker
ctx context.Context
f func()
reset chan struct{}
Expand All @@ -20,7 +20,7 @@ func NewTicker(ctx context.Context, interval time.Duration, f func()) *Ticker {
}

t := &Ticker{
ticker: time.NewTimer(interval),
ticker: time.NewTicker(interval),
ctx: ctx,
f: f,
reset: make(chan struct{}),
Expand Down
9 changes: 0 additions & 9 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,6 @@ func (c *Client) Remove(keys ...string) (int, error) {
return base.ParseInt[int](args), nil
}

// Rename
func (c *Client) Rename(key, newKey string) (bool, error) {
args, err := c.do(NewCodec(OpRename).Str(key).Str(newKey))
if err != nil {
return false, err
}
return args[0] == _true, nil
}

// Get
func (c *Client) Get(key string) ([]byte, error) {
return c.do(NewCodec(OpGet).Str(key))
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/sakeven/RbTree v0.0.0-20220710124251-94e35f9fed6c
github.com/sourcegraph/conc v0.3.0
github.com/stretchr/testify v1.8.4
github.com/xgzlucario/GigaCache v0.0.0-20231022133204-b0a967d404cb
github.com/xgzlucario/GigaCache v0.0.0-20231106153843-1c6e60f7fbe0
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
)

Expand All @@ -22,17 +22,17 @@ require (
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dolthub/maphash v0.1.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/mschoch/smat v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/arch v0.5.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/arch v0.6.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.14.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ github.com/dolthub/maphash v0.1.0/go.mod h1:gkg4Ch4CdCDu5h6PMriVLawB7koZ+5ijb9pu
github.com/dolthub/swiss v0.2.1 h1:gs2osYs5SJkAaH5/ggVJqXQxRXtWshF6uE0lgR/Y3Gw=
github.com/dolthub/swiss v0.2.1/go.mod h1:8AhKZZ1HK7g18j7v7k6c5cYIGEZJcPn0ARsai8cUrh0=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg=
github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/48xc=
github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
Expand Down Expand Up @@ -60,8 +60,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/xgzlucario/GigaCache v0.0.0-20231022133204-b0a967d404cb h1:HqKnS65YqDtZtDNwKDRMIiZKfV3eFWYuomKban0KY+k=
github.com/xgzlucario/GigaCache v0.0.0-20231022133204-b0a967d404cb/go.mod h1:n0gu6svrq5UYwUWv8RRYgt06u8e5E3AMNg5eqflP74Y=
github.com/xgzlucario/GigaCache v0.0.0-20231106153843-1c6e60f7fbe0 h1:0D0QVBK17VlWGnpNaRGDciruNkuzu9wE7zjt8z1jBGo=
github.com/xgzlucario/GigaCache v0.0.0-20231106153843-1c6e60f7fbe0/go.mod h1:ekx7bzT2n6Y0XNen9lVE39kKNaDEl27AaGl6iKNj7hw=
github.com/zeebo/assert v1.3.1 h1:vukIABvugfNMZMQO1ABsyQDJDTVQbn+LWSMy1ol1h6A=
github.com/zeebo/assert v1.3.1/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0=
Expand All @@ -73,15 +73,15 @@ go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN8
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.5.0 h1:jpGode6huXQxcskEIpOCvrU+tzo81b6+oFLUYXWtH/Y=
golang.org/x/arch v0.5.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.6.0 h1:S0JTfE48HbRj80+4tbvZDYsJ3tGv6BUU3XxyZ7CirAc=
golang.org/x/arch v0.6.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
35 changes: 9 additions & 26 deletions rotom.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"log/slog"
"os"
"reflect"
"runtime"
"runtime/debug"
"strconv"
Expand All @@ -29,7 +28,6 @@ const (
OpGet
OpRemove
OpIncr
OpRename
OpLen
// map
OpHSet
Expand Down Expand Up @@ -92,7 +90,7 @@ var cmdTable = []Cmd{

switch Type {
case TypeString:
e.m.SetTx(string(args[1]), args[3], ts)
e.SetTx(string(args[1]), args[3], ts)

case TypeList:
ls := structx.NewList[string]()
Expand Down Expand Up @@ -161,11 +159,6 @@ var cmdTable = []Cmd{
}
return w.Write(res)
}},
{OpRename, 2, func(e *Engine, args [][]byte, w base.Writer) error {
// old, new
ok := e.Rename(string(args[0]), string(args[1]))
return w.WriteByte(bool2byte(ok))
}},
{OpLen, 0, func(e *Engine, args [][]byte, w base.Writer) error {
return w.Write(base.FormatInt(e.Stat().Len))
}},
Expand Down Expand Up @@ -631,12 +624,6 @@ func (e *Engine) Remove(keys ...string) int {
return sum
}

// Rename
func (e *Engine) Rename(old, new string) bool {
e.encode(NewCodec(OpRename).Str(old).Str(new))
return e.m.Rename(old, new)
}

// Keys
func (e *Engine) Keys() []string {
return e.m.Keys()
Expand Down Expand Up @@ -1078,9 +1065,9 @@ func (e *Engine) load() error {
func (e *Engine) shrink() {
var _type Type
data, err := e.m.MarshalBytesFunc(func(key string, v any, i int64) {
switch v := v.(type) {
switch v.(type) {
case Map:
_type = TypeString
_type = TypeMap
case BitMap:
_type = TypeBitmap
case List:
Expand All @@ -1089,8 +1076,6 @@ func (e *Engine) shrink() {
_type = TypeSet
case ZSet:
_type = TypeZSet
default:
panic(fmt.Errorf("%w: %d", base.ErrUnSupportDataType, v))
}
// SetTx
if cd, err := NewCodec(OpSetTx).Type(_type).Str(key).Int(i / timeCarry).Any(v); err == nil {
Expand Down Expand Up @@ -1159,21 +1144,19 @@ func (e *Engine) fetchZSet(key string, setnx ...bool) (z ZSet, err error) {
}

// fetch
func fetch[T any](e *Engine, key string, new func() T, setnx ...bool) (v T, err error) {
m, _, ok := e.m.Get(key)
func fetch[T any](e *Engine, key string, new func() T, setnx ...bool) (T, error) {
item, _, ok := e.m.Get(key)
if ok {
m, ok := m.(T)
v, ok := item.(T)
if ok {
return m, nil
return v, nil
}
return v, fmt.Errorf("%w: %v->%v", base.ErrWrongType, reflect.TypeOf(m), reflect.TypeOf(v))
return v, fmt.Errorf("%w: %T->%T", base.ErrWrongType, item, v)
}

v = new()
v := new()
if len(setnx) > 0 && setnx[0] {
e.m.Set(key, v)
}

return v, nil
}

Expand Down
Loading