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


Java Pipeline.hmset方法代碼示例

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


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

示例1: storeJob

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
/**
 * Store a job in Redis
 * @param jobDetail the {@link org.quartz.JobDetail} object to be stored
 * @param replaceExisting if true, any existing job with the same group and name as the given job will be overwritten
 * @param jedis a thread-safe Redis connection
 * @throws org.quartz.ObjectAlreadyExistsException
 */
@Override
@SuppressWarnings("unchecked")
public void storeJob(JobDetail jobDetail, boolean replaceExisting, Jedis jedis) throws ObjectAlreadyExistsException {
    final String jobHashKey = redisSchema.jobHashKey(jobDetail.getKey());
    final String jobDataMapHashKey = redisSchema.jobDataMapHashKey(jobDetail.getKey());
    final String jobGroupSetKey = redisSchema.jobGroupSetKey(jobDetail.getKey());

    if(!replaceExisting && jedis.exists(jobHashKey)){
        throw new ObjectAlreadyExistsException(jobDetail);
    }

    Pipeline pipe = jedis.pipelined();
    pipe.hmset(jobHashKey, (Map<String, String>) mapper.convertValue(jobDetail, new TypeReference<HashMap<String, String>>() {}));
    if(jobDetail.getJobDataMap() != null && !jobDetail.getJobDataMap().isEmpty()){
        pipe.hmset(jobDataMapHashKey, getStringDataMap(jobDetail.getJobDataMap()));
    }

    pipe.sadd(redisSchema.jobsSet(), jobHashKey);
    pipe.sadd(redisSchema.jobGroupsSet(), jobGroupSetKey);
    pipe.sadd(jobGroupSetKey, jobHashKey);
    pipe.sync();
}
 
開發者ID:jlinn,項目名稱:quartz-redis-jobstore,代碼行數:30,代碼來源:RedisStorage.java

示例2: storeCalendar

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
/**
 * Store a {@link org.quartz.Calendar}
 * @param name the name of the calendar
 * @param calendar the calendar object to be stored
 * @param replaceExisting if true, any existing calendar with the same name will be overwritten
 * @param updateTriggers if true, any existing triggers associated with the calendar will be updated
 * @param jedis a thread-safe Redis connection
 * @throws JobPersistenceException
 */
@Override
public void storeCalendar(String name, Calendar calendar, boolean replaceExisting, boolean updateTriggers, Jedis jedis) throws JobPersistenceException{
    final String calendarHashKey = redisSchema.calendarHashKey(name);
    if(!replaceExisting && jedis.exists(calendarHashKey)){
        throw new ObjectAlreadyExistsException(String.format("Calendar with key %s already exists.", calendarHashKey));
    }
    Map<String, String> calendarMap = new HashMap<>();
    calendarMap.put(CALENDAR_CLASS, calendar.getClass().getName());
    try {
        calendarMap.put(CALENDAR_JSON, mapper.writeValueAsString(calendar));
    } catch (JsonProcessingException e) {
        throw new JobPersistenceException("Unable to serialize calendar.", e);
    }

    Pipeline pipe = jedis.pipelined();
    pipe.hmset(calendarHashKey, calendarMap);
    pipe.sadd(redisSchema.calendarsSet(), calendarHashKey);
    pipe.sync();

    if(updateTriggers){
        final String calendarTriggersSetKey = redisSchema.calendarTriggersSetKey(name);
        Set<String> triggerHashKeys = jedis.smembers(calendarTriggersSetKey);
        for (String triggerHashKey : triggerHashKeys) {
            OperableTrigger trigger = retrieveTrigger(redisSchema.triggerKey(triggerHashKey), jedis);
            long removed = jedis.zrem(redisSchema.triggerStateKey(RedisTriggerState.WAITING), triggerHashKey);
            trigger.updateWithNewCalendar(calendar, misfireThreshold);
            if(removed == 1){
                setTriggerState(RedisTriggerState.WAITING, (double) trigger.getNextFireTime().getTime(), triggerHashKey, jedis);
            }
        }
    }
}
 
開發者ID:jlinn,項目名稱:quartz-redis-jobstore,代碼行數:42,代碼來源:RedisStorage.java

示例3: createPlayer

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
protected static void createPlayer(PendingConnection connection, Pipeline pipeline, boolean fireEvent) {
    Map<String, String> playerData = new HashMap<>(4);
    playerData.put("online", "0");
    playerData.put("ip", connection.getAddress().getAddress().getHostAddress());
    playerData.put("proxy", RedisBungee.getConfiguration().getServerId());

    pipeline.sadd("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", connection.getUniqueId().toString());
    pipeline.hmset("player:" + connection.getUniqueId().toString(), playerData);

    if (fireEvent) {
        pipeline.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
                connection.getUniqueId(), DataManager.DataManagerMessage.Action.JOIN,
                new DataManager.LoginPayload(connection.getAddress().getAddress()))));
    }
}
 
開發者ID:minecrafter,項目名稱:RedisBungee,代碼行數:16,代碼來源:RedisUtil.java

示例4: put

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Override
public RedisPermissionsRepository put(@NonNull UserPermission permission) {
  Map<ResourceType, Map<String, String>> resourceTypeToRedisValue =
      new HashMap<>(ResourceType.values().length);

  permission
      .getAllResources()
      .forEach(resource -> {
        try {
          resourceTypeToRedisValue
              .computeIfAbsent(resource.getResourceType(), key -> new HashMap<>())
              .put(resource.getName(), objectMapper.writeValueAsString(resource));
        } catch (JsonProcessingException jpe) {
          log.error("Serialization exception writing " + permission.getId() + " entry.", jpe);
        }
      });

  try (Jedis jedis = jedisSource.getJedis()) {
    Pipeline deleteOldValuesPipeline = jedis.pipelined();
    Pipeline insertNewValuesPipeline = jedis.pipelined();

    String userId = permission.getId();
    insertNewValuesPipeline.sadd(allUsersKey(), userId);

    permission.getRoles().forEach(role -> insertNewValuesPipeline.sadd(roleKey(role), userId));

    for (ResourceType r : ResourceType.values()) {
      String userResourceKey = userKey(userId, r);

      deleteOldValuesPipeline.del(userResourceKey);

      Map<String, String> redisValue = resourceTypeToRedisValue.get(r);
      if (redisValue != null && !redisValue.isEmpty()) {
        insertNewValuesPipeline.hmset(userResourceKey, redisValue);
      }
    }
    deleteOldValuesPipeline.sync();
    insertNewValuesPipeline.sync();
  } catch (Exception e) {
    log.error("Storage exception writing " + permission.getId() + " entry.", e);
  }
  return this;
}
 
開發者ID:spinnaker,項目名稱:fiat,代碼行數:44,代碼來源:RedisPermissionsRepository.java

示例5: storeTrigger

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
/**
 * Store a trigger in redis
 * @param trigger the trigger to be stored
 * @param replaceExisting true if an existing trigger with the same identity should be replaced
 * @param jedis a thread-safe Redis connection
 * @throws JobPersistenceException
 * @throws ObjectAlreadyExistsException
 */
@Override
public void storeTrigger(OperableTrigger trigger, boolean replaceExisting, Jedis jedis) throws JobPersistenceException {
    final String triggerHashKey = redisSchema.triggerHashKey(trigger.getKey());
    final String triggerGroupSetKey = redisSchema.triggerGroupSetKey(trigger.getKey());
    final String jobTriggerSetKey = redisSchema.jobTriggersSetKey(trigger.getJobKey());

    if(!(trigger instanceof SimpleTrigger) && !(trigger instanceof CronTrigger)){
        throw new UnsupportedOperationException("Only SimpleTrigger and CronTrigger are supported.");
    }
    final boolean exists = jedis.exists(triggerHashKey);
    if(exists && !replaceExisting){
        throw new ObjectAlreadyExistsException(trigger);
    }

    Map<String, String> triggerMap = mapper.convertValue(trigger, new TypeReference<HashMap<String, String>>() {});
    triggerMap.put(TRIGGER_CLASS, trigger.getClass().getName());

    Pipeline pipe = jedis.pipelined();
    pipe.hmset(triggerHashKey, triggerMap);
    pipe.sadd(redisSchema.triggersSet(), triggerHashKey);
    pipe.sadd(redisSchema.triggerGroupsSet(), triggerGroupSetKey);
    pipe.sadd(triggerGroupSetKey, triggerHashKey);
    pipe.sadd(jobTriggerSetKey, triggerHashKey);
    if(trigger.getCalendarName() != null && !trigger.getCalendarName().isEmpty()){
        final String calendarTriggersSetKey = redisSchema.calendarTriggersSetKey(trigger.getCalendarName());
        pipe.sadd(calendarTriggersSetKey, triggerHashKey);
    }
    if (trigger.getJobDataMap() != null && !trigger.getJobDataMap().isEmpty()) {
        final String triggerDataMapHashKey = redisSchema.triggerDataMapHashKey(trigger.getKey());
        pipe.hmset(triggerDataMapHashKey, getStringDataMap(trigger.getJobDataMap()));
    }
    pipe.sync();

    if(exists){
        // We're overwriting a previously stored instance of this trigger, so clear any existing trigger state.
        unsetTriggerState(triggerHashKey, jedis);
    }

    pipe = jedis.pipelined();
    Response<Boolean> triggerPausedResponse = pipe.sismember(redisSchema.pausedTriggerGroupsSet(), triggerGroupSetKey);
    Response<Boolean> jobPausedResponse = pipe.sismember(redisSchema.pausedJobGroupsSet(), redisSchema.jobGroupSetKey(trigger.getJobKey()));
    pipe.sync();
    final String jobHashKey = redisSchema.jobHashKey(trigger.getJobKey());
    final long nextFireTime = trigger.getNextFireTime() != null ? trigger.getNextFireTime().getTime() : -1;
    if (triggerPausedResponse.get() || jobPausedResponse.get()){
        if (jedis.sismember(redisSchema.blockedJobsSet(), jobHashKey)) {
            setTriggerState(RedisTriggerState.PAUSED_BLOCKED, (double) nextFireTime, triggerHashKey, jedis);
        } else {
            setTriggerState(RedisTriggerState.PAUSED, (double) nextFireTime, triggerHashKey, jedis);
        }
    } else if(trigger.getNextFireTime() != null){
        if (jedis.sismember(redisSchema.blockedJobsSet(), jobHashKey)) {
            setTriggerState(RedisTriggerState.BLOCKED, nextFireTime, triggerHashKey, jedis);
        } else {
            setTriggerState(RedisTriggerState.WAITING, (double) trigger.getNextFireTime().getTime(), triggerHashKey, jedis);
        }
    }
}
 
開發者ID:jlinn,項目名稱:quartz-redis-jobstore,代碼行數:67,代碼來源:RedisStorage.java

示例6: persistInfo

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
public final void persistInfo(String name, UUID uuid, Pipeline jedis) {
    addToMaps(name, uuid);
    String json = RedisBungee.getGson().toJson(uuidToNameMap.get(uuid));
    jedis.hmset("uuid-cache", ImmutableMap.of(name.toLowerCase(), json, uuid.toString(), json));
}
 
開發者ID:minecrafter,項目名稱:RedisBungee,代碼行數:6,代碼來源:UUIDTranslator.java


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