mirror of
https://github.com/navidrome/navidrome.git
synced 2024-09-10 11:32:48 +02:00
36 lines
589 B
Go
36 lines
589 B
Go
package persistence
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/astaxie/beego"
|
|
"github.com/siddontang/ledisdb/config"
|
|
"github.com/siddontang/ledisdb/ledis"
|
|
)
|
|
|
|
var (
|
|
_ledisInstance *ledis.Ledis
|
|
_dbInstance *ledis.DB
|
|
once sync.Once
|
|
)
|
|
|
|
func Db() *ledis.DB {
|
|
once.Do(func() {
|
|
config := config.NewConfigDefault()
|
|
config.DataDir = beego.AppConfig.String("dbPath")
|
|
l, _ := ledis.Open(config)
|
|
instance, err := l.Select(0)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
_ledisInstance = l
|
|
_dbInstance = instance
|
|
})
|
|
return _dbInstance
|
|
}
|
|
|
|
func dropDb() {
|
|
Db()
|
|
_ledisInstance.FlushAll()
|
|
}
|