-
Notifications
You must be signed in to change notification settings - Fork 71
/
docs.go
69 lines (55 loc) · 1.34 KB
/
docs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
Package gokv contains a simple key-value store abstraction in the form of a Go interface.
Implementations of the gokv.Store interface can be found in the sub-packages.
Usage
Example code for using Redis:
package main
import (
"fmt"
"github.com/philippgille/gokv"
"github.com/philippgille/gokv/redis"
)
type foo struct {
Bar string
}
func main() {
options := redis.DefaultOptions // Address: "localhost:6379", Password: "", DB: 0
// Create client
client, err := redis.NewClient(options)
if err != nil {
panic(err)
}
defer client.Close()
// Store, retrieve, print and delete a value
interactWithStore(client)
}
// interactWithStore stores, retrieves, prints and deletes a value.
// It's completely independent of the store implementation.
func interactWithStore(store gokv.Store) {
// Store value
val := foo{
Bar: "baz",
}
err := store.Set("foo123", val)
if err != nil {
panic(err)
}
// Retrieve value
retrievedVal := new(foo)
found, err := store.Get("foo123", retrievedVal)
if err != nil {
panic(err)
}
if !found {
panic("Value not found")
}
fmt.Printf("foo: %+v", *retrievedVal) // Prints `foo: {Bar:baz}`
// Delete value
err = store.Delete("foo123")
if err != nil {
panic(err)
}
}
More details can be found on https://github.com/philippgille/gokv.
*/
package gokv