本文整理汇总了Golang中github.com/siddontang/ledisdb/config.NewConfigDefault函数的典型用法代码示例。如果您正苦于以下问题:Golang NewConfigDefault函数的具体用法?Golang NewConfigDefault怎么用?Golang NewConfigDefault使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewConfigDefault函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: startTestAppAuth
func startTestAppAuth(password string) {
f := func() {
newTestLedisClientAuth()
cfg := config.NewConfigDefault()
cfg.DataDir = "/tmp/testdb_auth"
os.RemoveAll(cfg.DataDir)
cfg.Addr = "127.0.0.1:20000"
cfg.HttpAddr = "127.0.0.1:20001"
cfg.AuthPassword = password
os.RemoveAll(cfg.DataDir)
var err error
testApp, err = NewApp(cfg)
if err != nil {
println(err.Error())
panic(err)
}
go testApp.Run()
}
testAppAuthOnce.Do(f)
}
示例2: startTestApp
func startTestApp() {
f := func() {
newTestLedisClient()
cfg := config.NewConfigDefault()
cfg.DataDir = "/tmp/testdb"
os.RemoveAll(cfg.DataDir)
cfg.Addr = "127.0.0.1:16380"
cfg.HttpAddr = "127.0.0.1:21181"
os.RemoveAll(cfg.DataDir)
var err error
testApp, err = NewApp(cfg)
if err != nil {
println(err.Error())
panic(err)
}
go testApp.Run()
}
testAppOnce.Do(f)
}
示例3: TestScan
func TestScan(t *testing.T) {
cfg := config.NewConfigDefault()
cfg.DataDir = "/tmp/test_scan"
cfg.Addr = "127.0.0.1:11185"
os.RemoveAll(cfg.DataDir)
s, err := NewApp(cfg)
if err != nil {
t.Fatal(err)
}
go s.Run()
defer s.Close()
c := goredis.NewClient(cfg.Addr, "")
c.SetMaxIdleConns(1)
defer c.Close()
testKVScan(t, c)
testHashKeyScan(t, c)
testListKeyScan(t, c)
testZSetKeyScan(t, c)
testSetKeyScan(t, c)
}
示例4: TestReplication
func TestReplication(t *testing.T) {
dir, err := ioutil.TempDir("", "rpl")
if err != nil {
t.Fatalf("err: %v ", err)
}
defer os.RemoveAll(dir)
c := config.NewConfigDefault()
c.Replication.Path = dir
r, err := NewReplication(c)
if err != nil {
t.Fatal(err)
}
if l1, err := r.Log([]byte("hello world")); err != nil {
t.Fatal(err)
} else if l1.ID != 1 {
t.Fatal(l1.ID)
}
if b, _ := r.CommitIDBehind(); !b {
t.Fatal("must backward")
}
if err := r.UpdateCommitID(1); err != nil {
t.Fatal(err)
}
if b, _ := r.CommitIDBehind(); b {
t.Fatal("must not backward")
}
r.Close()
}
示例5: TestSnapshot
func TestSnapshot(t *testing.T) {
cfg := config.NewConfigDefault()
cfg.Snapshot.MaxNum = 2
cfg.Snapshot.Path = path.Join(os.TempDir(), "snapshot")
defer os.RemoveAll(cfg.Snapshot.Path)
d := new(testSnapshotDumper)
s, err := newSnapshotStore(cfg)
if err != nil {
t.Fatal(err)
}
if f, _, err := s.Create(d); err != nil {
t.Fatal(err)
} else {
defer f.Close()
if b, _ := ioutil.ReadAll(f); string(b) != "hello world" {
t.Fatal("invalid read snapshot")
}
if len(s.names) != 1 {
t.Fatal("must 1 snapshot")
}
}
if f, _, err := s.Create(d); err != nil {
t.Fatal(err)
} else {
defer f.Close()
if b, _ := ioutil.ReadAll(f); string(b) != "hello world" {
t.Fatal("invalid read snapshot")
}
if len(s.names) != 2 {
t.Fatal("must 2 snapshot")
}
}
if f, _, err := s.Create(d); err != nil {
t.Fatal(err)
} else {
defer f.Close()
if b, _ := ioutil.ReadAll(f); string(b) != "hello world" {
t.Fatal("invalid read snapshot")
}
if len(s.names) != 2 {
t.Fatal("must 2 snapshot")
}
}
fs, _ := ioutil.ReadDir(cfg.Snapshot.Path)
if len(fs) != 2 {
t.Fatal("must 2 snapshot")
}
s.Close()
}
示例6: TestDump
func TestDump(t *testing.T) {
cfgM := config.NewConfigDefault()
cfgM.DataDir = "/tmp/test_ledis_master"
os.RemoveAll(cfgM.DataDir)
master, err := Open(cfgM)
if err != nil {
t.Fatal(err)
}
cfgS := config.NewConfigDefault()
cfgS.DataDir = "/tmp/test_ledis_slave"
os.RemoveAll(cfgS.DataDir)
var slave *Ledis
if slave, err = Open(cfgS); err != nil {
t.Fatal(err)
}
db, _ := master.Select(0)
db.Set([]byte("a"), []byte("1"))
db.Set([]byte("b"), []byte("2"))
db.Set([]byte("c"), []byte("3"))
if err := master.DumpFile("/tmp/testdb.dump"); err != nil {
t.Fatal(err)
}
if _, err := slave.LoadDumpFile("/tmp/testdb.dump"); err != nil {
t.Fatal(err)
}
it := master.ldb.RangeLimitIterator(nil, nil, store.RangeClose, 0, -1)
for ; it.Valid(); it.Next() {
key := it.Key()
value := it.Value()
if v, err := slave.ldb.Get(key); err != nil {
t.Fatal(err)
} else if !bytes.Equal(v, value) {
t.Fatal("load dump error")
}
}
}
示例7: StartLedis
// Start in-process ledis server. Data will go in the specified directory and it will bind to the given port.
// Return value is a function you can call to stop the server.
func StartLedis(dataDir string, bind string) (stop func(), err error) {
cfg := config.NewConfigDefault()
cfg.DBName = "goleveldb"
cfg.Addr = bind
cfg.DataDir = dataDir
app, err := server.NewApp(cfg)
if err != nil {
log.Fatal(err)
return func() {}, err
}
go app.Run()
return app.Close, 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(*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()
}
示例9: New
/* New(string,bool) initializes a cache object,
takes as input database name and a boolean parameter stating whether a compression is needed or not.
*/
func New(dataDir string) (*Cache, error) {
cfg := config.NewConfigDefault()
dataDir = fmt.Sprint(cfg.DataDir, "/", dataDir)
cfg.DataDir = dataDir
cfg.Replication.Compression = false
ledis_connection, err := ledis.Open(cfg)
if err != nil {
panic("Resource temporary unavailable, error opening a Connection!!!")
}
db, err := ledis_connection.Select(0)
return &Cache{
cfg,
ledis_connection,
db,
}, err
}
示例10: NewLedis
/*
Create a backend that stores pushed events in ledisdb.
*/
func NewLedis(dirname string) (Backend, error) {
lcfg := config.NewConfigDefault()
lcfg.DataDir = dirname
lcfg.Addr = ""
lcfg.Databases = 1
ledis, err := ledis.Open(lcfg)
if err != nil {
return nil, err
}
db, err := ledis.Select(0)
if err != nil {
return nil, err
}
return &ledisBackend{dirname, ledis, db, sync.Mutex{}, map[string]*ledisStreamObj{}}, nil
}
示例11: getTestDB
func getTestDB() *DB {
f := func() {
cfg := config.NewConfigDefault()
cfg.DataDir = "/tmp/test_ledis"
os.RemoveAll(cfg.DataDir)
var err error
testLedis, err = Open(cfg)
if err != nil {
println(err.Error())
panic(err)
}
}
testLedisOnce.Do(f)
db, _ := testLedis.Select(0)
return db
}
示例12: NewGoLevelDBStore
func NewGoLevelDBStore(base string, syncLog int) (*GoLevelDBStore, error) {
cfg := config.NewConfigDefault()
cfg.DBName = "goleveldb"
cfg.DBPath = base
cfg.LevelDB.BlockSize = 16 * 1024 * 1024
cfg.LevelDB.CacheSize = 64 * 1024 * 1024
cfg.LevelDB.WriteBufferSize = 64 * 1024 * 1024
cfg.LevelDB.Compression = false
cfg.DBSyncCommit = syncLog
s := new(GoLevelDBStore)
s.cfg = cfg
if err := s.open(); err != nil {
return nil, err
}
return s, nil
}
示例13: TestFileStore
func TestFileStore(t *testing.T) {
// Create a test dir
dir, err := ioutil.TempDir("", "ldb")
if err != nil {
t.Fatalf("err: %v ", err)
}
defer os.RemoveAll(dir)
// New level
cfg := config.NewConfigDefault()
cfg.Replication.MaxLogFileSize = 4096
l, err := NewFileStore(dir, cfg)
if err != nil {
t.Fatalf("err: %v ", err)
}
defer l.Close()
testLogs(t, l)
}
示例14: Open
// Open ledis store.
func Open(path string, db int, dropDatabase bool) (data.Store, error) {
if dropDatabase {
if _, err := os.Stat(path); err == nil {
os.RemoveAll(path)
}
}
cfg := config.NewConfigDefault()
cfg.DataDir = path
l, err := ledis.Open(cfg)
if err != nil {
return nil, debug.Err("open", err)
}
d, err := l.Select(db)
if err != nil {
return nil, debug.Err("select", err)
}
return redis.New(&store{l, d}), nil
}
示例15: New
/* New(string,bool) initializes a cache object,
takes as input database name and a boolean parameter stating whether a compression is needed or not.
*/
func New(dbName string, Iscompression bool) *Cache {
cfg := config.NewConfigDefault()
cfg.DBName = dbName
cfg.Replication.Compression = Iscompression
ledis_connection, err := ledis.Open(cfg)
if err != nil {
panic("Resource temporary unavailable, problem in opening a Connection!!!")
}
db, err := ledis_connection.Select(0)
if err != nil {
panic("Problem selecting a Database Connection!!!")
}
return &Cache{
cfg,
ledis_connection,
db,
}
}