Documentation
¶
Overview ¶
Example ¶
package main
import (
"context"
"fmt"
"time"
"github.com/boxgo/box/pkg/cache/rediscache"
"github.com/boxgo/box/pkg/util/strutil"
)
var inst = rediscache.StdConfig("default").Build()
func main() {
val := ""
ctx := context.Background()
testKey := strutil.RandomAlphabet(10)
testVal := strutil.RandomAlphabet(100)
if err := inst.Set(ctx, testKey, testVal, time.Second*5); err != nil {
panic(err)
}
if err := inst.Get(ctx, testKey, &val); err != nil {
panic(err)
}
fmt.Println(testVal == val)
}
Output: true
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
Default = StdConfig("default").Build()
)
Functions ¶
func Get ¶
Example ¶
package main
import (
"bytes"
"context"
"encoding/json"
"fmt"
"time"
"github.com/boxgo/box/pkg/cache/rediscache"
"github.com/boxgo/box/pkg/util/strutil"
)
var inst = rediscache.StdConfig("default").Build()
func main() {
type (
testStruct struct {
String string
Int int
StringSlice []string
Boolean bool
Map map[string]interface{}
}
)
ctx := context.Background()
testKey := strutil.RandomAlphabet(10)
testVal := testStruct{
String: "box",
Int: 1234,
StringSlice: []string{"tom", "andy", "luck"},
Boolean: true,
Map: map[string]interface{}{
"int": 99,
"sliceInt": []int{1, 2, 3},
"mapStringString": map[string]string{
"key1": "val1",
"key2": "val2",
},
},
}
err := inst.Set(ctx, testKey, testVal, time.Second*5)
if err != nil {
panic(err)
}
val := testStruct{}
err = inst.Get(ctx, testKey, &val)
a, _ := json.Marshal(val)
b, _ := json.Marshal(testVal)
fmt.Println(bytes.Compare(a, b) == 0)
}
Output: true
Types ¶
type Config ¶
type Config struct {
Prefix string `config:"prefix" desc:"cache key prefix. if empty, auto prefix with format: ${serviceName}.cache.${key}."`
Marshaller string `config:"marshaller" desc:"support json only"`
Config string `config:"config" desc:"redis config path. eg: 'default' means use 'redis.default' config"`
BigCacheSize int `config:"bigCacheSize" desc:"big cache size, unit: byte"`
// contains filtered or unexported fields
}
func DefaultConfig ¶
Click to show internal directories.
Click to hide internal directories.