• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang ledis.Open函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/siddontang/ledisdb/ledis.Open函数的典型用法代码示例。如果您正苦于以下问题:Golang Open函数的具体用法?Golang Open怎么用?Golang Open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Open函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: SessionInit

// init ledis session
// savepath like ledis server saveDataPath,pool size
// e.g. 127.0.0.1:6379,100,astaxie
func (lp *LedisProvider) SessionInit(maxlifetime int64, savePath string) error {
	var err error
	lp.maxlifetime = maxlifetime
	configs := strings.Split(savePath, ",")
	if len(configs) == 1 {
		lp.savePath = configs[0]
	} else if len(configs) == 2 {
		lp.savePath = configs[0]
		lp.db, err = strconv.Atoi(configs[1])
		if err != nil {
			return err
		}
	}
	cfg := new(config.Config)
	cfg.DataDir = lp.savePath
	nowLedis, err := ledis.Open(cfg)
	c, err = nowLedis.Select(lp.db)
	if err != nil {
		println(err)
		return nil
	}
	return nil
}
开发者ID:shelmesky,项目名称:rtmonitor_dashboard,代码行数:26,代码来源:ledis_session.go


示例17: 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

	app.slaves = make(map[string]*client)
	app.slaveSyncAck = make(chan uint64)

	app.rcs = make(map[*respClient]struct{})

	app.migrateClients = make(map[string]*goredis.Client)
	app.newMigrateKeyLockers()

	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.snap, err = newSnapshotStore(cfg); err != nil {
		return nil, err
	}

	if len(app.cfg.SlaveOf) > 0 {
		//slave must readonly
		app.cfg.Readonly = true
	}

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

	app.m = newMaster(app)

	app.openScript()

	app.ldb.AddNewLogEventHandler(app.publishNewLog)

	return app, nil
}
开发者ID:insionng,项目名称:ledisdb,代码行数:71,代码来源:app.go


示例18: BlacklistToken

package auth

import (
	lediscfg "github.com/siddontang/ledisdb/config"
	"github.com/siddontang/ledisdb/ledis"
)

var cfg *lediscfg.Config = lediscfg.NewConfigDefault()
var l, _ = ledis.Open(cfg)
var db, _ = l.Select(0)

// BlacklistToken adds the token to a ledis database
func BlacklistToken(token []byte, expireAt int64) error {

	db.Set(token, token)
	db.ExpireAt(token, expireAt)

	return nil
}

// IsBlackListed checks if a token is in the blacklist list
func IsBlacklisted(token []byte) (bool, error) {
	res, err := db.Get(token)
	if err != nil {
		return false, err
	}

	if res == nil {
		return false, err
	}
开发者ID:malloc-fi,项目名称:vantaa,代码行数:30,代码来源:jwt_store.go



注:本文中的github.com/siddontang/ledisdb/ledis.Open函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang ledis.Slice函数代码示例发布时间:2022-05-28
下一篇:
Golang config.LevelDBConfig类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap