當前位置: 首頁>>代碼示例>>Java>>正文


Java Jedis.hmset方法代碼示例

本文整理匯總了Java中redis.clients.jedis.Jedis.hmset方法的典型用法代碼示例。如果您正苦於以下問題:Java Jedis.hmset方法的具體用法?Java Jedis.hmset怎麽用?Java Jedis.hmset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在redis.clients.jedis.Jedis的用法示例。


在下文中一共展示了Jedis.hmset方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setMap

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
 * 設置Map緩存
 *
 * @param key          鍵
 * @param value        值
 * @param cacheSeconds 超時時間,0為不超時
 * @return
 */
public static String setMap(String key, Map<String, String> value, int cacheSeconds) {
	String result = null;
	Jedis jedis = null;
	try {
		jedis = getResource();
		if (jedis.exists(key)) {
			jedis.del(key);
		}
		result = jedis.hmset(key, value);
		if (cacheSeconds != 0) {
			jedis.expire(key, cacheSeconds);
		}
		logger.debug("setMap {} = {}", key, value);
	} catch (Exception e) {
		logger.warn("setMap {} = {}", key, value, e);
	} finally {
		returnResource(jedis);
	}
	return result;
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:29,代碼來源:JedisUtils.java

示例2: testAddHash

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Test
public void testAddHash() throws Exception {
    Client cl = new Client("testung", "localhost", 6379);
    Jedis conn = cl._conn();
    conn.flushDB();
    Schema sc = new Schema().addTextField("title", 1.0);
    assertTrue(cl.createIndex(sc, Client.IndexOptions.Default()));
    HashMap hm = new HashMap();
    hm.put("title", "hello world");
    conn.hmset("foo", hm);

    assertTrue(cl.addHash("foo", 1, false));
    SearchResult res = cl.search(new Query("hello world").setVerbatim());
    assertEquals(1, res.totalResults);
    assertEquals("foo", res.docs.get(0).getId());
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:17,代碼來源:ClientTest.java

示例3: set

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public void set(String key, Map<String, String> map) {
    Jedis jedis = null;
    try {
        jedis = getJedis();
        if (jedis != null) {
            jedis.hmset(key, map);
        } else {
            logger.error("hmset opt connection null error!");
        }
    } catch (JedisConnectionException e) {
        if (jedis != null) {
            jedis.close();
            jedis = null;
        }
        logger.error("hmset connect error:", e);
    } finally {
        returnJedisResource(jedis);
    }
}
 
開發者ID:Zephery,項目名稱:newblog,代碼行數:20,代碼來源:JedisUtil.java

示例4: setMap

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
 * 設置Map緩存
 * @param key 鍵
 * @param value 值
 * @param cacheSeconds 超時時間,0為不超時
 * @return
 */
public static String setMap(String key, Map<String, String> value, int cacheSeconds) {
	String result = null;
	Jedis jedis = null;
	try {
		jedis = getResource();
		if (jedis.exists(key)) {
			jedis.del(key);
		}
		result = jedis.hmset(key, value);
		if (cacheSeconds != 0) {
			jedis.expire(key, cacheSeconds);
		}
		logger.debug("setMap {} = {}", key, value);
	} catch (Exception e) {
		logger.warn("setMap {} = {}", key, value, e);
	} finally {
		returnResource(jedis);
	}
	return result;
}
 
開發者ID:egojit8,項目名稱:easyweb,代碼行數:28,代碼來源:JedisUtils.java

示例5: mapPut

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
 * 向Map緩存中添加值
 *
 * @param key   鍵
 * @param value 值
 * @return
 */
public static String mapPut(String key, Map<String, String> value) {
	String result = null;
	Jedis jedis = null;
	try {
		jedis = getResource();
		result = jedis.hmset(key, value);
		logger.debug("mapPut {} = {}", key, value);
	} catch (Exception e) {
		logger.warn("mapPut {} = {}", key, value, e);
	} finally {
		returnResource(jedis);
	}
	return result;
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:22,代碼來源:JedisUtils.java

示例6: setObjectToHash

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
 * 將對象保存到hash中,並且設置生命周期
 * 
 * @param key
 * @param entity
 * @param seconds
 */
public boolean setObjectToHash(String key, IEntity entity, int seconds) {
	Jedis jedis = null;
	boolean success = true;
	boolean ret = false;
	try {
		jedis = jedisPool.getResource();
		if (jedis == null) {
			success = false;
			return false;
		}
		Map<String, String> map = EntityUtils.getCacheValueMap(entity, EntitySaveEnum.Save2Redis);
		if (map != null && map.size() > 0) {
			String result = jedis.hmset(key, map);
			ret = "OK".equalsIgnoreCase(result);
			if (ret && (seconds >= 0)) {
				jedis.expire(key, seconds);
			}
		}
	} catch (Exception e) {
		success = false;
		returnBrokenResource(jedis, "setObjectToHash:" + key, e);
	} finally {
		releaseReidsSource(success, jedis);
	}
	return ret;
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:34,代碼來源:RedisService.java

示例7: setListToHash

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public boolean setListToHash(String key, List<RedisListInterface> list, int seconds) {
	Jedis jedis = null;
	boolean success = true;
	boolean ret = false;
	try {
		jedis = jedisPool.getResource();
		if (jedis == null) {
			success = false;
			return false;
		}
		Map<String, String> map = new HashMap<String, String>();
		for (RedisListInterface po : list) {
			Map<String, String> cacheMap = EntityUtils.getCacheValueMap((IEntity) po, EntitySaveEnum.Save2Redis);
			if (cacheMap != null && (!cacheMap.isEmpty())) {
				map.put(po.getSubUniqueKey(), JSON.toJSONString(cacheMap));
			}
		}
		if (map != null && map.size() > 0) {
			String result = jedis.hmset(key, map);
			ret = "OK".equalsIgnoreCase(result);
			if (ret && (seconds >= 0)) {
				jedis.expire(key, seconds);
			}
		}
	} catch (Exception e) {
		success = false;
		returnBrokenResource(jedis, "setListToHash:" + key, e);
	} finally {
		releaseReidsSource(success, jedis);
	}
	return ret;
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:33,代碼來源:RedisService.java

示例8: setMapData

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
 * 保存數據 類型為 Map
 *
 * @param key key
 * @param mapData Map
 */
public String setMapData(String key, Map<String, String> mapData) {
    Jedis jedis = null;

    try {
        jedis = getConnect();
        return jedis.hmset(key, mapData);
    } catch (Exception e) {
        logger.error("redis setRedisData map data failed! map = " + mapData, e);
    } finally {
        close(jedis);
    }

    return "false";
}
 
開發者ID:TwoDragonLake,項目名稱:tdl-seckill,代碼行數:21,代碼來源:RedisUtil.java

示例9: mapPut

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
/**
 * 向Map緩存中添加值
 * @param key 鍵
 * @param value 值
 * @return
 */
public static String mapPut(String key, Map<String, String> value) {
	String result = null;
	Jedis jedis = null;
	try {
		jedis = getResource();
		result = jedis.hmset(key, value);
		logger.debug("mapPut {} = {}", key, value);
	} catch (Exception e) {
		logger.warn("mapPut {} = {}", key, value, e);
	} finally {
		returnResource(jedis);
	}
	return result;
}
 
開發者ID:egojit8,項目名稱:easyweb,代碼行數:21,代碼來源:JedisUtils.java

示例10: hmset

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
@Override
public String hmset(String key, Map<String, String> hash) {
    Jedis jedis = null;
    String res = null;
    try {
        jedis = pool.getResource();
        res = jedis.hmset(key, hash);
    } catch (Exception e) {

        LOGGER.error(e.getMessage());
    } finally {
        returnResource(pool, jedis);
    }
    return res;
}
 
開發者ID:wxiaoqi,項目名稱:ace-cache,代碼行數:16,代碼來源:RedisServiceImpl.java

示例11: addCache

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public void addCache(String key, Map<String, Object> map) {
    if (map != null && map.size() > 0) {
        Jedis jedis = null;

        try {
            jedis = pool.getResource();
            Map<String, String> m = new HashMap();
            Set<String> sets = map.keySet();
            Iterator it = sets.iterator();

            while(it.hasNext()) {
                String k = (String)it.next();
                Object o = map.get(k);
                if (o != null) {
                    if (o instanceof String) {
                        m.put(k, (String)o);
                    } else if (!(o instanceof Collection)) {
                        m.put(k, String.valueOf(o));
                    } else {
                        m.put(k, null);
                    }
                } else {
                    m.put(k, null);
                }
            }

            jedis.hmset(key, m);
        } catch (Exception var12) {
            throw new RuntimeException(var12);
        } finally {
            pool.returnResourceObject(jedis);
        }
    }

}
 
開發者ID:bitstd,項目名稱:bitstd,代碼行數:36,代碼來源:RedisCacheWithoutCluster.java

示例12: updateObjectHashMap

import redis.clients.jedis.Jedis; //導入方法依賴的package包/類
public boolean updateObjectHashMap(String key, Map<String, Object> mapToUpdate, int seconds) {
	Jedis jedis = null;
	boolean success = true;
	boolean ret = false;
	try {
		jedis = jedisPool.getResource();
		if (jedis == null) {
			success = false;
			return false;
		}
		Map<String, String> map = new HashMap<String, String>();
		for (Entry<String, Object> entry : mapToUpdate.entrySet()) {
			String temp = entry.getKey();
			Object obj = entry.getValue();
			if (obj instanceof Date) {
				map.put(temp, TimeUtils.dateToString((Date) obj));
			}
			else if((obj instanceof Map)||(obj instanceof HashMap)) {
				map.put(temp, JSON.toJSONString(obj));
			}
			else if((obj instanceof List)||(obj instanceof ArrayList)) {
				map.put(temp, JSON.toJSONString(obj));
			}
			else {
				map.put(temp, obj.toString());
			}
		}
		if (map != null && map.size() > 0) {
			String result = jedis.hmset(key, map);
			ret = "OK".equalsIgnoreCase(result);
			if (ret && (seconds >= 0)) {
				jedis.expire(key, seconds);
			}
		}
	} catch (Exception e) {
		success = false;
		returnBrokenResource(jedis, "updateHashMap:" + key, e);
	} finally {
		releaseReidsSource(success, jedis);
	}
	return ret;
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:43,代碼來源:RedisService.java


注:本文中的redis.clients.jedis.Jedis.hmset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。