Skip to content

jau1jz/map-ttl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 

Repository files navigation

map-ttl

golang ttl map like redis

func main() {
	tmap := map_ttl.Map_ttl{}
	tmap.Init()
	c := make(chan interface{})
	tmap.Set_callback(&c) //set callback chan this chan will be receive data when timeout , but if you del key by func Del() this chan don't work
	tmap.Set("jone","taylar",time.Second * 60) // 60s ttl
	tmap.Set("jack","ma",0) //no ttl
	tmap.Set("jack","ma",time.Second * 60) //reset ttl to 60s
	tmap.SetData("jack","li") //if don't have key "jack" func will be return false
	tmap.Get("jone") //get value
	tmap.Del("jone")
	tmap.Clear()//clear map
	tmap.Range(func(key interface{}, value interface{}) {
        //in func Range just can use unsafe func
        tmap.UnsafeSetData("jack","Hu")
        tmap.UnsafeSetData("jack","Hu")
	})
	go func() {
		for {
			select {
			case <- c :
				//timeout do something

			}
		}
	}()
}

About

a ttl map

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages