Java Code Examples for redis.clients.jedis.Jedis.hmset()

来源:互联网 发布:重庆博拉网络 编辑:程序博客网 时间:2024/05/19 03:20

Java Code Examples for redis.clients.jedis.Jedis.hmset()

The following are Jave code examples for showing how to usehmset()of theredis.clients.jedis.Jedis class.You can vote up the examples you like. Your votes will be used in our system to getmore good examples.

+ Save this method
Example 1
Project: dk-masterView SourceVote up6votes
/** * ?????hash???????byte???? * @param mapKey * @param data */public void putToMap(byte[] mapKey, Map<byte[], byte[]> data) {Jedis conn = getConnection();if (conn == null) {return;}try {conn.hmset(mapKey, data);returnConnection(conn);} catch (Exception e) {returnBorkenConnection(conn);}} 
Example 2
Project: TOTP-authentication-demo-masterView SourceVote up6votes
@Overridepublic void addAccount(Account account) {Jedis jedis = null;try {jedis = pool.getResource();long id = getIncresedId();Map<String, String> hash = new HashMap<String, String>();hash.put("name", account.getName());hash.put("password", account.getPassword());hash.put("secret", account.getSecret());hash.put("created", Long.toString(account.getCreated().getTime()));jedis.set(getAccountNameIndexKey(account.getName()), Long.toString(id));jedis.hmset(getAccountDataKey(Long.toString(id)), hash);} finally {pool.returnResource(jedis);}} 
Example 3
Project: jfinal-masterView SourceVote up6votes
/** * ????? field-value (?-?)??????? key ?? * ???????????????? * ?? key ???????????????? HMSET ??? */public String hmset(Object key, Map<Object, Object> hash) {Jedis jedis = getJedis();try {Map<byte[], byte[]> para = new HashMap<byte[], byte[]>();for (Entry<Object, Object> e : hash.entrySet())para.put(keyToBytes(e.getKey()), valueToBytes(e.getValue()));return jedis.hmset(keyToBytes(key), para);}finally {close(jedis);}} 
Example 4
Project: redis-store-masterView SourceVote up6votes
public void save(Session session) throws IOException {    ObjectOutputStream oos = null;    ByteArrayOutputStream bos = null;    Map<byte[], byte[]> hash = new HashMap<byte[], byte[]>();    bos = new ByteArrayOutputStream();    oos = new ObjectOutputStream(new BufferedOutputStream(bos));    ((StandardSession) session).writeObjectData(oos);    oos.close();    oos = null;    hash.put(ID_FIELD, session.getIdInternal().getBytes());    hash.put(DATA_FIELD, bos.toByteArray());    Jedis jedis = getJedis();    jedis.hmset(session.getIdInternal().getBytes(), hash);    closeJedis(jedis);    if (log.isLoggable(Level.INFO)) {        log.info("Saved session with id " + session.getIdInternal());    }} 
Example 5
Project: redis-quartz-masterView SourceVote up6votes
/** * 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<String, String>();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 6
Project: OG-Platform-masterView SourceVote up6votes
protected void updateTimeSeries(String redisKey, LocalDateDoubleTimeSeries timeseries, boolean clear, int attempts) {  try (Timer.Context context = _updateSeriesTimer.time()) {    Jedis jedis = getJedisPool().getResource();    try {      Map<String, String> htsMap = Maps.newHashMap();      BiMap<Double, String> dates = HashBiMap.create();      for (Entry<LocalDate, Double> entry : timeseries) {        String dateAsIntText = Integer.toString(LocalDateToIntConverter.convertToInt(entry.getKey()));        htsMap.put(dateAsIntText, Double.toString(entry.getValue()));        dates.put(Double.valueOf(dateAsIntText), dateAsIntText);      }      String redisHtsDatapointKey = toRedisHtsDatapointKey(redisKey);      jedis.hmset(redisHtsDatapointKey, htsMap);            String redisHtsDaysKey = toRedisHtsDaysKey(redisKey);      if (clear) {        jedis.del(redisHtsDaysKey);      } else {        jedis.zrem(redisHtsDaysKey, dates.inverse().keySet().toArray(new String[dates.size()]));      }            jedis.zadd(redisHtsDaysKey, dates);            getJedisPool().returnResource(jedis);    } catch (Throwable e) {      getJedisPool().returnBrokenResource(jedis);      if (attempts > 0) {        s_logger.warn("Unable to put timeseries with id, will retry: " + redisKey, e);        updateTimeSeries(redisKey, timeseries, clear, attempts - 1);      }      throw new OpenGammaRuntimeException("Unable to put timeseries with id: " + redisKey, e);    }  }} 
Example 7
Project: trident-extended-state-masterView SourceVote up6votes
@Overridepublic void multiPut(Map<K, V> values) {Jedis jedis = this.pool.getResource();try {byte[] rawKey = this.generateKey();Map<byte[], byte[]> rawHash = new HashMap<byte[], byte[]>(values.size());for (Entry<K, V> entry : values.entrySet()) {rawHash.put(keySerializer.serialize(entry.getKey()), serializer.serialize(entry.getValue()));}jedis.hmset(rawKey, rawHash);} finally {this.pool.returnResource(jedis);}} 
Example 8
Project: Carolina-Digital-Repository-masterView SourceVote up6votes
public void started(String jobUUID, String depositUUID, Class<?> jobClass) {Map<String, String> status = new HashMap<String, String>();status.put(JobField.uuid.name(), jobUUID);status.put(JobField.name.name(), jobClass.getName());status.put(JobField.status.name(), JobStatus.working.name());status.put(JobField.starttime.name(),String.valueOf(System.currentTimeMillis()));status.put(JobField.num.name(), "0");Jedis jedis = getJedisPool().getResource();jedis.hmset(JOB_STATUS_PREFIX + jobUUID, status);jedis.rpush(DEPOSIT_TO_JOBS_PREFIX + depositUUID, jobUUID);getJedisPool().returnResource(jedis);}

来自: http://www.programcreek.com/java-api-examples/index.php?class=redis.clients.jedis.Jedis&method=hmset

0 0