登录
首页 >  数据库 >  MySQL

鎺ㄨ崘涓€涓秴绾ц交閲忕骇KV瀛樺偍馃敟

来源:SegmentFault

时间:2023-02-16 15:28:38 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)
}

褰撶劧涔熷彲浠ヤ娇鐢ㄥ唴缃殑

# Bottle config options
Enable: TRUE
Secret: "1234567890123456"
Directory: "./testdata"
DataFileMaxSize: 536870912

闇€瑕佹敞鎰忕殑鏄唴缃殑鍔犲瘑鍣ㄥ疄鐜扮殑绉橀挜蹇呴』鏄?code>16
浣嶏紝濡傛灉浣犳槸鑷畾涔夊疄鐜扮殑鍔犲瘑鍣ㄥ彲閫氳繃

./testdata
鈹溾攢鈹€ data
鈹?  鈹斺攢鈹€ 1.data
鈹斺攢鈹€ index
    鈹溾攢鈹€ 1646378326.index
    鈹斺攢鈹€ 1646378328.index

2 directories, 3 files

褰撳瓨鍌ㄥ紩鎿庡紑濮嬪伐浣滅殑鏃跺€欙紝杩欎釜鐩綍涓嬬殑鎵€浠ユ枃浠跺す鍜屾枃浠跺彧鑳借杩欎釜杩涚▼鎿嶄綔锛屼繚璇佹暟鎹畨鍏ㄣ€?/p>

鍚庣画缁存姢

鍏朵粬淇℃伅

濡傛灉浣犲彂鐜颁簡bug娆㈣繋鎻?code>issue鎴栬€呭彂璧?code>pull request锛屾垜鏀跺埌浜嗘秷鎭細灏藉揩鍥炲浣狅紝鍙﹀娆㈣繋鍚勪綅

Gopher
鎻愬嚭鑷繁鎰忚锛屾垨鑰呰础鐚仛鑷繁鐨勪唬鐮佷篃鏄彲浠ョ殑锛屽彟澶栨垜浠篃闈炲父娆㈣繋澶у杩涜瀛樺偍鐩稿叧鎶€鏈氦娴侊紝涓嶉敊鐨勮瘽鍒繕鍘?code>Github鐐逛竴涓?code>猸?/code>Thanks鈾?锝ハ夛渐)锞夈€?/p>

鏇磋缁嗙殑闂鍙互鏌ョ湅锛?a href="https://link.segmentfault.com/?enc=JX7jSGBTnaM7n2S0JB06hw%3D%3D.13CqOVDGBgDUD8dW%2Fv0DQ1uu4McR1Ppl6O2sAHZDzBI%3D" rel="nofollow">https://github.com/auula/bottle

今天带大家了解了MySQL、Java、鍚庣、鏁版嵁搴?/a>go的相关知识,希望对你有所帮助;关于数据库的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~

声明:本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>
评论列表