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