码迷,mamicode.com
首页 > 其他好文 > 详细

RedisService

时间:2016-09-05 13:38:38      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.sprucetec.bone.common.redis;

import com.alibaba.fastjson.JSON;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;
import redis.clients.util.Pool;

@Service
public class RedisService {
@Autowired
private Pool<Jedis> pool;

public RedisService() {
}

public Pool<Jedis> getPool() {
return this.pool;
}

public boolean exists(String key) {
Jedis jedis = null;

boolean var3;
try {
jedis = (Jedis)this.pool.getResource();
var3 = jedis.exists(key).booleanValue();
} finally {
if(jedis != null) {
jedis.close();
}

}

return var3;
}

public long delete(String... keys) {
Jedis jedis = null;

long var3;
try {
jedis = (Jedis)this.pool.getResource();
var3 = jedis.del(keys).longValue();
} finally {
if(jedis != null) {
jedis.close();
}

}

return var3;
}

public String rename(String oldkey, String newkey) {
Jedis jedis = null;

String var4;
try {
jedis = (Jedis)this.pool.getResource();
var4 = jedis.rename(oldkey, newkey);
} finally {
if(jedis != null) {
jedis.close();
}

}

return var4;
}

public long expire(String key, int seconds) {
Jedis jedis = null;

long var4;
try {
jedis = (Jedis)this.pool.getResource();
var4 = jedis.expire(key, seconds).longValue();
} finally {
if(jedis != null) {
jedis.close();
}

}

return var4;
}

public long incrBy(String key, long integer) {
Jedis jedis = null;

long var5;
try {
jedis = (Jedis)this.pool.getResource();
var5 = jedis.incrBy(key, integer).longValue();
} finally {
if(jedis != null) {
jedis.close();
}

}

return var5;
}

public long incr(String key) {
Jedis jedis = null;

long var3;
try {
jedis = (Jedis)this.pool.getResource();
var3 = jedis.incr(key).longValue();
} finally {
if(jedis != null) {
jedis.close();
}

}

return var3;
}

public long decrBy(String key, long integer) {
Jedis jedis = null;

long var5;
try {
jedis = (Jedis)this.pool.getResource();
var5 = jedis.decrBy(key, integer).longValue();
} finally {
if(jedis != null) {
jedis.close();
}

}

return var5;
}

public long decr(String key) {
Jedis jedis = null;

long var3;
try {
jedis = (Jedis)this.pool.getResource();
var3 = jedis.decr(key).longValue();
} finally {
if(jedis != null) {
jedis.close();
}

}

return var3;
}

public <T> T getJSONToObject(Class<?> clazz, String key) {
Jedis jedis = null;

Object var5;
try {
jedis = (Jedis)this.pool.getResource();
String value = jedis.get(key);
var5 = JSON.toJavaObject((JSON)JSON.parse(value), clazz);
} finally {
if(jedis != null) {
jedis.close();
}

}

return var5;
}

public String getString(String key) {
Jedis jedis = null;

String var3;
try {
jedis = (Jedis)this.pool.getResource();
var3 = jedis.get(key);
} finally {
if(jedis != null) {
jedis.close();
}

}

return var3;
}

public <T> List<T> mget(Class<?> clazz, String... keys) {
ArrayList list = new ArrayList();
Jedis jedis = null;

try {
jedis = (Jedis)this.pool.getResource();
List values = jedis.mget(keys);
Iterator var6 = values.iterator();

while(var6.hasNext()) {
String value = (String)var6.next();
list.add(JSON.toJavaObject((JSON)JSON.parse(value), clazz));
}

ArrayList var11 = list;
return var11;
} finally {
if(jedis != null) {
jedis.close();
}

}
}

public <T> String setObjectToJSON(String key, T value) {
Jedis jedis = null;

String var5;
try {
jedis = (Jedis)this.pool.getResource();
String str = JSON.toJSONString(value);
var5 = jedis.set(key, str);
} finally {
if(jedis != null) {
jedis.close();
}

}

return var5;
}

public String set(String key, String value) {
Jedis jedis = null;

String var4;
try {
jedis = (Jedis)this.pool.getResource();
var4 = jedis.set(key, value);
} finally {
if(jedis != null) {
jedis.close();
}

}

return var4;
}

public <T> String setex(String key, int seconds, T value) {
Jedis jedis = null;

String var6;
try {
jedis = (Jedis)this.pool.getResource();
String str = JSON.toJSONString(value);
var6 = jedis.setex(key, seconds, str);
} finally {
if(jedis != null) {
jedis.close();
}

}

return var6;
}

public <T> String mset(Map<String, T> map) {
Jedis jedis = null;

try {
jedis = (Jedis)this.pool.getResource();
String[] keyValues = new String[map.size() * 2];
int i = 0;

for(Iterator var5 = map.keySet().iterator(); var5.hasNext(); ++i) {
String key = (String)var5.next();
keyValues[2 * i] = key;
keyValues[2 * i + 1] = JSON.toJSONString(map.get(key));
}

String var10 = jedis.mset(keyValues);
return var10;
} finally {
if(jedis != null) {
jedis.close();
}

}
}

public <T> Long msetnx(Map<String, T> map) {
Jedis jedis = null;

try {
jedis = (Jedis)this.pool.getResource();
String[] keyValues = new String[map.size() * 2];
int i = 0;

for(Iterator var5 = map.keySet().iterator(); var5.hasNext(); ++i) {
String key = (String)var5.next();
keyValues[2 * i] = key;
keyValues[2 * i + 1] = JSON.toJSONString(map.get(key));
}

Long var10 = jedis.msetnx(keyValues);
return var10;
} finally {
if(jedis != null) {
jedis.close();
}

}
}

public int hset(String key, String field, String value) {
Jedis jedis = null;

int var5;
try {
jedis = (Jedis)this.pool.getResource();
var5 = jedis.hset(key, field, value).intValue();
} finally {
if(jedis != null) {
jedis.close();
}

}

return var5;
}

public String hget(String key, String field) {
Jedis jedis = null;

String var4;
try {
jedis = (Jedis)this.pool.getResource();
var4 = jedis.hget(key, field);
} finally {
if(jedis != null) {
jedis.close();
}

}

return var4;
}

public Map<String, String> hgetAll(String key) {
Jedis jedis = null;

Map var3;
try {
jedis = (Jedis)this.pool.getResource();
var3 = jedis.hgetAll(key);
} finally {
if(jedis != null) {
jedis.close();
}

}

return var3;
}

public long hdel(String hashKey, String taskId) {
Jedis jedis = null;

long var4;
try {
jedis = (Jedis)this.pool.getResource();
var4 = jedis.hdel(hashKey, new String[]{taskId}).longValue();
} finally {
if(jedis != null) {
jedis.close();
}

}

return var4;
}
}

RedisService

标签:

原文地址:http://www.cnblogs.com/duyinqiang/p/5841803.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!