本文整理汇总了Java中redis.clients.jedis.Jedis.get方法的典型用法代码示例。如果您正苦于以下问题:Java Jedis.get方法的具体用法?Java Jedis.get怎么用?Java Jedis.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redis.clients.jedis.Jedis
的用法示例。
在下文中一共展示了Jedis.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public byte[] get(byte[] key){
byte[] value = null;
Jedis jedis = null;
try{
jedis = get();
if (jedis == null)
return null;
value = jedis.get(key);
pool.returnResource(jedis);
}catch(Exception e){
pool.returnBrokenResource(jedis);
}
return value;
}
示例2: get
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 获取缓存
*
* @param key 键
* @return 值
*/
public static String get(String key) {
String value = null;
Jedis jedis = null;
try {
jedis = getResource();
if (jedis.exists(key)) {
value = jedis.get(key);
value = StringUtils.isNotBlank(value) && !"nil".equalsIgnoreCase(value) ? value : null;
logger.debug("get {} = {}", key, value);
}
} catch (Exception e) {
logger.warn("get {} = {}", key, value, e);
} finally {
returnResource(jedis);
}
return value;
}
示例3: loadSessionDataFromRedis
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public byte[] loadSessionDataFromRedis(String id) throws IOException {
Jedis jedis = null;
Boolean error = true;
try {
log.trace("Attempting to load session " + id + " from Redis");
jedis = acquireConnection();
byte[] data = jedis.get(id.getBytes());
error = false;
if (data == null) {
log.trace("Session " + id + " not found in Redis");
}
return data;
} finally {
if (jedis != null) {
returnConnection(jedis, error);
}
}
}
示例4: pullObject
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public Object pullObject(String key) {
log.trace("strar find cache with " + key);
Jedis jedis = null;
try {
jedis = redisConnection.getJedis();
jedis.select(dbIndex);
byte[] result = jedis.get(key.getBytes());
if (result == null) {
log.trace("can not find caceh with " + key);
return null;
} else {
log.trace("find cache success with " + key);
return SerializeUtil.unserialize(result);
}
} catch (Exception e) {
log.warn(e.getMessage(), e);
} finally {
if (jedis != null) {
jedis.close();
}
}
return null;
}
示例5: getStringAndSuccess
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 需要知道是否是成功获取的
*
* @param key
* @return
*/
public Object[] getStringAndSuccess(String key) {
Jedis jedis = null;
boolean success = true;
String ret = "";
try {
jedis = jedisPool.getResource();
if (jedis == null) {
success = false;
return null;
}
ret = jedis.get(key);
} catch (Exception e) {
success = false;
returnBrokenResource(jedis, "getString", e);
} finally {
releaseReidsSource(success, jedis);
}
Object[] object = new Object[2];
object[0] = success;
object[1] = ret;
return object;
}
示例6: foo
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
private static void foo() {
System.out.println("TEST Jedis ======================================================");
Jedis jedis = new Jedis(ip, port);
jedis.set("foo", "bar");
jedis.get("foo");
jedis.lpush("lll", "a");
jedis.lpush("lll", "b");
jedis.lpush("lll", "c");
jedis.lpop("lll");
jedis.lpop("lll");
jedis.lpop("lll");
jedis.hset("mmm", "abc", "123");
jedis.hset("mmm", "def", "456");
jedis.hgetAll("mmm");
jedis.close();
}
示例7: connectWithShardInfoAndCustomHostnameVerifier
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* Tests opening an SSL/TLS connection to redis with a custom hostname
* verifier.
*/
@Test
public void connectWithShardInfoAndCustomHostnameVerifier() {
final URI uri = URI.create("rediss://localhost:6390");
final SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
final SSLParameters sslParameters = new SSLParameters();
HostnameVerifier hostnameVerifier = new BasicHostnameVerifier();
JedisShardInfo shardInfo = new JedisShardInfo(uri, sslSocketFactory, sslParameters, hostnameVerifier);
shardInfo.setPassword("foobared");
Jedis jedis = new Jedis(shardInfo);
jedis.get("foo");
jedis.disconnect();
jedis.close();
}
示例8: connectWithShardInfoAndCustomSocketFactory
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* Tests opening an SSL/TLS connection to redis with a custom socket factory.
*/
@Test
public void connectWithShardInfoAndCustomSocketFactory() throws Exception {
final URI uri = URI.create("rediss://localhost:6390");
final SSLSocketFactory sslSocketFactory = createTrustStoreSslSocketFactory();
final SSLParameters sslParameters = new SSLParameters();
HostnameVerifier hostnameVerifier = new BasicHostnameVerifier();
JedisShardInfo shardInfo = new JedisShardInfo(uri, sslSocketFactory, sslParameters, hostnameVerifier);
shardInfo.setPassword("foobared");
Jedis jedis = new Jedis(shardInfo);
jedis.get("foo");
jedis.disconnect();
jedis.close();
}
示例9: getCacheForObject
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
public Object getCacheForObject(String key) {
Jedis jedis = null;
Object var3;
try {
jedis = pool.getResource();
byte[] value = jedis.get(key.getBytes());
var3 = SerializeUtil. unserialize(value);
} catch (Exception var7) {
throw new RuntimeException(var7);
} finally {
pool.returnResourceObject(jedis);
}
return var3;
}
示例10: executeTask
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
private void executeTask(TopicViewCountTask task) {
Jedis jedis = redisManager.getJedis();
String cacheValue = jedis.get(task.getKey());
int count = cacheValue == null ? 0 : Integer.valueOf(cacheValue);
if (count < 2) {
jedis.incrBy(task.getKey(), task.getViews());
} else {
jedis.del(task.getKey());
topicService.updateTopicViews(Long.valueOf(task.getTopicId()), count + task.getViews());
}
redisManager.retureRes(jedis);
}
示例11: jedispolltest
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@GET
@Path("jedispooltest")
@Produces(MediaType.TEXT_HTML + ";charset=utf-8")
public String jedispolltest() {
System.out.println("TEST JedisPool ======================================================");
JedisPoolConfig cfg = new JedisPoolConfig();
cfg.setMaxTotal(5);
cfg.setMaxIdle(1);
cfg.setMaxWaitMillis(10000L);
JedisPool jp = new JedisPool(cfg, "localhost", 6379);
Jedis jedis = jp.getResource();
jedis.set("foo", "bar");
// jedis.close();
jedis = jp.getResource();
jedis.get("foo");
// jedis.close();
jedis = jp.getResource();
jedis.lpush("lll", "a");
jedis.lpush("lll", "b");
jedis.lpush("lll", "c");
jedis.lpop("lll");
jedis.lpop("lll");
jedis.lpop("lll");
// jedis.close();
jedis = jp.getResource();
jedis.hset("mmm", "abc", "123");
jedis.hset("mmm", "def", "456");
jedis.hgetAll("mmm");
jp.close();
return "jedispooltest";
}
示例12: getWxToken
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 获取微信Token
* @return Token数据键值对
*/
public Map<String, Object> getWxToken() {
Jedis jedis = null;
try{
jedis = RedisConnectionFactory.getJedisInstance();
String jsonString = jedis.get("token:" + this.appId);
if(jsonString == null){
return getNewWxToken();
}else{
Map<String, Object> tokenMap = JSON.parseObject(jsonString, new TypeReference<Map<String, Object>>(){});
long nowTime = System.currentTimeMillis();
if(nowTime < (Long.parseLong(tokenMap.get("time").toString())-5000)){
return tokenMap;
}else{
return getNewWxToken();
}
}
}catch (Exception e) {
e.printStackTrace();
logger.error("从Redis中取AccessToken时:" + e.toString());
return null;
}finally{
if(jedis != null){
jedis.close();
}
}
}
示例13: get
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
/**
* 获取String值
* @param key
* @return value
*/
public synchronized static String get(String key) {
Jedis jedis = getJedis();
if (null == jedis) {
return null;
}
String value = jedis.get(key);
jedis.close();
return value;
}
示例14: get
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
@Override
public String get(String key) {
Jedis jedis = jedisPool.getResource();
String result = jedis.get(key);
jedis.close();
return result;
}
示例15: isKeyMatchAndAlive
import redis.clients.jedis.Jedis; //导入方法依赖的package包/类
private boolean isKeyMatchAndAlive(Jedis jedis, String key, String value) {
long ttl = jedis.ttl(key);
if (ttl < 0) {
return false;
}
String valueInRedis = jedis.get(key);
if (valueInRedis == null || !valueInRedis.equals(value)) {
return false;
}
return true;
}