Example #1
0
/**
添加数据
**/
func Add(readyData *Entity.ReadyData, waitData *Entity.WaitData, key string, value interface{}, expired uint) error {
	//如果到期时间为0,表示是一个需要立即执行的任务,直接放入readyData列表中
	//不为0,放入waitData,等待时间到期
	if expired == 0 {
		readyData.Add(key, value, expired)
	} else {
		waitData.Add(key, value, expired)
	}
	//存储数据
	Store.SetData(readyData, waitData)
	return nil
}
Example #2
0
/**
增加任务到期时间
**/
func AddExpired(readyData *Entity.ReadyData, waitData *Entity.WaitData, key string, expired uint) error {
	//增加到期时间,就从就绪队列中删除,并添加到wait队列中
	if readyData.Isset(key) {
		waitData.Add(key, (*readyData)[key].Value, (*readyData)[key].Expired)
		readyData.Del(key)
		//存储数据
		Store.SetData(readyData, waitData)
		return nil
	}
	//在wait队列中的,只更新到期时间
	if waitData.Isset(key) {
		waitData.AddExpired(key, expired)
		//存储数据
		Store.SetData(readyData, waitData)
		return nil
	}
	return Utils.LogErr(1001)
}