本文整理汇总了Golang中github.com/siddontang/ledisdb/config.Config.DBName方法的典型用法代码示例。如果您正苦于以下问题:Golang Config.DBName方法的具体用法?Golang Config.DBName怎么用?Golang Config.DBName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/siddontang/ledisdb/config.Config
的用法示例。
在下文中一共展示了Config.DBName方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetStore
func GetStore(cfg *config.Config) (Store, error) {
if len(cfg.DBName) == 0 {
cfg.DBName = config.DefaultDBName
}
s, ok := dbs[cfg.DBName]
if !ok {
return nil, fmt.Errorf("store %s is not registered", cfg.DBName)
}
return s, nil
}
示例2: main
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
flag.Parse()
var cfg *config.Config
var err error
if len(*configFile) == 0 {
println("no config set, using default config")
cfg = config.NewConfigDefault()
} else {
cfg, err = config.NewConfigWithFile(*configFile)
}
if err != nil {
println(err.Error())
return
}
if len(*dbName) > 0 {
cfg.DBName = *dbName
}
var app *server.App
app, err = server.NewApp(cfg)
if err != nil {
println(err.Error())
return
}
sc := make(chan os.Signal, 1)
signal.Notify(sc,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
<-sc
app.Close()
}()
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
app.Run()
}
示例3: newTestRocksDB
func newTestRocksDB() *DB {
cfg := new(config.Config)
cfg.DBName = "rocksdb"
cfg.DataDir = "/tmp/testdb"
os.RemoveAll(getStorePath(cfg))
db, err := Open(cfg)
if err != nil {
println(err.Error())
panic(err)
}
return db
}
示例4: newTestLMDB
func newTestLMDB() *DB {
cfg := new(config.Config)
cfg.DBName = "lmdb"
cfg.DataDir = "/tmp/testdb"
cfg.LMDB.MapSize = 10 * 1024 * 1024
os.RemoveAll(getStorePath(cfg))
db, err := Open(cfg)
if err != nil {
println(err.Error())
panic(err)
}
return db
}
示例5: testTx
func testTx(t *testing.T, name string) {
cfg := new(config.Config)
cfg.DataDir = "/tmp/ledis_test_tx"
cfg.DBName = name
cfg.LMDB.MapSize = 10 * 1024 * 1024
os.RemoveAll(cfg.DataDir)
l, err := Open(cfg)
if err != nil {
t.Fatal(err)
}
defer l.Close()
db, _ := l.Select(0)
testTxRollback(t, db)
testTxCommit(t, db)
testTxSelect(t, db)
}
示例6: TestStore
func TestStore(t *testing.T) {
cfg := new(config.Config)
cfg.DataDir = "/tmp/testdb"
cfg.LMDB.MapSize = 10 * 1024 * 1024
ns := driver.ListStores()
for _, s := range ns {
cfg.DBName = s
os.RemoveAll(getStorePath(cfg))
db, err := Open(cfg)
if err != nil {
t.Fatal(err)
}
testStore(db, t)
testClear(db, t)
testTx(db, t)
db.Close()
}
}
示例7: TestLuaCall
func TestLuaCall(t *testing.T) {
cfg := new(config.Config)
cfg.Addr = ":11188"
cfg.DataDir = "/tmp/testscript"
cfg.DBName = "memory"
app, e := NewApp(cfg)
if e != nil {
t.Fatal(e)
}
go app.Run()
defer app.Close()
db, _ := app.ldb.Select(0)
m, _ := db.Multi()
defer m.Close()
luaClient := app.s.c
luaClient.db = m.DB
luaClient.script = m
l := app.s.l
err := app.s.l.DoString(testScript1)
if err != nil {
t.Fatal(err)
}
v := luaReplyToLedisReply(l)
if vv, ok := v.([]interface{}); ok {
if len(vv) != 3 {
t.Fatal(len(vv))
}
} else {
t.Fatal(fmt.Sprintf("%v %T", v, v))
}
err = app.s.l.DoString(testScript2)
if err != nil {
t.Fatal(err)
}
v = luaReplyToLedisReply(l)
if vv := v.(string); vv != "PONG" {
t.Fatal(fmt.Sprintf("%v %T", v, v))
}
err = app.s.l.DoString(testScript3)
if err != nil {
t.Fatal(err)
}
if v, err := db.Get([]byte("1")); err != nil {
t.Fatal(err)
} else if string(v) != "a" {
t.Fatal(string(v))
}
err = app.s.l.DoString(testScript4)
if err != nil {
t.Fatal(err)
}
if luaClient.db.Index() != 2 {
t.Fatal(luaClient.db.Index())
}
db2, _ := app.ldb.Select(2)
if v, err := db2.Get([]byte("2")); err != nil {
t.Fatal(err)
} else if string(v) != "b" {
t.Fatal(string(v))
}
luaClient.db = nil
}
示例8: main
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
flag.Parse()
var cfg *config.Config
var err error
if len(*configFile) == 0 {
println("no config set, using default config")
cfg = config.NewConfigDefault()
} else {
cfg, err = config.NewConfigWithFile(*configFile)
}
if err != nil {
println(err.Error())
return
}
if len(*addr) > 0 {
cfg.Addr = *addr
}
if len(*dataDir) > 0 {
cfg.DataDir = *dataDir
}
if len(*dbName) > 0 {
cfg.DBName = *dbName
}
if *databases > 0 {
cfg.Databases = *databases
}
// check bool flag, use it.
for _, arg := range os.Args {
arg := strings.ToLower(arg)
switch arg {
case "-rpl", "-rpl=true", "-rpl=false":
cfg.UseReplication = *rpl
case "-readonly", "-readonly=true", "-readonly=false":
cfg.Readonly = *readonly
case "-rpl_sync", "-rpl_sync=true", "-rpl_sync=false":
cfg.Replication.Sync = *rplSync
}
}
if len(*slaveof) > 0 {
cfg.SlaveOf = *slaveof
cfg.Readonly = true
cfg.UseReplication = true
}
if *ttlCheck > 0 {
cfg.TTLCheckInterval = *ttlCheck
}
var app *server.App
app, err = server.NewApp(cfg)
if err != nil {
println(err.Error())
return
}
sc := make(chan os.Signal, 1)
signal.Notify(sc,
os.Kill,
os.Interrupt,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
if *usePprof {
go func() {
log.Println(http.ListenAndServe(fmt.Sprintf(":%d", *pprofPort), nil))
}()
}
go app.Run()
<-sc
println("ledis-server is closing")
app.Close()
println("ledis-server is closed")
}