mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 05:39:54 +05:00
RedisNotFound error for GetAccount
This commit is contained in:
@@ -46,6 +46,11 @@ func init() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
const (
|
||||
META_CCR_USAGE = "*ccr_usage"
|
||||
META_CCR_SMG_EVENT_NAME = "*ccr_smg_event_name"
|
||||
)
|
||||
|
||||
func loadDictionaries(dictsDir, componentId string) error {
|
||||
fi, err := os.Stat(dictsDir)
|
||||
if err != nil {
|
||||
@@ -329,6 +334,11 @@ func avpValAsString(a *diam.AVP) string {
|
||||
// Extracts data out of CCR into a SMGenericEvent based on the configured template
|
||||
func (self *CCR) AsSMGenericEvent(tpl []*config.CfgCdrField) (sessionmanager.SMGenericEvent, error) {
|
||||
outMap := make(map[string]string) // work with it so we can append values to keys
|
||||
if evName, err := self.metaHandler(META_CCR_SMG_EVENT_NAME, ""); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
outMap[utils.EVENT_NAME] = evName
|
||||
}
|
||||
for _, fldTpl := range tpl {
|
||||
var outVal string
|
||||
for _, rsrTpl := range fldTpl.Value {
|
||||
@@ -361,6 +371,17 @@ func (self *CCR) AsSMGenericEvent(tpl []*config.CfgCdrField) (sessionmanager.SMG
|
||||
return sessionmanager.SMGenericEvent(utils.ConvertMapValStrIf(outMap)), nil
|
||||
}
|
||||
|
||||
// Handler for meta functions
|
||||
func (self *CCR) metaHandler(tag, arg string) (string, error) {
|
||||
switch tag {
|
||||
case META_CCR_SMG_EVENT_NAME:
|
||||
return "", nil
|
||||
case META_CCR_USAGE:
|
||||
return "", nil
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func NewCCAFromCCR(ccr *CCR) *CCA {
|
||||
return &CCA{SessionId: ccr.SessionId, AuthApplicationId: ccr.AuthApplicationId, CCRequestType: ccr.CCRequestType, CCRequestNumber: ccr.CCRequestNumber,
|
||||
diamMessage: diam.NewMessage(ccr.diamMessage.Header.CommandCode, ccr.diamMessage.Header.CommandFlags&^diam.RequestFlag, ccr.diamMessage.Header.ApplicationID,
|
||||
|
||||
@@ -23,14 +23,17 @@ import (
|
||||
"compress/zlib"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/cache2go"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/mediocregopher/radix.v2/pool"
|
||||
"github.com/mediocregopher/radix.v2/redis"
|
||||
)
|
||||
|
||||
"io/ioutil"
|
||||
"time"
|
||||
var (
|
||||
ErrRedisNotFound = errors.New("RedisNotFound")
|
||||
)
|
||||
|
||||
type RedisStorage struct {
|
||||
@@ -607,14 +610,22 @@ func (rs *RedisStorage) SetSharedGroup(sg *SharedGroup) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) GetAccount(key string) (ub *Account, err error) {
|
||||
var values []byte
|
||||
if values, err = rs.db.Cmd("GET", utils.ACCOUNT_PREFIX+key).Bytes(); err == nil {
|
||||
ub = &Account{Id: key}
|
||||
err = rs.ms.Unmarshal(values, ub)
|
||||
func (rs *RedisStorage) GetAccount(key string) (*Account, error) {
|
||||
rpl := rs.db.Cmd("GET", utils.ACCOUNT_PREFIX+key)
|
||||
if rpl.Err != nil {
|
||||
return nil, rpl.Err
|
||||
} else if rpl.IsType(redis.Nil) {
|
||||
return nil, ErrRedisNotFound
|
||||
}
|
||||
|
||||
return
|
||||
values, err := rpl.Bytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ub := &Account{Id: key}
|
||||
if err = rs.ms.Unmarshal(values, ub); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ub, nil
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) SetAccount(ub *Account) (err error) {
|
||||
|
||||
Reference in New Issue
Block a user