apt install -y redis-tools && \
apt install -y git && \
apt install -y wget && \
- wget https://dl.google.com/go/go1.15.6.linux-amd64.tar.gz && \
- tar -xvf go1.15.6.linux-amd64.tar.gz && \
+ wget https://golang.org/dl/go1.12.17.linux-amd64.tar.gz && \
+ tar -xvf go1.12.17.linux-amd64.tar.gz && \
mv go /usr/local && \
apt-get clean
# Install go testapplication
RUN export GOROOT=/usr/local/go && \
- export GOPATH=$HOME/Projects/Proj1 && \
- export PATH=$GOPATH/bin:$GOROOT/bin:$PATH && \
+ export PATH=$GOROOT/bin:$PATH && \
+ export GO111MODULE=on && \
go get github.com/go-redis/redis && \
- go build /testapplication/go/testapp.go
+ cd /testapplication/go/ && \
+ go build ./...
# Keep the container alive
ENTRYPOINT ["tail", "-f", "/dev/null"]
func (s *SdlInstance) CheckRedisModuleExtensionCommands() {
var moduleError bool
- commands, err := s.client.Command(s.client.Context()).Result()
+ commands, err := s.client.Command().Result()
if err == nil {
redisModuleCommands := []string{
- "setie", "delie", "setiepub", "setnxpub",
- "msetmpub", "delmpub",
+ "setie", "delie", "setiepub", "deliepub",
+ "setnxpub", "msetmpub", "delmpub",
}
for _, v := range redisModuleCommands {
_, ok := commands[v]
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(s.client.Context(), keyAndData...).Err()
+ err := s.client.MSet(keyAndData...).Err()
return err
}
for _, v := range keys {
keysWithNs = append(keysWithNs, s.nsPrefix+v)
}
- val, err := s.client.MGet(s.client.Context(), keysWithNs...).Result()
+ val, err := s.client.MGet(keysWithNs...).Result()
m := make(map[string]interface{})
if err != nil {
return m, err
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{}) {
package main
import (
- "./sdl"
"fmt"
+ "testapp/sdl"
)
func main() {
fmt.Printf("unable to write to DB\n")
}
+ _, err = sdl1.SetIf("key1", "data1", "data2")
+ if err != nil {
+ fmt.Printf("unable to write to DB\n")
+ }
+
retDataMap, err := sdl1.Get([]string{"key1", "key3", "key2"})
if err != nil {
fmt.Printf("Unable to read from DB\n")