Revert "Support for XApp configuration update"
[ric-plt/appmgr.git] / internal / sdlgo / internal / sdlgoredis / sdlgoredis.go
1 package sdlgoredis
2
3 import (
4         "os"
5
6         "github.com/go-redis/redis"
7 )
8
9 type DB struct {
10         client *redis.Client
11 }
12
13 func Create() *DB {
14         hostname := os.Getenv("DBAAS_SERVICE_HOST")
15         if hostname == "" {
16                 hostname = "localhost"
17         }
18         port := os.Getenv("DBAAS_SERVICE_PORT")
19         if port == "" {
20                 port = "6379"
21         }
22         redisAddress := hostname + ":" + port
23         client := redis.NewClient(&redis.Options{
24                 Addr:     redisAddress,
25                 Password: "", // no password set
26                 DB:       0,  // use default DB
27                 PoolSize: 20,
28         })
29
30         db := DB{
31                 client: client,
32         }
33
34         return &db
35 }
36
37 func (db *DB) Close() error {
38         return db.Close()
39 }
40
41 func (db *DB) MSet(pairs ...interface{}) error {
42         return db.client.MSet(pairs...).Err()
43 }
44
45 func (db *DB) MGet(keys []string) ([]interface{}, error) {
46         val, err := db.client.MGet(keys...).Result()
47         return val, err
48 }
49
50 func (db *DB) Del(keys []string) error {
51         _, err := db.client.Del(keys...).Result()
52         return err
53 }
54
55 func (db *DB) Keys(pattern string) ([]string, error) {
56         val, err := db.client.Keys(pattern).Result()
57         return val, err
58 }