2 Copyright (c) 2019 AT&T Intellectual Property.
3 Copyright (c) 2018-2019 Nokia.
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
25 "github.com/go-redis/redis"
34 hostname := os.Getenv("DBAAS_SERVICE_HOST")
36 hostname = "localhost"
38 port := os.Getenv("DBAAS_SERVICE_PORT")
42 redisAddress := hostname + ":" + port
43 client := redis.NewClient(&redis.Options{
45 Password: "", // no password set
46 DB: 0, // use default DB
55 commands, err := db.client.Command().Result()
57 redisModuleCommands := []string{"setie", "delie"}
58 for _, v := range redisModuleCommands {
61 db.redisModules = false
70 func (db *DB) Close() error {
71 return db.client.Close()
74 func (db *DB) MSet(pairs ...interface{}) error {
75 return db.client.MSet(pairs...).Err()
78 func (db *DB) MGet(keys []string) ([]interface{}, error) {
79 val, err := db.client.MGet(keys...).Result()
83 func (db *DB) Del(keys []string) error {
84 _, err := db.client.Del(keys...).Result()
88 func (db *DB) Keys(pattern string) ([]string, error) {
89 val, err := db.client.Keys(pattern).Result()
93 func (db *DB) SetIE(key string, oldData, newData interface{}) (bool, error) {
95 return false, errors.New("Redis deployment not supporting command")
98 result, err := db.client.Do("SETIE", key, newData, oldData).Result()
109 func (db *DB) SetNX(key string, data interface{}) (bool, error) {
110 result, err := db.client.SetNX(key, data, 0).Result()
114 func (db *DB) DelIE(key string, data interface{}) (bool, error) {
115 if !db.redisModules {
116 return false, errors.New("Redis deployment not supporting command")
118 result, err := db.client.Do("DELIE", key, data).Result()