英文:
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/
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论