x
This commit is contained in:
+23
-20
@@ -55,6 +55,7 @@ func MakeBucket(name string) storage.Bucket {
|
||||
bkt = app
|
||||
} else {
|
||||
isredis = true
|
||||
logs.Info("已使用redis进行数据存储")
|
||||
}
|
||||
}()
|
||||
bkt = redis.Initsillyplus(app.GetString("redis_addr"), app.GetString("redis_password"))
|
||||
@@ -92,26 +93,28 @@ func MakeBucket(name string) storage.Bucket {
|
||||
}
|
||||
return nil
|
||||
})
|
||||
storage.Watch(app, "redis_addr", func(old, new, _ string) *storage.Final {
|
||||
message := "Redis连接成功,重启生效!"
|
||||
err := redis.Try(new, app.GetString("redis_password"))
|
||||
if err != nil {
|
||||
message = "Redis连接失败:" + err.Error()
|
||||
}
|
||||
return &storage.Final{
|
||||
Message: message,
|
||||
}
|
||||
})
|
||||
storage.Watch(app, "redis_password", func(old, new, _ string) *storage.Final {
|
||||
message := "Redis连接成功,重启生效!"
|
||||
err := redis.Try(app.GetString("redis_addr"), new)
|
||||
if err != nil {
|
||||
message = "Redis连接失败:" + err.Error()
|
||||
}
|
||||
return &storage.Final{
|
||||
Message: message,
|
||||
}
|
||||
})
|
||||
if !isredis {
|
||||
storage.Watch(app, "redis_addr", func(old, new, _ string) *storage.Final {
|
||||
message := "Redis连接成功,重启生效!"
|
||||
err := redis.Try(new, app.GetString("redis_password"))
|
||||
if err != nil {
|
||||
message = "Redis连接失败:" + err.Error()
|
||||
}
|
||||
return &storage.Final{
|
||||
Message: message,
|
||||
}
|
||||
})
|
||||
storage.Watch(app, "redis_password", func(old, new, _ string) *storage.Final {
|
||||
message := "Redis连接成功,重启生效!"
|
||||
err := redis.Try(app.GetString("redis_addr"), new)
|
||||
if err != nil {
|
||||
message = "Redis连接失败:" + err.Error()
|
||||
}
|
||||
return &storage.Final{
|
||||
Message: message,
|
||||
}
|
||||
})
|
||||
}
|
||||
for _, name := range bkt.Buckets() {
|
||||
b := bkt.Copy(name)
|
||||
keys, err := b.Keys()
|
||||
|
||||
@@ -376,12 +376,12 @@ func (bucket *Bucket) First(i interface{}) error {
|
||||
b := tx.Bucket([]byte(bucket.name))
|
||||
if b == nil {
|
||||
err = errors.New("bucket not find")
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
data := b.Get([]byte(fmt.Sprint(v)))
|
||||
if len(data) == 0 {
|
||||
err = errors.New("record not find")
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
return json.Unmarshal(data, i)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user