Skip to content

Commit

Permalink
chore:golint
Browse files Browse the repository at this point in the history
  • Loading branch information
zenghur committed Apr 7, 2020
1 parent 3ab6cc2 commit 4193569
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion entry/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Entry struct {
localExp time.Duration
data []byte
ttl float64
loadFrom int
loadFrom int
codec codec.Codec
enableLocalCache bool
}
Expand Down
2 changes: 1 addition & 1 deletion entry/load_source.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package entry

const (
_ int = iota
_ int = iota
SourceLocal
SourceCenter
)
2 changes: 2 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package freesia

// Error 错误类型
type Error string

// Error 错误接口
func (e Error) Error() string {
return string(e)
}
13 changes: 9 additions & 4 deletions freesia.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ package freesia

import (
"context"
"os"

"github.com/xiaojiaoyu100/lizard/mass"

"github.com/go-redis/redis"
"github.com/sirupsen/logrus"
"github.com/vmihailenco/msgpack"
"github.com/xiaojiaoyu100/curlew"
"github.com/xiaojiaoyu100/freesia/entry"
"github.com/xiaojiaoyu100/lizard/mass"
"github.com/xiaojiaoyu100/roc"
"os"
)

// Freesia 多级缓存
type Freesia struct {
store Store
cache *roc.Cache
Expand All @@ -22,6 +21,7 @@ type Freesia struct {
logger *logrus.Logger
}

// New 生成一个实例
func New(store Store, setters ...Setter) (*Freesia, error) {
var err error

Expand Down Expand Up @@ -61,6 +61,7 @@ func New(store Store, setters ...Setter) (*Freesia, error) {
return f, nil
}

// Set sets a key-value.
func (f *Freesia) Set(e *entry.Entry) error {
if err := e.Encode(); err != nil {
return err
Expand All @@ -76,6 +77,7 @@ func (f *Freesia) Set(e *entry.Entry) error {
return nil
}

// MSet batch sets entries.
func (f *Freesia) MSet(es ...*entry.Entry) error {
pipe := f.store.Pipeline()
for _, e := range es {
Expand Down Expand Up @@ -130,6 +132,7 @@ func (f *Freesia) Get(e *entry.Entry) error {
}
}

// GetWithTTL gets value with ttl.
func (f *Freesia) GetWithTTL(e *entry.Entry) error {
if e.EnableLocalExp() {
data, err := f.cache.Get(e.Key())
Expand Down Expand Up @@ -236,6 +239,7 @@ func (f *Freesia) batchGet(es ...*entry.Entry) ([]*entry.Entry, error) {
return missEntries, nil
}

// MGet batch get entries.
func (f *Freesia) MGet(es ...*entry.Entry) ([]*entry.Entry, error) {
batch := mass.New(len(es), 3000)
missEntries := make([]*entry.Entry, 0, len(es))
Expand All @@ -250,6 +254,7 @@ func (f *Freesia) MGet(es ...*entry.Entry) ([]*entry.Entry, error) {
return missEntries, nil
}

// Del deletes keys.
func (f *Freesia) Del(keys ...string) error {
if len(keys) == 0 {
return nil
Expand Down
1 change: 1 addition & 0 deletions setter.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package freesia

// Setter 配置函数
type Setter func(f *Freesia) error
1 change: 1 addition & 0 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/go-redis/redis"
)

// Store represents redis op.
type Store interface {
Set(key string, value interface{}, expiration time.Duration) *redis.StatusCmd
MSet(pairs ...interface{}) *redis.StatusCmd
Expand Down

0 comments on commit 4193569

Please sign in to comment.