package com.ks.tool.bkz.service.manager;
|
|
import org.springframework.stereotype.Component;
|
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.JedisPool;
|
|
import javax.annotation.Resource;
|
|
@Component
|
public class RedisManager {
|
|
@Resource
|
private JedisPool jedisPool;
|
|
|
public void save(String key, String value, int expire) {
|
Jedis jedis = jedisPool.getResource();
|
try {
|
jedis.setex(key, expire, value);
|
} finally {
|
jedisPool.returnResource(jedis);
|
}
|
}
|
|
public void delete(String key) {
|
Jedis jedis = jedisPool.getResource();
|
try {
|
jedis.del(key);
|
} finally {
|
jedisPool.returnResource(jedis);
|
}
|
}
|
|
public String get(String key) {
|
Jedis jedis = jedisPool.getResource();
|
try {
|
return jedis.get(key);
|
} finally {
|
jedisPool.returnResource(jedis);
|
}
|
}
|
|
}
|