Golang如何开始使用KEYDB

huangapple go评论83阅读模式
英文:

Golang how to get started with KEYDB

问题

我开始研究如何替换REDIS,并找到了关于KEYDB数据库的描述,但我没有找到如何在Golang中开始使用它的描述。如果有示例或者知道在哪里可以阅读相关信息的人,请分享一下。

英文:

I started studying the question of how to replace REDIS and found descriptions of the KEYDB database, but I did not find a description of how to start using it with Golang, if there are examples or who knows where to read, please share information.

答案1

得分: -1

互联网上有很多示例。但是,我会始终参考官方文档。

在这里参考文档:https://github.com/robaho/keydb 和 https://pkg.go.dev/github.com/robaho/keydb

使用方法:

db, err := keydb.Open("test/mydb", true)
if err != nil {
    t.Fatal("无法创建数据库", err)
}
tx, err := db.BeginTX("main")
if err != nil {
    t.Fatal("无法创建事务", err)
}
err = tx.Put([]byte("mykey"), []byte("myvalue"))
if err != nil {
    t.Fatal("无法放置键/值", err)
}
err = tx.Commit()
if err != nil {
    t.Fatal("无法提交事务", err)
}
err = db.Close()
if err != nil {
    t.Fatal("无法关闭数据库", err)
}

互联网上有很多示例,请参考以下链接:
https://golang.hotexamples.com/examples/github.com.endophage.gotuf.keys/KeyDB/-/golang-keydb-class-examples.html

此外,如何从KeyDB迁移到Redis或反之,请参考以下链接:
https://docs.keydb.dev/docs/migration/

英文:

There are many example present over the internet. But, I would refer the official docs always.

Refer docs here : https://github.com/robaho/keydb and https://pkg.go.dev/github.com/robaho/keydb

How to use :

db, err := keydb.Open("test/mydb", true)
if err != nil {
	t.Fatal("unable to create database", err)
}
tx, err := db.BeginTX("main")
if err != nil {
	t.Fatal("unable to create transaction", err)
}
err = tx.Put([]byte("mykey"), []byte("myvalue"))
if err != nil {
	t.Fatal("unable to put key/Value", err)
}
err = tx.Commit()
if err != nil {
    t.Fatal("unable to commit transaction", err)
}
err = db.Close()
if err != nil {
    t.Fatal("unable to close database", err)
}

Many example present over the net please refer this :
https://golang.hotexamples.com/examples/github.com.endophage.gotuf.keys/KeyDB/-/golang-keydb-class-examples.html

Also how to migrate from keydb to redis and vise versa refer this link :
https://docs.keydb.dev/docs/migration/

huangapple
  • 本文由 发表于 2022年1月13日 17:10:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/70693940.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定