X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=testapplication%2Fgo%2Fsdl%2Fsdl.go;h=315afa86f6428f7b160c33b3a8256c201e71b746;hb=bee504ced3a7785d657afcbdfbfad75c6abbe696;hp=2a40dac8de9760c175cc7a5c584797a583640c08;hpb=99f548c04df61680aa16e76f8135201cb09914be;p=ric-plt%2Fdbaas.git diff --git a/testapplication/go/sdl/sdl.go b/testapplication/go/sdl/sdl.go index 2a40dac..315afa8 100644 --- a/testapplication/go/sdl/sdl.go +++ b/testapplication/go/sdl/sdl.go @@ -21,6 +21,7 @@ package sdl import ( + "fmt" "github.com/go-redis/redis" "os" "reflect" @@ -53,10 +54,35 @@ func Create(nameSpace string) *SdlInstance { nsPrefix: "{" + nameSpace + "},", client: client, } + s.CheckRedisModuleExtensionCommands() return &s } +func (s *SdlInstance) CheckRedisModuleExtensionCommands() { + var moduleError bool + commands, err := s.client.Command().Result() + if err == nil { + redisModuleCommands := []string{ + "setie", "delie", "setiepub", "deliepub", + "setnxpub", "msetmpub", "delmpub", + } + for _, v := range redisModuleCommands { + _, ok := commands[v] + if !ok { + fmt.Println("ERROR: Missing command:", v) + moduleError = true + } + } + } else { + fmt.Println("ERROR:", err) + } + if moduleError { + fmt.Println("Please make sure that redis extension modules have been installed.") + fmt.Println("To install: redis-cli module load /usr/local/libexec/redismodule/libredismodule.so") + } +} + func (s *SdlInstance) setNamespaceToKeys(pairs ...interface{}) []interface{} { var retVal []interface{} for i, v := range pairs { @@ -91,6 +117,19 @@ func (s *SdlInstance) setNamespaceToKeys(pairs ...interface{}) []interface{} { return retVal } +func checkResultAndError(result interface{}, err error) (bool, error) { + if err != nil { + if err == redis.Nil { + return false, nil + } + return false, err + } + if result == "OK" { + return true, nil + } + return false, nil +} + func (s *SdlInstance) Set(pairs ...interface{}) error { keyAndData := s.setNamespaceToKeys(pairs...) err := s.client.MSet(keyAndData...).Err() @@ -113,8 +152,8 @@ func (s *SdlInstance) Get(keys []string) (map[string]interface{}, error) { return m, err } -func (s *SdlInstance) SetIf(key string, oldData, newData interface{}) { - panic("SetIf not implemented\n") +func (s *SdlInstance) SetIf(key string, oldData, newData interface{}) (bool, error) { + return checkResultAndError(s.client.Do("SETIE", key, newData, oldData).Result()) } func (s *SdlInstance) SetIfiNotExists(key string, data interface{}) { @@ -136,4 +175,3 @@ func (s *SdlInstance) GetAll() []string { func (s *SdlInstance) RemoveAll() { panic("RemoveAll not implemented\n") } -