鎺ㄨ崘涓€涓秴绾ц交閲忕骇KV瀛樺偍馃敟
时间:2023-02-16
浏览:230
作者:佚名
本篇文章向大家介绍《鎺ㄨ崘涓€涓秴绾ц交閲忕骇KV瀛樺偍馃敟》,主要包括MySQL、Java、鍚庣、鏁版嵁搴?/a>go,具有一定的参考价值,需要的朋友可以参考一下。
Hi (喙戔暪鈼♀暪)锞夆€濓紝鍚勪綅go get -u github.com/auula/bottle鍩烘湰API
濡備綍鎿嶄綔涓€涓?code>Bottle瀹炰緥浠g爜:
package main import ( "fmt" "github.com/auula/bottle" ) func init() { // 閫氳繃榛樿閰嶇疆鎵撳紑涓€涓瓨鍌ㄥ疄渚? err := bottle.Open(bottle.DefaultOption) // 骞朵笖澶勭悊涓€涓嬪彲鑳藉彂鐢熺殑閿欒 if err != nil { panic(err) } } // Userinfo 娴嬭瘯鏁版嵁缁撴瀯 type Userinfo struct { Name string Age uint8 Skill []string } func main() { // PUT Data bottle.Put([]byte("foo"), []byte("66.6")) // 濡傛灉杞垚string閭d箞灏辨槸瀛楃涓? fmt.Println(bottle.Get([]byte("foo")).String()) // 濡傛灉涓嶅瓨鍦ㄩ粯璁ゅ€煎氨鏄? fmt.Println(bottle.Get([]byte("foo")).Int()) // 濡傛灉涓嶆垚鍔熷氨鏄痜alse fmt.Println(bottle.Get([]byte("foo")).Bool()) // 濡傛灉涓嶆垚鍔熷氨鏄?.0 fmt.Println(bottle.Get([]byte("foo")).Float()) user := Userinfo{ Name: "Leon Ding", Age: 22, Skill: []string{"Java", "Go", "Rust"}, } var u Userinfo // 閫氳繃Bson淇濆瓨鏁版嵁瀵硅薄锛屽苟涓旇缃秴鏃舵椂闂翠负5绉掞紝TTL瓒呮椂鍙互涓嶈缃湅闇€姹? bottle.Put([]byte("user"), bottle.Bson(&user), bottle.TTL(5)) // 閫氳繃Unwrap瑙f瀽鍑虹粨鏋勪綋 bottle.Get([]byte("user")).Unwrap(&u) // 鎵撳嵃鍙栧€? fmt.Println(u) // 鍒犻櫎涓€涓猭ey bottle.Remove([]byte("foo")) // 鍏抽棴澶勭悊涓€涓嬪彲鑳藉彂鐢熺殑閿欒 if err := bottle.Close(); err != nil { fmt.Println(err) } }鍔犲瘑鍣?/h3>
鏁版嵁鍔犲瘑鍣ㄦ槸閽堝鏁版嵁鐨?code>value璁板綍鐨勶紝涔熷氨鏄拡瀵瑰瓧娈电骇鍒殑鍖哄潡鍔犲瘑锛屽苟闈炴槸鎶婃暣涓枃浠跺姞瀵嗕竴閬嶏紝閭f牱璁捐浼氬甫鏉ユ€ц兘娑堣€楋紝鎵€浠ラ噰鐢ㄥ尯鍧楁暟鎹鏂瑰紡鍔犲瘑鐨勬柟寮忋€?/p>
涓嬮潰渚嬪瓙鏄€氳繃
func init() { bottle.SetEncryptor(bottle.AES(), []byte("1234567890123456")) }浣犱篃鍙互鑷畾涔夊幓瀹炵幇鏁版嵁鍔犲瘑鍣ㄧ殑鎺ュ彛锛?/p>
// SourceData for encryption and decryption type SourceData struct { Data []byte Secret []byte } // Encryptor used for data encryption and decryption operation type Encryptor interface { Encode(sd *SourceData) error Decode(sd *SourceData) error }涓嬮潰浠g爜灏辨槸鍐呯疆
// AESEncryptor Implement the Encryptor interface type AESEncryptor struct{} // Encode source data encode func (AESEncryptor) Encode(sd *SourceData) error { sd.Data = aesEncrypt(sd.Data, sd.Secret) return nil } // Decode source data decode func (AESEncryptor) Decode(sd *SourceData) error { sd.Data = aesDecrypt(sd.Data, sd.Secret) return nil }鍏蜂綋鐨勫姞瀵嗗櫒瀹炵幇浠g爜鍙互鏌ョ湅
type Hashed interface { Sum64([]byte) uint64 }鐒跺悗閫氳繃鍐呯疆鐨?a href="https://link.segmentfault.com/?enc=9L62AyzRXw1Wk6CVUoxITQ%3D%3D.r7hz9RdaVfsmeGM2dTmw%2B9W%2BZPJHHHesSFCkslmp014%2BwZfDuNO9PQV1AEqL3fhX%2BNyEaDoLzB1xMfQlZog0Yw%3D%3D" rel="nofollow">
func init() { // 璁剧疆绱㈠紩澶у皬 bottle.SetIndexSize(1000) }閰嶇疆淇℃伅
浣犱篃鍙互涓嶄娇鐢ㄩ粯璁ら厤缃紝浣犲彲浠ヤ娇鐢ㄥ唴缃殑
func init() { // 鑷畾涔夐厤缃俊鎭? option := bottle.Option{ // 宸ヤ綔鐩綍 Directory: "./data", // 绠楁硶寮€鍚姞瀵? Enable: true, // 鑷畾涔夌閽ワ紝鍙互浣跨敤鍐呯疆鐨勭閽? Secret: bottle.Secret, // 鑷畾涔夋暟鎹ぇ灏忥紝瀛樺偍鍗曚綅鏄痥b DataFileMaxSize: 1048576, } // 閫氳繃鑷畾涔夐厤缃俊鎭? bottle.Open(option) }
近期热门
站内热门
最新文章
热门专题
