package com.bardframework.bard.util.cache;

import com.bardframework.bard.core.Util;
import redis.clients.jedis.Jedis;

public class RedisCache implements Cache {
    private final Jedis jedis = new Jedis(
        Util.getConfig().getString("bard.util.redis.host", "localhost"),
        Util.getConfig().getInt("bard.util.redis.port", 6379));

    private String name;

    public RedisCache() {
    }

    private String getkey(String key) {
        return name + "." + key;
    }

    @Override public void setName(String name) {
        this.name = name;
    }

    @Override public String get(String key) {
        return jedis.get(getkey(key));
    }

    @Override public void set(String key, String value) {
        jedis.set(getkey(key), value);
    }

    @Override public void setex(String key, final int seconds, String value) {
        jedis.setex(getkey(key), seconds, value);
    }

    @Override public void del(String key) {
        jedis.del(getkey(key));
    }
}

@@ -110,16 +110,64 @@
 is.Jedis
+Pool;%0Aimport redis.clients.jedis.JedisPoolConfig
 ;%0A%0Apubli
@@ -227,22 +227,30 @@
 al Jedis
+Pool
  jedis
+Pool
  = new J
@@ -253,17 +253,52 @@
 ew Jedis
-(
+Pool(%0A        new JedisPoolConfig(),
 %0A       
@@ -715,16 +715,34 @@
 rn jedis
+Pool.getResource()
 .get(get
@@ -826,24 +826,42 @@
        jedis
+Pool.getResource()
 .set(getkey(
@@ -973,16 +973,34 @@
    jedis
+Pool.getResource()
 .setex(g
@@ -1092,16 +1092,34 @@
    jedis
+Pool.getResource()
 .del(get

use jedis pool