2 * Copyright 2018 NEC Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 "github.com/go-redis/redis"
24 // RedisPool is an implementation of Pool by redis.
25 type RedisPool struct {
29 // Set is to set data in redis.
30 func (thisPool RedisPool) Set(key string, data string) error {
31 key = redisLabel + "/" + key
32 err := thisPool.Client.Set(key, data, 0).Err()
34 log.Printf("redis Set error: %s", err)
39 // Get is to get data in redis.
40 func (thisPool RedisPool) Get(key string) (string, error) {
41 key = redisLabel + "/" + key
42 value, err := thisPool.Client.Get(key).Result()
44 log.Printf("redis Get error: %s", err)
49 // Del is to delete data in redis.
50 func (thisPool RedisPool) Del(key string) error {
51 key = redisLabel + "/" + key
52 err := thisPool.Client.Del(key).Err()
54 log.Printf("redis Del error: %s", err)
59 // DelAll is to delete all data, begins with <redisLabel>, in redis.
60 func (thisPool RedisPool) DelAll() error {
61 pattern := redisLabel + "/*"
63 keys, err := thisPool.Client.Keys(pattern).Result()
65 log.Printf("redis Keys error :%s", err)
68 for _, v := range keys {
69 thisPool.Client.Del(v)