本文整理匯總了Golang中github.com/cgrates/cgrates/cache.RemKey函數的典型用法代碼示例。如果您正苦於以下問題:Golang RemKey函數的具體用法?Golang RemKey怎麽用?Golang RemKey使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了RemKey函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SetActionPlan
func (rs *RedisStorage) SetActionPlan(key string, ats *ActionPlan, overwrite bool, transactionID string) (err error) {
cCommit := cacheCommit(transactionID)
if len(ats.ActionTimings) == 0 {
// delete the key
err = rs.Cmd("DEL", utils.ACTION_PLAN_PREFIX+key).Err
cache.RemKey(utils.ACTION_PLAN_PREFIX+key, cCommit, transactionID)
return err
}
if !overwrite {
// get existing action plan to merge the account ids
if existingAts, _ := rs.GetActionPlan(key, true, transactionID); existingAts != nil {
if ats.AccountIDs == nil && len(existingAts.AccountIDs) > 0 {
ats.AccountIDs = make(utils.StringMap)
}
for accID := range existingAts.AccountIDs {
ats.AccountIDs[accID] = true
}
}
// do not keep this in cache (will be obsolete)
cache.RemKey(utils.ACTION_PLAN_PREFIX+key, cCommit, transactionID)
}
result, err := rs.ms.Marshal(ats)
if err != nil {
return err
}
var b bytes.Buffer
w := zlib.NewWriter(&b)
w.Write(result)
w.Close()
err = rs.Cmd("SET", utils.ACTION_PLAN_PREFIX+key, b.Bytes()).Err
cache.RemKey(utils.ACTION_PLAN_PREFIX+key, cCommit, transactionID)
return
}
示例2: RemoveAlias
func (rs *RedisStorage) RemoveAlias(id string, transactionID string) (err error) {
key := utils.ALIASES_PREFIX + id
// get alias for values list
al, err := rs.GetAlias(id, false, transactionID)
if err != nil {
return
}
err = rs.Cmd("DEL", key).Err
if err != nil {
return err
}
cCommit := cacheCommit(transactionID)
cache.RemKey(key, cCommit, transactionID)
for _, value := range al.Values {
tmpKey := utils.ConcatenatedKey(al.GetId(), value.DestinationId)
for target, pairs := range value.Pairs {
for _, alias := range pairs {
rKey := utils.REVERSE_ALIASES_PREFIX + alias + target + al.Context
err = rs.Cmd("SREM", rKey, tmpKey).Err
if err != nil {
return err
}
cache.RemKey(rKey, cCommit, transactionID)
/*_, err = rs.GetReverseAlias(rKey, true) // recache
if err != nil {
return err
}*/
}
}
}
return
}
示例3: RemoveAlias
func (ms *MapStorage) RemoveAlias(key string, transactionID string) error {
// get alias for values list
al, err := ms.GetAlias(key, false, transactionID)
if err != nil {
return err
}
ms.mu.Lock()
defer ms.mu.Unlock()
key = utils.ALIASES_PREFIX + key
aliasValues := make(AliasValues, 0)
if values, ok := ms.dict[key]; ok {
ms.ms.Unmarshal(values, &aliasValues)
}
delete(ms.dict, key)
cCommit := cacheCommit(transactionID)
cache.RemKey(key, cCommit, transactionID)
for _, value := range al.Values {
tmpKey := utils.ConcatenatedKey(al.GetId(), value.DestinationId)
for target, pairs := range value.Pairs {
for _, alias := range pairs {
rKey := utils.REVERSE_ALIASES_PREFIX + alias + target + al.Context
ms.dict.srem(rKey, tmpKey, ms.ms)
cache.RemKey(rKey, cCommit, transactionID)
/*_, err = ms.GetReverseAlias(rKey, true) // recache
if err != nil {
return err
}*/
}
}
}
return nil
}
示例4: SetActionPlan
func (ms *MapStorage) SetActionPlan(key string, ats *ActionPlan, overwrite bool, transactionID string) (err error) {
cCommit := cacheCommit(transactionID)
if len(ats.ActionTimings) == 0 {
ms.mu.Lock()
defer ms.mu.Unlock()
// delete the key
delete(ms.dict, utils.ACTION_PLAN_PREFIX+key)
cache.RemKey(utils.ACTION_PLAN_PREFIX+key, cCommit, transactionID)
return
}
if !overwrite {
// get existing action plan to merge the account ids
if existingAts, _ := ms.GetActionPlan(key, true, transactionID); existingAts != nil {
if ats.AccountIDs == nil && len(existingAts.AccountIDs) > 0 {
ats.AccountIDs = make(utils.StringMap)
}
for accID := range existingAts.AccountIDs {
ats.AccountIDs[accID] = true
}
}
}
ms.mu.Lock()
defer ms.mu.Unlock()
result, err := ms.ms.Marshal(&ats)
ms.dict[utils.ACTION_PLAN_PREFIX+key] = result
cache.RemKey(utils.ACTION_PLAN_PREFIX+key, cCommit, transactionID)
return
}
示例5: UpdateReverseDestination
func (ms *MongoStorage) UpdateReverseDestination(oldDest, newDest *Destination, transactionID string) error {
session, col := ms.conn(colRds)
defer session.Close()
//log.Printf("Old: %+v, New: %+v", oldDest, newDest)
var obsoletePrefixes []string
var addedPrefixes []string
var found bool
for _, oldPrefix := range oldDest.Prefixes {
found = false
for _, newPrefix := range newDest.Prefixes {
if oldPrefix == newPrefix {
found = true
break
}
}
if !found {
obsoletePrefixes = append(obsoletePrefixes, oldPrefix)
}
}
for _, newPrefix := range newDest.Prefixes {
found = false
for _, oldPrefix := range oldDest.Prefixes {
if newPrefix == oldPrefix {
found = true
break
}
}
if !found {
addedPrefixes = append(addedPrefixes, newPrefix)
}
}
//log.Print("Obsolete prefixes: ", obsoletePrefixes)
//log.Print("Added prefixes: ", addedPrefixes)
// remove id for all obsolete prefixes
cCommit := cacheCommit(transactionID)
var err error
for _, obsoletePrefix := range obsoletePrefixes {
err = col.Update(bson.M{"key": obsoletePrefix}, bson.M{"$pull": bson.M{"value": oldDest.Id}})
if err != nil {
return err
}
cache.RemKey(utils.REVERSE_DESTINATION_PREFIX+obsoletePrefix, cCommit, transactionID)
}
// add the id to all new prefixes
for _, addedPrefix := range addedPrefixes {
_, err = col.Upsert(bson.M{"key": addedPrefix}, bson.M{"$addToSet": bson.M{"value": newDest.Id}})
if err != nil {
return err
}
cache.RemKey(utils.REVERSE_DESTINATION_PREFIX+addedPrefix, cCommit, transactionID)
}
return nil
}
示例6: UpdateReverseDestination
func (rs *RedisStorage) UpdateReverseDestination(oldDest, newDest *Destination, transactionID string) error {
//log.Printf("Old: %+v, New: %+v", oldDest, newDest)
var obsoletePrefixes []string
var addedPrefixes []string
var found bool
for _, oldPrefix := range oldDest.Prefixes {
found = false
for _, newPrefix := range newDest.Prefixes {
if oldPrefix == newPrefix {
found = true
break
}
}
if !found {
obsoletePrefixes = append(obsoletePrefixes, oldPrefix)
}
}
for _, newPrefix := range newDest.Prefixes {
found = false
for _, oldPrefix := range oldDest.Prefixes {
if newPrefix == oldPrefix {
found = true
break
}
}
if !found {
addedPrefixes = append(addedPrefixes, newPrefix)
}
}
//log.Print("Obsolete prefixes: ", obsoletePrefixes)
//log.Print("Added prefixes: ", addedPrefixes)
// remove id for all obsolete prefixes
cCommit := cacheCommit(transactionID)
var err error
for _, obsoletePrefix := range obsoletePrefixes {
err = rs.Cmd("SREM", utils.REVERSE_DESTINATION_PREFIX+obsoletePrefix, oldDest.Id).Err
if err != nil {
return err
}
cache.RemKey(utils.REVERSE_DESTINATION_PREFIX+obsoletePrefix, cCommit, transactionID)
}
// add the id to all new prefixes
for _, addedPrefix := range addedPrefixes {
err = rs.Cmd("SADD", utils.REVERSE_DESTINATION_PREFIX+addedPrefix, newDest.Id).Err
if err != nil {
return err
}
cache.RemKey(utils.REVERSE_DESTINATION_PREFIX+addedPrefix, cCommit, transactionID)
}
return nil
}
示例7: UpdateReverseDestination
func (ms *MapStorage) UpdateReverseDestination(oldDest, newDest *Destination, transactionID string) error {
//log.Printf("Old: %+v, New: %+v", oldDest, newDest)
var obsoletePrefixes []string
var addedPrefixes []string
var found bool
for _, oldPrefix := range oldDest.Prefixes {
found = false
for _, newPrefix := range newDest.Prefixes {
if oldPrefix == newPrefix {
found = true
break
}
}
if !found {
obsoletePrefixes = append(obsoletePrefixes, oldPrefix)
}
}
for _, newPrefix := range newDest.Prefixes {
found = false
for _, oldPrefix := range oldDest.Prefixes {
if newPrefix == oldPrefix {
found = true
break
}
}
if !found {
addedPrefixes = append(addedPrefixes, newPrefix)
}
}
//log.Print("Obsolete prefixes: ", obsoletePrefixes)
//log.Print("Added prefixes: ", addedPrefixes)
// remove id for all obsolete prefixes
cCommit := cacheCommit(transactionID)
var err error
for _, obsoletePrefix := range obsoletePrefixes {
ms.mu.Lock()
ms.dict.srem(utils.REVERSE_DESTINATION_PREFIX+obsoletePrefix, oldDest.Id, ms.ms)
ms.mu.Unlock()
cache.RemKey(utils.REVERSE_DESTINATION_PREFIX+obsoletePrefix, cCommit, transactionID)
}
// add the id to all new prefixes
for _, addedPrefix := range addedPrefixes {
ms.mu.Lock()
ms.dict.sadd(utils.REVERSE_DESTINATION_PREFIX+addedPrefix, newDest.Id, ms.ms)
ms.mu.Unlock()
cache.RemKey(utils.REVERSE_DESTINATION_PREFIX+addedPrefix, cCommit, transactionID)
}
return err
}
示例8: SetDerivedChargers
func (ms *MapStorage) SetDerivedChargers(key string, dcs *utils.DerivedChargers, transactionID string) error {
ms.mu.Lock()
defer ms.mu.Unlock()
cCommit := cacheCommit(transactionID)
key = utils.DERIVEDCHARGERS_PREFIX + key
if dcs == nil || len(dcs.Chargers) == 0 {
delete(ms.dict, key)
cache.RemKey(key, cCommit, transactionID)
return nil
}
result, err := ms.ms.Marshal(dcs)
ms.dict[key] = result
cache.RemKey(key, cCommit, transactionID)
return err
}
示例9: SetDerivedChargers
func (rs *RedisStorage) SetDerivedChargers(key string, dcs *utils.DerivedChargers, transactionID string) (err error) {
key = utils.DERIVEDCHARGERS_PREFIX + key
cCommit := cacheCommit(transactionID)
if dcs == nil || len(dcs.Chargers) == 0 {
err = rs.Cmd("DEL", key).Err
cache.RemKey(key, cCommit, transactionID)
return err
}
marshaled, err := rs.ms.Marshal(dcs)
if err != nil {
return err
}
err = rs.Cmd("SET", key, marshaled).Err
cache.RemKey(key, cCommit, transactionID)
return
}
示例10: SetSharedGroup
func (ms *MongoStorage) SetSharedGroup(sg *SharedGroup, transactionID string) (err error) {
session, col := ms.conn(colShg)
defer session.Close()
_, err = col.Upsert(bson.M{"id": sg.Id}, sg)
cache.RemKey(utils.SHARED_GROUP_PREFIX+sg.Id, cacheCommit(transactionID), transactionID)
return err
}
示例11: RemoveActions
func (ms *MongoStorage) RemoveActions(key string, transactionID string) error {
session, col := ms.conn(colAct)
defer session.Close()
err := col.Remove(bson.M{"key": key})
cache.RemKey(utils.ACTION_PREFIX+key, cacheCommit(transactionID), transactionID)
return err
}
示例12: AddLoadHistory
// Adds a single load instance to load history
func (rs *RedisStorage) AddLoadHistory(ldInst *utils.LoadInstance, loadHistSize int, transactionID string) error {
if loadHistSize == 0 { // Load history disabled
return nil
}
marshaled, err := rs.ms.Marshal(&ldInst)
if err != nil {
return err
}
_, err = Guardian.Guard(func() (interface{}, error) { // Make sure we do it locked since other instance can modify history while we read it
histLen, err := rs.Cmd("LLEN", utils.LOADINST_KEY).Int()
if err != nil {
return nil, err
}
if histLen >= loadHistSize { // Have hit maximum history allowed, remove oldest element in order to add new one
if err := rs.Cmd("RPOP", utils.LOADINST_KEY).Err; err != nil {
return nil, err
}
}
err = rs.Cmd("LPUSH", utils.LOADINST_KEY, marshaled).Err
return nil, err
}, 0, utils.LOADINST_KEY)
cache.RemKey(utils.LOADINST_KEY, cacheCommit(transactionID), transactionID)
return err
}
示例13: RemoveDestination
func (ms *MongoStorage) RemoveDestination(destID string, transactionID string) (err error) {
session, col := ms.conn(colDst)
key := utils.DESTINATION_PREFIX + destID
// get destination for prefix list
d, err := ms.GetDestination(destID, false, transactionID)
if err != nil {
return
}
err = col.Remove(bson.M{"key": key})
if err != nil {
return err
}
cache.RemKey(key, cacheCommit(transactionID), transactionID)
session.Close()
session, col = ms.conn(colRds)
defer session.Close()
for _, prefix := range d.Prefixes {
err = col.Update(bson.M{"key": prefix}, bson.M{"$pull": bson.M{"value": destID}})
if err != nil {
return err
}
ms.GetReverseDestination(prefix, true, transactionID) // it will recache the destination
}
return
}
示例14: GetLoadHistory
// Limit will only retrieve the last n items out of history, newest first
func (ms *MongoStorage) GetLoadHistory(limit int, skipCache bool, transactionID string) (loadInsts []*utils.LoadInstance, err error) {
if limit == 0 {
return nil, nil
}
if !skipCache {
if x, ok := cache.Get(utils.LOADINST_KEY); ok {
if x != nil {
items := x.([]*utils.LoadInstance)
if len(items) < limit || limit == -1 {
return items, nil
}
return items[:limit], nil
}
return nil, utils.ErrNotFound
}
}
var kv struct {
Key string
Value []*utils.LoadInstance
}
session, col := ms.conn(colLht)
defer session.Close()
err = col.Find(bson.M{"key": utils.LOADINST_KEY}).One(&kv)
cCommit := cacheCommit(transactionID)
if err == nil {
loadInsts = kv.Value
cache.RemKey(utils.LOADINST_KEY, cCommit, transactionID)
cache.Set(utils.LOADINST_KEY, loadInsts, cCommit, transactionID)
}
if len(loadInsts) < limit || limit == -1 {
return loadInsts, nil
}
return loadInsts[:limit], nil
}
示例15: RemoveActionTriggers
func (ms *MapStorage) RemoveActionTriggers(key string, transactionID string) (err error) {
ms.mu.Lock()
defer ms.mu.Unlock()
delete(ms.dict, utils.ACTION_TRIGGER_PREFIX+key)
cache.RemKey(key, cacheCommit(transactionID), transactionID)
return
}