Giter Club home page Giter Club logo

triecache's Introduction

triecache

triecache是一个内存中的 key - value 缓存,用法类似redis,对于一些想要临时存储一些数据,但是没必要接入redis的场景适用;原理是通过树形结构实现的,相较于根据map[string]interface{} 的 go-cache 等,实现了前缀搜索的功能,例如 key: abcdefg 可以使用 abc*搜索

安装

go get -u github.com/lzy1102/triecache

用法

package main

import (
	"fmt"
	"github.com/lzy1102/triecache"
	"time"
)

func main() {
	key := "hellofdafas123"
	key2 := "helloerqwr456"
	value := 10
	var c triecache.Cache
	c = triecache.New(time.Minute*5, time.Second*10)
	err := c.Set(key, value, time.Second*10)
	if err != nil {
		panic(err)
	}
	c.Set(key2, value, time.Second)
	time.Sleep(time.Second * 2)
	get, err := c.Get(key)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println("key ", key, "  value ", get)

	get, err = c.Get(key2)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println("key2 ", key2, "  value2 ", get)
	keys, err := c.Keys("hello*")
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println("keys ", keys)
	for _, s := range keys {
		v, _ := c.Get(s)
		fmt.Println(s, v)
	}
}

triecache's People

Contributors

lzy1102 avatar

Stargazers

科科 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.