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


Java Pipeline.scard方法代碼示例

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


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

示例1: removeJob

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
/**
 * Remove the given job from Redis
 * @param jobKey the job to be removed
 * @param jedis a thread-safe Redis connection
 * @return true if the job was removed; false if it did not exist
 */
@Override
public boolean removeJob(JobKey jobKey, Jedis jedis) throws JobPersistenceException {
    final String jobHashKey = redisSchema.jobHashKey(jobKey);
    final String jobBlockedKey = redisSchema.jobBlockedKey(jobKey);
    final String jobDataMapHashKey = redisSchema.jobDataMapHashKey(jobKey);
    final String jobGroupSetKey = redisSchema.jobGroupSetKey(jobKey);
    final String jobTriggerSetKey = redisSchema.jobTriggersSetKey(jobKey);

    Pipeline pipe = jedis.pipelined();
    // remove the job and any associated data
    Response<Long> delJobHashKeyResponse = pipe.del(jobHashKey);
    // remove the blocked job key
    pipe.del(jobBlockedKey);
    // remove the job's data map
    pipe.del(jobDataMapHashKey);
    // remove the job from the set of all jobs
    pipe.srem(redisSchema.jobsSet(), jobHashKey);
    // remove the job from the set of blocked jobs
    pipe.srem(redisSchema.blockedJobsSet(), jobHashKey);
    // remove the job from its group
    pipe.srem(jobGroupSetKey, jobHashKey);
    // retrieve the keys for all triggers associated with this job, then delete that set
    Response<Set<String>> jobTriggerSetResponse = pipe.smembers(jobTriggerSetKey);
    pipe.del(jobTriggerSetKey);
    Response<Long> jobGroupSetSizeResponse = pipe.scard(jobGroupSetKey);
    pipe.sync();
    if(jobGroupSetSizeResponse.get() == 0){
        // The group now contains no jobs. Remove it from the set of all job groups.
        jedis.srem(redisSchema.jobGroupsSet(), jobGroupSetKey);
    }

    // remove all triggers associated with this job
    pipe = jedis.pipelined();
    for (String triggerHashKey : jobTriggerSetResponse.get()) {
        // get this trigger's TriggerKey
        final TriggerKey triggerKey = redisSchema.triggerKey(triggerHashKey);
        final String triggerGroupSetKey = redisSchema.triggerGroupSetKey(triggerKey);
        unsetTriggerState(triggerHashKey, jedis);
        // remove the trigger from the set of all triggers
        pipe.srem(redisSchema.triggersSet(), triggerHashKey);
        // remove the trigger's group from the set of all trigger groups
        pipe.srem(redisSchema.triggerGroupsSet(), triggerGroupSetKey);
        // remove this trigger from its group
        pipe.srem(triggerGroupSetKey, triggerHashKey);
        // delete the trigger
        pipe.del(triggerHashKey);
    }
    pipe.sync();

    return delJobHashKeyResponse.get() == 1;
}
 
開發者ID:jlinn,項目名稱:quartz-redis-jobstore,代碼行數:58,代碼來源:RedisStorage.java

示例2: removeTrigger

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
/**
 * Remove (delete) the <code>{@link org.quartz.Trigger}</code> with the given key.
 * @param triggerKey the key of the trigger to be removed
 * @param removeNonDurableJob if true, the job associated with the given trigger will be removed if it is non-durable
 *                            and has no other triggers
 * @param jedis a thread-safe Redis connection
 * @return true if the trigger was found and removed
 */
@Override
protected boolean removeTrigger(TriggerKey triggerKey, boolean removeNonDurableJob, Jedis jedis) throws JobPersistenceException, ClassNotFoundException {
    final String triggerHashKey = redisSchema.triggerHashKey(triggerKey);
    final String triggerGroupSetKey = redisSchema.triggerGroupSetKey(triggerKey);

    if(!jedis.exists(triggerHashKey)){
        return false;
    }

    OperableTrigger trigger = retrieveTrigger(triggerKey, jedis);

    final String jobHashKey = redisSchema.jobHashKey(trigger.getJobKey());
    final String jobTriggerSetKey = redisSchema.jobTriggersSetKey(trigger.getJobKey());

    Pipeline pipe = jedis.pipelined();
    // remove the trigger from the set of all triggers
    pipe.srem(redisSchema.triggersSet(), triggerHashKey);
    // remove the trigger from its trigger group set
    pipe.srem(triggerGroupSetKey, triggerHashKey);
    // remove the trigger from the associated job's trigger set
    pipe.srem(jobTriggerSetKey, triggerHashKey);
    pipe.sync();

    if(jedis.scard(triggerGroupSetKey) == 0){
        // The trigger group set is empty. Remove the trigger group from the set of trigger groups.
        jedis.srem(redisSchema.triggerGroupsSet(), triggerGroupSetKey);
    }

    if(removeNonDurableJob){
        pipe = jedis.pipelined();
        Response<Long> jobTriggerSetKeySizeResponse = pipe.scard(jobTriggerSetKey);
        Response<Boolean> jobExistsResponse = pipe.exists(jobHashKey);
        pipe.sync();
        if(jobTriggerSetKeySizeResponse.get() == 0 && jobExistsResponse.get()){
            JobDetail job = retrieveJob(trigger.getJobKey(), jedis);
            if(!job.isDurable()){
                // Job is not durable and has no remaining triggers. Delete it.
                removeJob(job.getKey(), jedis);
                signaler.notifySchedulerListenersJobDeleted(job.getKey());
            }
        }
    }

    if(isNullOrEmpty(trigger.getCalendarName())){
        jedis.srem(redisSchema.calendarTriggersSetKey(trigger.getCalendarName()), triggerHashKey);
    }
    unsetTriggerState(triggerHashKey, jedis);
    jedis.del(triggerHashKey);
    jedis.del(redisSchema.triggerDataMapHashKey(triggerKey));
    return true;
}
 
開發者ID:jlinn,項目名稱:quartz-redis-jobstore,代碼行數:60,代碼來源:RedisStorage.java


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