Java Code Examples for redis.clients.jedis.Jedis#scard()

The following examples show how to use redis.clients.jedis.Jedis#scard() . 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: InfoDaoImpl.java    From dynamic-show with Apache License 2.0 6 votes vote down vote up
@Override
public List<Map<String, String>> getUV(String dateStr) {
    Jedis jedis = JedisUtil.getJedis();
    List<Map<String, String>> uvData = new ArrayList<>();
    String uvKey = null;
    Long result = null;
    Map<String, String> map = null;
    for(String province : ProvinceUtil.provinceMap.keySet()) {
        uvKey = province + "_mids_" + dateStr;
        result = jedis.scard(uvKey);
        if(result == null) {
            result = 0L;
        }
        map = new HashMap<>();
        map.put("name", ProvinceUtil.provinceMap.get(province));
        map.put("value", result + "");
        uvData.add(map);
    }

    // 释放jedis资源
    JedisUtil.returnJedis(jedis);

    return uvData;
}
 
Example 2
Source File: ChurchDB.java    From VileBot with MIT License 6 votes vote down vote up
/**
 * Change the title of noun to a string.
 *
 * @param noun The noun to change the karma of
 * @param newTitle The string to change the title to
 */
public static void modDonorTitle( String noun, String newTitle )
{
    Jedis jedis = pool.getResource();
    Long titleCount = jedis.scard( keyOfChurchDonorTitleSortedSet + noun );
    try
    {
        for ( Long i = 0L; i < titleCount; i++ )
        {
            jedis.spop( keyOfChurchDonorTitleSortedSet + noun );
        }
        jedis.sadd( keyOfChurchDonorTitleSortedSet + noun, newTitle );
    }
    finally
    {
        pool.returnResource( jedis );
    }
}
 
Example 3
Source File: RedisStorage.java    From quartz-redis-jobstore with Apache License 2.0 6 votes vote down vote up
/**
 * Remove (delete) the <code>{@link org.quartz.Calendar}</code> with the given name.
 * @param calendarName the name of the calendar to be removed
 * @param jedis a thread-safe Redis connection
 * @return true if a calendar with the given name was found and removed
 */
@Override
public boolean removeCalendar(String calendarName, Jedis jedis) throws JobPersistenceException {
    final String calendarTriggersSetKey = redisSchema.calendarTriggersSetKey(calendarName);

    if(jedis.scard(calendarTriggersSetKey) > 0){
        throw new JobPersistenceException(String.format("There are triggers pointing to calendar %s, so it cannot be removed.", calendarName));
    }
    final String calendarHashKey = redisSchema.calendarHashKey(calendarName);
    Pipeline pipe = jedis.pipelined();
    Response<Long> deleteResponse = pipe.del(calendarHashKey);
    pipe.srem(redisSchema.calendarsSet(), calendarHashKey);
    pipe.sync();

    return deleteResponse.get() == 1;
}
 
Example 4
Source File: RedisJobStore.java    From redis-quartz with MIT License 5 votes vote down vote up
/**
 * Removes the job from redis.
 *
 * @param jobKey the job key
 * @param jedis thread-safe redis connection
 */
private void removeJob(JobKey jobKey, Jedis jedis) {
	String jobHashKey = createJobHashKey(jobKey.getGroup(), jobKey.getName());
	String jobDataMapHashKey = createJobDataMapHashKey(jobKey.getGroup(), jobKey.getName());
	String jobGroupSetKey = createJobGroupSetKey(jobKey.getGroup());
	
	jedis.del(jobHashKey);
	jedis.del(jobDataMapHashKey);
	jedis.srem(JOBS_SET, jobHashKey);
	jedis.srem(BLOCKED_JOBS_SET, jobHashKey);
	jedis.srem(jobGroupSetKey, jobHashKey);
	if (jedis.scard(jobGroupSetKey) == 0) {
		jedis.srem(JOB_GROUPS_SET, jobGroupSetKey);
	}
}
 
Example 5
Source File: RedisScheduler.java    From webmagic with Apache License 2.0 5 votes vote down vote up
@Override
public int getTotalRequestsCount(Task task) {
    Jedis jedis = pool.getResource();
    try {
        Long size = jedis.scard(getSetKey(task));
        return size.intValue();
    } finally {
        pool.returnResource(jedis);
    }
}
 
Example 6
Source File: QuoteFactDB.java    From VileBot with MIT License 5 votes vote down vote up
/**
 * Get the number of facts associated with a noun.
 *
 * @param noun The noun to get the facts of
 * @return The number of facts
 */
public static Long getFactsLength( String noun )
{
    Jedis jedis = pool.getResource();
    try
    {
        return jedis.scard( keyOfFactSetsPrefix + noun );
    }
    finally
    {
        pool.returnResource( jedis );
    }
}
 
Example 7
Source File: QuoteFactDB.java    From VileBot with MIT License 5 votes vote down vote up
/**
 * Get the number of quotes associated with a noun.
 *
 * @param noun The noun to get the quotes of
 * @return The number of quotes
 */
public static Long getQuotesLength( String noun )
{
    Jedis jedis = pool.getResource();
    try
    {
        return jedis.scard( keyOfQuoteSetsPrefix + noun );
    }
    finally
    {
        pool.returnResource( jedis );
    }
}
 
Example 8
Source File: GroupDB.java    From VileBot with MIT License 5 votes vote down vote up
private static long groupSize( String group )
{
    Jedis jedis = pool.getResource();
    try
    {
        return jedis.scard( keyOfGroupSetsPrefix + group );
    }
    finally
    {
        pool.returnResource( jedis );
    }
}
 
Example 9
Source File: RedisJobStore.java    From redis-quartz with MIT License 5 votes vote down vote up
/**
 * Removes the calendar from redis.
 *
 * @param calName the calendar name
 * @param jedis thread-safe redis connection
 * @throws JobPersistenceException
 */
private void removeCalendar(String calName, Jedis jedis)
		throws JobPersistenceException {
	String calendarHashKey = createCalendarHashKey(calName);
	
	// checking if there are triggers pointing to this calendar
	String calendarTriggersSetkey = createCalendarTriggersSetKey(calName);
	if (jedis.scard(calendarTriggersSetkey) > 0)
		throw new JobPersistenceException("there are triggers pointing to: " + calendarHashKey + ", calendar can't be removed");			
			
	// removing the calendar
	jedis.del(calendarHashKey);
	jedis.srem(CALENDARS_SET, calendarHashKey);
}
 
Example 10
Source File: RedisJobStore.java    From redis-quartz with MIT License 5 votes vote down vote up
/**
 * Removes the trigger from redis.
 *
 * @param triggerKey the trigger key
 * jedis thread-safe redis connection
 * @throws JobPersistenceException
 */
private void removeTrigger(TriggerKey triggerKey, Jedis jedis) 
		throws JobPersistenceException {
	String triggerHashKey = createTriggerHashKey(triggerKey.getGroup(), triggerKey.getName());
	String triggerGroupSetKey = createTriggerGroupSetKey(triggerKey.getGroup());
	
	jedis.srem(TRIGGERS_SET, triggerHashKey);
	jedis.srem(triggerGroupSetKey, triggerHashKey);
	
	String jobHashkey = jedis.hget(triggerHashKey, JOB_HASH_KEY);
	String jobTriggerSetkey = createJobTriggersSetKey(jobHashkey.split(":")[1], jobHashkey.split(":")[2]); 
	jedis.srem(jobTriggerSetkey, triggerHashKey);
	
	if (jedis.scard(triggerGroupSetKey) == 0) {
		jedis.srem(TRIGGER_GROUPS_SET, triggerGroupSetKey);
	}
	
	// handling orphaned jobs
	if (jedis.scard(jobTriggerSetkey) == 0 && jedis.exists(jobHashkey)) {
		if (!Boolean.parseBoolean(jedis.hget(jobHashkey, IS_DURABLE))) {
			JobKey jobKey = new JobKey(jobHashkey.split(":")[2], jobHashkey.split(":")[1]);
			removeJob(jobKey, jedis);
			signaler.notifySchedulerListenersJobDeleted(jobKey);
		}				
	}
	
	String calendarName = jedis.hget(triggerHashKey, CALENDAR_NAME);
	if (!calendarName.isEmpty()) {
		String calendarTriggersSetKey = createCalendarTriggersSetKey(calendarName);
		jedis.srem(calendarTriggersSetKey, triggerHashKey);			
	}			
		
	// removing trigger state
	unsetTriggerState(triggerHashKey);		
	jedis.del(triggerHashKey);
}
 
Example 11
Source File: JedisUtils.java    From fw-spring-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * 通过key获取set中value的个数
 * </p>
 *
 * @param key
 * @return
 */
public Long scard(String key) {
    Jedis jedis = null;
    Long res = null;
    try {
        jedis = jedisPool.getResource();
        res = jedis.scard(key);
    } catch (Exception e) {

        log.error(e.getMessage());
    } finally {
        returnResource(jedisPool, jedis);
    }
    return res;
}
 
Example 12
Source File: JedisUtil.java    From BigData with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 获取给定key中元素个数
 * 
 * @param String
 *            key
 * @return 元素个数
 * */
public long scard(String key) {
	// ShardedJedis sjedis = getShardedJedis();
	Jedis sjedis = getJedis();
	long len = sjedis.scard(key);
	returnJedis(sjedis);
	return len;
}
 
Example 13
Source File: RedisServiceImpl.java    From ace-cache with Apache License 2.0 5 votes vote down vote up
@Override
public Long scard(String key) {
    Jedis jedis = null;
    Long res = null;
    try {
        jedis = pool.getResource();
        res = jedis.scard(key);
    } catch (Exception e) {

        LOGGER.error(e.getMessage());
    } finally {
        returnResource(pool, jedis);
    }
    return res;
}
 
Example 14
Source File: JedisClientPool.java    From paas with Apache License 2.0 5 votes vote down vote up
@Override
public Long scard(String key) {
    Jedis jedis = jedisPool.getResource();
    Long result = jedis.scard(key);
    jedis.close();
    return result;
}
 
Example 15
Source File: JedisClientPool.java    From blog-sample with Apache License 2.0 5 votes vote down vote up
@Override
public Long scard(String key) {
    Jedis jedis = jedisPool.getResource();
    Long result = jedis.scard(key);
    jedis.close();
    return result;
}
 
Example 16
Source File: JedisUtil.java    From Project with Apache License 2.0 5 votes vote down vote up
/**
 * 获取给定key中元素个数
 * 
 * @param  key
 * @return 元素个数
 */
public long scard(String key) {
	// ShardedJedis sjedis = getShardedJedis();
	Jedis sjedis = getJedis();
	long len = sjedis.scard(key);
	sjedis.close();
	return len;
}
 
Example 17
Source File: RedisStorage.java    From quartz-redis-jobstore with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 18
Source File: DefaultRedis.java    From craft-atom with MIT License 4 votes vote down vote up
private Long scard0(Jedis j, String key) {
	return j.scard(key);
}