github.com/cockroachdb/pebble@v0.0.0-20231214172447-ab4952c5f87b/example_test.go (about)

     1  // Copyright 2020 The LevelDB-Go and Pebble Authors. All rights reserved. Use
     2  // of this source code is governed by a BSD-style license that can be found in
     3  // the LICENSE file.
     4  
     5  package pebble_test
     6  
     7  import (
     8  	"fmt"
     9  	"log"
    10  
    11  	"github.com/cockroachdb/pebble"
    12  	"github.com/cockroachdb/pebble/vfs"
    13  )
    14  
    15  func Example() {
    16  	db, err := pebble.Open("", &pebble.Options{FS: vfs.NewMem()})
    17  	if err != nil {
    18  		log.Fatal(err)
    19  	}
    20  	key := []byte("hello")
    21  	if err := db.Set(key, []byte("world"), pebble.Sync); err != nil {
    22  		log.Fatal(err)
    23  	}
    24  	value, closer, err := db.Get(key)
    25  	if err != nil {
    26  		log.Fatal(err)
    27  	}
    28  	fmt.Printf("%s %s\n", key, value)
    29  	if err := closer.Close(); err != nil {
    30  		log.Fatal(err)
    31  	}
    32  	if err := db.Close(); err != nil {
    33  		log.Fatal(err)
    34  	}
    35  	// Output:
    36  	// hello world
    37  }