當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ledis.Open函數代碼示例

本文整理匯總了Golang中github.com/siddontang/ledisdb/ledis.Open函數的典型用法代碼示例。如果您正苦於以下問題:Golang Open函數的具體用法?Golang Open怎麽用?Golang Open使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Open函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Init

// Init initializes ledis session provider.
// configs: data_dir=./app.db,db=0
func (p *LedisProvider) Init(expire int64, configs string) error {
	p.expire = expire

	cfg, err := ini.Load([]byte(strings.Replace(configs, ",", "\n", -1)))
	if err != nil {
		return err
	}

	db := 0
	opt := new(config.Config)
	for k, v := range cfg.Section("").KeysHash() {
		switch k {
		case "data_dir":
			opt.DataDir = v
		case "db":
			db = com.StrTo(v).MustInt()
		default:
			return fmt.Errorf("session/ledis: unsupported option '%s'", k)
		}
	}

	l, err := ledis.Open(opt)
	if err != nil {
		return fmt.Errorf("session/ledis: error opening db: %v", err)
	}
	p.c, err = l.Select(db)
	return err
}
開發者ID:mbrukman,項目名稱:grafana,代碼行數:30,代碼來源:ledis.go

示例2: StartAndGC

// StartAndGC starts GC routine based on config string settings.
// AdapterConfig: data_dir=./app.db,db=0
func (c *LedisCacher) StartAndGC(opts cache.Options) error {
	c.interval = opts.Interval

	cfg, err := ini.Load([]byte(strings.Replace(opts.AdapterConfig, ",", "\n", -1)))
	if err != nil {
		return err
	}

	db := 0
	opt := new(config.Config)
	for k, v := range cfg.Section("").KeysHash() {
		switch k {
		case "data_dir":
			opt.DataDir = v
		case "db":
			db = com.StrTo(v).MustInt()
		default:
			return fmt.Errorf("session/ledis: unsupported option '%s'", k)
		}
	}

	l, err := ledis.Open(opt)
	if err != nil {
		return fmt.Errorf("session/ledis: error opening db: %v", err)
	}
	c.c, err = l.Select(db)
	if err != nil {
		return err
	}

	go c.startGC()
	return nil
}
開發者ID:kenno,項目名稱:cache,代碼行數:35,代碼來源:ledis.go

示例3: NewStore

func NewStore(DbPath string) (*Store, error) {
	if !dry.FileExists(DbPath) {
		e := os.MkdirAll(DbPath, 0777)
		if e != nil {
			return nil, e
		}
	}
	db, e := bolt.Open(filepath.Join(DbPath, "bolt"), 0600, nil)
	if e != nil {
		return nil, e
	}
	e = db.Update(func(tx *bolt.Tx) (e error) {
		buckets := []string{SITE_BUCKET, URI_BUCKET, USER_AGENT_BUCKET, USER_ID_BUCKET,
			SESSION_ID_BUCKET}
		for _, v := range buckets {
			if e != nil {
				continue
			}
			_, e = tx.CreateBucketIfNotExists([]byte(v))
		}
		return
	})
	if e != nil {
		return nil, e
	}

	ldb, e := leveldb.OpenFile(filepath.Join(DbPath, "level"), nil)
	if e != nil {
		return nil, e
	}

	ledisdb, e := ledis.Open(&config.Config{DataDir: filepath.Join(DbPath, "ledis")})
	if e != nil {
		return nil, e
	}
	ledisdbFirst, e := ledisdb.Select(0)
	if e != nil {
		return nil, e
	}

	e = os.MkdirAll(filepath.Join(DbPath, BINLOGS_DIR), 0777)
	if e != nil {
		return nil, e
	}
	bl, e := NewWriteBinLog(filepath.Join(DbPath, BINLOGS_DIR, "today"))
	if e != nil {
		return nil, e
	}

	s := new(Store)
	s.db = db
	s.ldb = ldb
	s.ledisdb = ledisdbFirst
	s.binlog = bl
	s.DbPath = DbPath

	e = s.ArchiveBinlogIfNeeded()

	return s, e
}
開發者ID:zhuharev,項目名稱:stat,代碼行數:60,代碼來源:store.go

示例4: NewApp

func NewApp(cfg *config.Config) (*App, error) {
	if len(cfg.DataDir) == 0 {
		println("use default datadir %s", config.DefaultDataDir)
		cfg.DataDir = config.DefaultDataDir
	}

	app := new(App)

	app.quit = make(chan struct{})

	app.closed = false

	app.cfg = cfg

	var err error

	if app.info, err = newInfo(app); err != nil {
		return nil, err
	}

	if app.listener, err = net.Listen(netType(cfg.Addr), cfg.Addr); err != nil {
		return nil, err
	}

	if len(cfg.HttpAddr) > 0 {
		if app.httpListener, err = net.Listen(netType(cfg.HttpAddr), cfg.HttpAddr); err != nil {
			return nil, err
		}
	}

	if len(cfg.AccessLog) > 0 {
		if path.Dir(cfg.AccessLog) == "." {
			app.access, err = newAcessLog(path.Join(cfg.DataDir, cfg.AccessLog))
		} else {
			app.access, err = newAcessLog(cfg.AccessLog)
		}

		if err != nil {
			return nil, err
		}
	}

	if app.ldb, err = ledis.Open(cfg); err != nil {
		return nil, err
	}

	app.m = newMaster(app)

	app.openScript()

	return app, nil
}
開發者ID:Abioy,項目名稱:ledisdb,代碼行數:52,代碼來源:app.go

示例5: ClearAllTokens

func ClearAllTokens() (int64, error) {
	l, err := ledis.Open(cfg)
	defer l.Close()
	if err != nil {
		return 0, err
	}

	db, err := l.Select(0)
	if err != nil {
		return 0, err
	}

	return db.FlushAll()
}
開發者ID:malloc-fi,項目名稱:vantaa,代碼行數:14,代碼來源:jwt_store.go

示例6: NewApp

func NewApp(cfg *Config) (*App, error) {
	if len(cfg.DataDir) == 0 {
		return nil, fmt.Errorf("must set data_dir first")
	}

	if len(cfg.DB.DataDir) == 0 {
		cfg.DB.DataDir = cfg.DataDir
	}

	app := new(App)

	app.quit = make(chan struct{})

	app.closed = false

	app.cfg = cfg

	var err error

	if strings.Contains(cfg.Addr, "/") {
		app.listener, err = net.Listen("unix", cfg.Addr)
	} else {
		app.listener, err = net.Listen("tcp", cfg.Addr)
	}

	if err != nil {
		return nil, err
	}

	if len(cfg.AccessLog) > 0 {
		if path.Dir(cfg.AccessLog) == "." {
			app.access, err = newAcessLog(path.Join(cfg.DataDir, cfg.AccessLog))
		} else {
			app.access, err = newAcessLog(cfg.AccessLog)
		}

		if err != nil {
			return nil, err
		}
	}

	if app.ldb, err = ledis.Open(&cfg.DB); err != nil {
		return nil, err
	}

	app.m = newMaster(app)

	return app, nil
}
開發者ID:Gohan,項目名稱:ledisdb,代碼行數:49,代碼來源:app.go

示例7: 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
}
開發者ID:elitalobo,項目名稱:DistributedCache,代碼行數:19,代碼來源:cache.go

示例8: main

func main() {
	flag.Parse()

	if len(*configPath) == 0 {
		println("need ledis config file")
		return
	}

	data, err := ioutil.ReadFile(*configPath)
	if err != nil {
		println(err.Error())
		return
	}

	if len(*dumpPath) == 0 {
		println("need dump file")
		return
	}

	var cfg ledis.Config
	if err = json.Unmarshal(data, &cfg); err != nil {
		println(err.Error())
		return
	}

	if len(cfg.DataDir) == 0 {
		println("must set data dir")
		return
	}

	ldb, err := ledis.Open(&cfg)
	if err != nil {
		println("ledis open error ", err.Error())
		return
	}

	err = loadDump(&cfg, ldb)
	ldb.Close()

	if err != nil {
		println(err.Error())
		return
	}

	println("Load OK")
}
開發者ID:Gohan,項目名稱:ledisdb,代碼行數:46,代碼來源:main.go

示例9: NewApp

func NewApp(cfg *Config) (*App, error) {
	if len(cfg.DataDir) == 0 {
		return nil, fmt.Errorf("must set data_dir first")
	}

	app := new(App)

	app.quit = make(chan struct{})

	app.closed = false

	app.cfg = cfg

	var err error

	if app.listener, err = net.Listen(netType(cfg.Addr), cfg.Addr); err != nil {
		return nil, err
	}

	if len(cfg.HttpAddr) > 0 {
		if app.httpListener, err = net.Listen(netType(cfg.HttpAddr), cfg.HttpAddr); err != nil {
			return nil, err
		}
	}

	if len(cfg.AccessLog) > 0 {
		if path.Dir(cfg.AccessLog) == "." {
			app.access, err = newAcessLog(path.Join(cfg.DataDir, cfg.AccessLog))
		} else {
			app.access, err = newAcessLog(cfg.AccessLog)
		}

		if err != nil {
			return nil, err
		}
	}

	if app.ldb, err = ledis.Open(cfg.NewLedisConfig()); err != nil {
		return nil, err
	}

	app.m = newMaster(app)

	return app, nil
}
開發者ID:JREAMLU,項目名稱:ledisdb,代碼行數:45,代碼來源:app.go

示例10: InitDb

func InitDb() {
	initLedisFunc := func() {
		cfg := new(config.Config)
		cfg.DataDir = beego.AppConfig.String("ledisdb::DataDir")
		var err error
		nowLedis, err = ledis.Open(cfg)
		if err != nil {
			println(err.Error())
			panic(err)
		}
	}

	ledisOnce.Do(initLedisFunc)

	db, _ := beego.AppConfig.Int("ledisdb::DB")

	LedisDB, _ = nowLedis.Select(db)
}
開發者ID:rechen,項目名稱:wharf,代碼行數:18,代碼來源:models.go

示例11: 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
}
開發者ID:Monnoroch,項目名稱:golfstream,代碼行數:21,代碼來源:ledis.go

示例12: InitDb

func InitDb() error {
	opt := &config.Config{
		DataDir: path.Join(setting.DataDir, "vessel.db"),
	}

	l, err := ledis.Open(opt)
	if err != nil {
		return fmt.Errorf("open Ledis DB: %v", err)
	}

	db := 0
	LedisDB, err = l.Select(db)
	if err != nil {
		return fmt.Errorf("select Ledis DB '%d': %v", db, err)
	}

	return nil
}
開發者ID:rechen,項目名稱:vessel,代碼行數:18,代碼來源:models.go

示例13: main

func main() {
	flag.Parse()

	if len(*configPath) == 0 {
		println("need ledis config file")
		return
	}

	cfg, err := config.NewConfigWithFile(*configPath)
	if err != nil {
		println(err.Error())
		return
	}

	if len(*dumpPath) == 0 {
		println("need dump file")
		return
	}

	if len(cfg.DataDir) == 0 {
		println("must set data dir")
		return
	}

	ldb, err := ledis.Open(cfg)
	if err != nil {
		println("ledis open error ", err.Error())
		return
	}

	err = loadDump(cfg, ldb)
	ldb.Close()

	if err != nil {
		println(err.Error())
		return
	}

	println("Load OK")
}
開發者ID:Abioy,項目名稱:ledisdb,代碼行數:40,代碼來源:main.go

示例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
}
開發者ID:gocontrib,項目名稱:nosql,代碼行數:23,代碼來源:store.go

示例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,
	}

}
開發者ID:elitalobo,項目名稱:stash,代碼行數:26,代碼來源:cache.go


注:本文中的github.com/siddontang/ledisdb/ledis.Open函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。