package main import ( "encoding/binary" "log" "sync" "github.com/tecbot/gorocksdb" ) func CreateData() { db, cfs := OpenDataBase() GCOUNT := 10 wg := &sync.WaitGroup{} wg.Add(GCOUNT) for i := 0; i < GCOUNT; i++ { go putData(wg, db, cfs) } wg.Wait() } func queryData(wg *sync.WaitGroup, db *gorocksdb.DB, cfs []*gorocksdb.ColumnFamilyHandle) { defer wg.Done() // now := time.Now().Unix() ro := gorocksdb.NewDefaultReadOptions() COUNT := 100 cf := cfs[len(cfs)-1] iter := db.NewIteratorCF(ro, cf) temp := make([]byte, 8) binary.BigEndian.PutUint64(temp, 10) iter.Seek(temp) log.Println(iter.Valid()) for i := 0; i < COUNT && iter.Valid(); i++ { bkey := iter.Key().Data() key := string(bkey) value := string(iter.Value().Data()) log.Println(binary.BigEndian.Uint64(bkey[0:8]), "\nkey:", key, "\n", "value:", value) iter.Next() } // log.Println(int64(COUNT) / (time.Now().Unix() - now)) } func QueryData() { db, cfs := OpenDataBase() GCOUNT := 1 wg := &sync.WaitGroup{} wg.Add(GCOUNT) for i := 0; i < GCOUNT; i++ { go queryData(wg, db, cfs) } wg.Wait() } func main() { QueryData() // CreateData() // db.Put(wo, []byte("foo"), []byte("bar")) // ro := gorocksdb.NewDefaultReadOptions() // db, err := gorocksdb.OpenDb(opts, "./.rocksdb") // if err != nil { // panic(err) // } // s, err := db.Get(ro, []byte("foo")) // if err != nil { // panic(err) // } // log.Println(string(s.Data())) }