Documentation ΒΆ
Index ΒΆ
- Variables
- func Hash(key []byte) uint64
- func Int2Bytes[I constraints.Integer](num I) []byte
- func IntHash[I constraints.Integer](num I) uint64
- func Path(num uint64) (string, string)
- type DB
- func (p *DB) Close()
- func (p *DB) Delete(key []byte) error
- func (p *DB) Get(key []byte) ([]byte, error)
- func (p *DB) GetByHash(hash uint64) ([]byte, error)
- func (p *DB) GetByPath(path string) ([]byte, error)
- func (p *DB) Has(key []byte) bool
- func (p *DB) Put(key, value []byte) *Result
- func (p *DB) PutTTL(key, value []byte, expire, access time.Duration) *Result
- func (p *DB) Refresh(hash uint64) error
- type Policy
- type Result
Examples ΒΆ
Constants ΒΆ
This section is empty.
Variables ΒΆ
View Source
var ( ErrIsDir = errors.New("is a directory") ErrNotFound = errors.New("not found") )
Functions ΒΆ
func Hash ΒΆ
Example ΒΆ
package main import ( "fmt" "github.com/xuender/fttl" ) func main() { fmt.Println(fttl.Hash([]byte("test"))) }
Output: 2771506328522617498
func Int2Bytes ΒΆ added in v0.0.3
func Int2Bytes[I constraints.Integer](num I) []byte
func IntHash ΒΆ added in v0.0.2
func IntHash[I constraints.Integer](num I) uint64
Example ΒΆ
package main import ( "fmt" "github.com/xuender/fttl" ) func main() { fmt.Println(fttl.IntHash(1)) fmt.Println(fttl.IntHash(2)) fmt.Println(fttl.IntHash(3)) }
Output: 3139486886484431350 3238141947922148205 4470094458844362118
Types ΒΆ
type DB ΒΆ
type DB struct {
// contains filtered or unexported fields
}
func (*DB) Get ΒΆ
Example ΒΆ
package main import ( "fmt" "os" "github.com/xuender/fttl" ) func main() { fdb := fttl.New(os.TempDir()) key := []byte("get") defer fdb.Delete(key) res := fdb.Put(key, []byte("value")) fmt.Println(res.Error) val, err := fdb.Get(key) fmt.Println(err) fmt.Println(string(val)) }
Output: <nil> <nil> value
func (*DB) Has ΒΆ added in v0.0.4
Example ΒΆ
package main import ( "fmt" "os" "time" "github.com/xuender/fttl" ) func main() { fdb := fttl.New(os.TempDir()) key := []byte("has") defer fdb.Delete(key) fdb.PutTTL(key, []byte("value"), time.Millisecond*100, 0) fmt.Println(fdb.Has(key)) time.Sleep(time.Millisecond * 200) fmt.Println(fdb.Has(key)) }
Output: true false
func (*DB) Put ΒΆ
Example ΒΆ
package main import ( "fmt" "os" "github.com/xuender/fttl" ) func main() { fdb := fttl.New(os.TempDir()) key := []byte("put") defer fdb.Delete(key) fdb.Put(key, []byte("value")) fdb.Put(key, []byte("value2")) val, _ := fdb.Get(key) fmt.Println(string(val)) }
Output: value2
func (*DB) PutTTL ΒΆ
Example ΒΆ
package main import ( "fmt" "os" "time" "github.com/xuender/fttl" ) func main() { fdb := fttl.New(os.TempDir()) key := []byte("ttl") defer fdb.Delete(key) fdb.PutTTL(key, []byte("value"), time.Millisecond*100, 0) val, _ := fdb.Get(key) fmt.Println(string(val)) time.Sleep(time.Millisecond * 200) _, err := fdb.Get(key) fmt.Println(err) }
Output: value not found
Click to show internal directories.
Click to hide internal directories.