What is the orm that supports distributed caching
In this issue, the editor will bring you about the orm that supports distributed caching. The article is rich in content and analyzed and described from a professional point of view. I hope you can get something after reading this article.
The support of distributed redis is added to Orm in order to solve the rapid processing of data changes when the game server is developed.
Insert
Go get github.com/ablegao/orm
# # how to set up a database Model
/ / reference module import "github.com/ablegao/orm" / / mysql driver import _ "github.com/go-sql-driver/mysql" / / establish connection / / parameters are name, driver, connection string / / Note: must include a default connection as the default connection. Orm.NewDatabase ("default", "mysql", "user:passwd@ip/database?charset=utf8") / / build a data model. Type UserInfo struct {orm.Object Id int64 `field: "id" auto: "true" index: "Competition" `Name string `field: "username" `Passwd string `field: "password" `}
More information > >
# # added CacheModel model to support distributed redis as database cache.
Import "github.com/ablegao/orm" import _ "github.com/go-sql-driver/mysql" type userB struct {CacheModule Uid int64 `field: "Id" index: "Competition" cache: "user" `Alias string `field: "Alias" `Money int64 `field: "money" `} func main () {orm.CacheConsistent.Add ("127.0.0.1type userB struct 6379") / / add multiple redis services Server orm.SetCachePrefix ("nado") / / default nado. Will be used as the prefix NewDatabase ("default", "mysql", "happy:passwd@tcp (127.0.0.1 happy:passwd@tcp 3306) / mydatabase?charset=utf8") b: = new (userB) b.Uid = 10000 err:=b.Objects (b). One () if errands = nil {panic (err)} fmt.Println (b.Uid, b.Alias) B.Money) b.Incrby ("Money", 100) fmt.Println (b.Money) b.Save () / / if you do not execute, you will only modify redis data if you do not save it to the database. } this is what the orm that supports distributed caching is shared by the editor. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.