当前位置: 首页>>代码示例>>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;未经允许,请勿转载。