Java Code Examples for redis.clients.jedis.Jedis#hmset()
The following examples show how to use
redis.clients.jedis.Jedis#hmset() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JedisUtils.java From fw-spring-cloud with Apache License 2.0 | 6 votes |
/** * <p> * 通过key同时设置 hash的多个field * </p> * * @param key * @param hash * @return 返回OK 异常返回null */ public String hmset(String key, Map<String, String> hash, int indexdb) { Jedis jedis = null; String res = null; try { jedis = jedisPool.getResource(); jedis.select(indexdb); res = jedis.hmset(key, hash); } catch (Exception e) { log.error(e.getMessage()); } finally { returnResource(jedisPool, jedis); } return res; }
Example 2
Source File: JedisUtils.java From Shop-for-JavaWeb with MIT License | 6 votes |
/** * 设置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; }
Example 3
Source File: RedisJobStore.java From redis-quartz with MIT License | 6 votes |
/** * Stores job in redis. * * @param newJob the new job * @param replaceExisting the replace existing * @param jedis thread-safe redis connection * @throws ObjectAlreadyExistsException */ private void storeJob(JobDetail newJob, boolean replaceExisting, Jedis jedis) throws ObjectAlreadyExistsException { String jobHashKey = createJobHashKey(newJob.getKey().getGroup(), newJob.getKey().getName()); String jobDataMapHashKey = createJobDataMapHashKey(newJob.getKey().getGroup(), newJob.getKey().getName()); String jobGroupSetKey = createJobGroupSetKey(newJob.getKey().getGroup()); if (jedis.exists(jobHashKey) && !replaceExisting) throw new ObjectAlreadyExistsException(newJob); Map<String, String> jobDetails = new HashMap<>(); jobDetails.put(DESCRIPTION, newJob.getDescription() != null ? newJob.getDescription() : ""); jobDetails.put(JOB_CLASS, newJob.getJobClass().getName()); jobDetails.put(IS_DURABLE, Boolean.toString(newJob.isDurable())); jobDetails.put(BLOCKED_BY, ""); jobDetails.put(BLOCK_TIME, ""); jedis.hmset(jobHashKey, jobDetails); if (newJob.getJobDataMap() != null && !newJob.getJobDataMap().isEmpty()) jedis.hmset(jobDataMapHashKey, getStringDataMap(newJob.getJobDataMap())); jedis.sadd(JOBS_SET, jobHashKey); jedis.sadd(JOB_GROUPS_SET, jobGroupSetKey); jedis.sadd(jobGroupSetKey, jobHashKey); }
Example 4
Source File: JedisUtil.java From newblog with Apache License 2.0 | 6 votes |
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); } }
Example 5
Source File: RedisAccessTokenStore.java From nutzwx with Apache License 2.0 | 6 votes |
@Override public void save(String token, int expires, long lastCacheTimeMillis) { Jedis jedis = null; try { jedis = jedisPool.getResource(); if (tokenKey == null) { throw new RuntimeException("Redis access_token key should not be null!"); } Map<String, String> hash = new HashMap<String, String>(); hash.put("token", token);// 存入token值 hash.put("lastCacheMillis", String.valueOf(lastCacheTimeMillis));// 存入设置的过期时间 hash.put("expires", String.valueOf(expires));// 存入当前缓存时间 String result = jedis.hmset(tokenKey, hash); log.infof("A new wx access_token was generated and stored to redis with the key [%s] , redis return code : %s", tokenKey, result); } catch (Exception e) { log.error(e); } finally { jedis.close(); } }
Example 6
Source File: RedisClient.java From Mykit with Apache License 2.0 | 6 votes |
/** * 存入的时hash结构的数据 * * @param key * key * @param map * map的key实质为field。 * @return */ public <T, S> boolean hmset(String key, Map<T, S> map) { Jedis client = jedisPool.getResource(); try { Iterator<Entry<T, S>> iterator = map.entrySet().iterator(); Map<String, String> stringMap = new HashMap<String, String>(); String filed; String value; while (iterator.hasNext()) { Entry<T, S> entry = iterator.next(); filed = String.valueOf(entry.getKey()); value = JsonUtils.beanToJson(entry.getValue()); stringMap.put(filed, value); } client.hmset(key, stringMap); return true; } finally { // 向连接池“归还”资源 jedisPool.returnResourceObject(client); } }
Example 7
Source File: RedisClient.java From apollo with GNU General Public License v2.0 | 6 votes |
public void hmSet(String key, Map<String, Serializable> values) throws Exception { Jedis jedis = null; try { jedis = this.jedisPool.getResource(); jedis.hmset(SafeEncoder.encode(key), encodeMap(values)); logger.info("hmSet key:" + key + ", field:" + values.keySet()); } catch (Exception e) { logger.error(e.getMessage(), e); this.jedisPool.returnBrokenResource(jedis); throw e; } finally { if (jedis != null) { this.jedisPool.returnResource(jedis); } } }
Example 8
Source File: JedisUtil.java From scaffold-cloud with MIT License | 6 votes |
/** * 设置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); } } catch (Exception e) { logger.warn("setMap {} = {}", key, value, e); } finally { close(jedis); } return result; }
Example 9
Source File: JedisUtil.java From scaffold-cloud with MIT License | 5 votes |
/** * 向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); } catch (Exception e) { logger.warn("mapPut {} = {}", key, value, e); } finally { close(jedis); } return result; }
Example 10
Source File: JedisUtils.java From easyweb with Apache License 2.0 | 5 votes |
/** * 向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; }
Example 11
Source File: RedisServiceImpl.java From ace-cache with Apache License 2.0 | 5 votes |
@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; }
Example 12
Source File: JedisUtils.java From Shop-for-JavaWeb with MIT License | 5 votes |
/** * 向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; }
Example 13
Source File: RedisManager.java From jee-universal-bms with Apache License 2.0 | 5 votes |
public void setHash(String key,HashMap<String,String> map,int expire){ Jedis jedis = pool.getResource(); try{ jedis.hmset(key, map); if (expire != 0) { jedis.expire(key, expire); } } catch (Exception e) { pool.returnBrokenResource(jedis); e.printStackTrace(); } finally{ pool.returnResource(jedis); } }
Example 14
Source File: DefaultRedis.java From craft-atom with MIT License | 4 votes |
private String hmset0(Jedis j, String key, Map<String, String> fieldvalues) { return j.hmset(key, fieldvalues); }
Example 15
Source File: UUIDTranslator.java From RedisBungee with Eclipse Public License 1.0 | 4 votes |
public final void persistInfo(String name, UUID uuid, Jedis jedis) { addToMaps(name, uuid); String json = RedisBungee.getGson().toJson(uuidToNameMap.get(uuid)); jedis.hmset("uuid-cache", ImmutableMap.of(name.toLowerCase(), json, uuid.toString(), json)); }
Example 16
Source File: RedisHmset.java From DDMQ with Apache License 2.0 | 4 votes |
@Override public String execute(Jedis jedis) { return jedis.hmset(key, hash); }
Example 17
Source File: JedisUtil.java From Project with Apache License 2.0 | 3 votes |
/** * 添加对应关系,如果对应关系已存在,则覆盖 * * @param key * @param map 对应关系 * @return 状态,成功返回OK */ public String hmset(byte[] key, Map<byte[], byte[]> map) { Jedis jedis = getJedis(); String s = jedis.hmset(key, map); jedis.close(); return s; }
Example 18
Source File: JedisUtil.java From Project with Apache License 2.0 | 3 votes |
/** * 添加对应关系,如果对应关系已存在,则覆盖 * * @param key * @param map 对应关系 * @return 状态,成功返回OK */ public String hmset(String key, Map<String, String> map) { Jedis jedis = getJedis(); String s = jedis.hmset(key, map); jedis.close(); return s; }
Example 19
Source File: JedisUtil.java From BigData with GNU General Public License v3.0 | 3 votes |
/** * 添加对应关系,如果对应关系已存在,则覆盖 * * @param Strin * key * @param Map * <String,String> 对应关系 * @return 状态,成功返回OK * */ public String hmset(String key, Map<String, String> map) { Jedis jedis = getJedis(); String s = jedis.hmset(key, map); returnJedis(jedis); return s; }
Example 20
Source File: JedisUtil.java From BigData with GNU General Public License v3.0 | 3 votes |
/** * 添加对应关系,如果对应关系已存在,则覆盖 * * @param Strin * key * @param Map * <String,String> 对应关系 * @return 状态,成功返回OK * */ public String hmset(byte[] key, Map<byte[], byte[]> map) { Jedis jedis = getJedis(); String s = jedis.hmset(key, map); returnJedis(jedis); return s; }