Java Code Examples for redis.clients.jedis.Pipeline#srem()

The following examples show how to use redis.clients.jedis.Pipeline#srem() . 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: 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 2
Source File: RedisUtil.java    From RedisBungee with Eclipse Public License 1.0 5 votes vote down vote up
public static void cleanUpPlayer(String player, Pipeline rsc) {
    rsc.srem("proxy:" + RedisBungee.getApi().getServerId() + ":usersOnline", player);
    rsc.hdel("player:" + player, "server", "ip", "proxy");
    long timestamp = System.currentTimeMillis();
    rsc.hset("player:" + player, "online", String.valueOf(timestamp));
    rsc.publish("redisbungee-data", RedisBungee.getGson().toJson(new DataManager.DataManagerMessage<>(
            UUID.fromString(player), DataManager.DataManagerMessage.Action.LEAVE,
            new DataManager.LogoutPayload(timestamp))));
}
 
Example 3
Source File: RedisStorage.java    From quartz-redis-jobstore with Apache License 2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 4
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 5
Source File: RedisRoomManager.java    From gameserver with Apache License 2.0 4 votes vote down vote up
/**
 * Delete a room from system. If there are users (except AI users) in room,
 * it cannot be deleted and return false. 
 * @param roomSessionKey
 * @return
 */
@Override
public boolean deleteRoomIfEmpty(Room room) {
	try {
		room.lock();

		List<UserInfo> userList = room.getUserInfoList();
		boolean emptyRoom = true;
		for ( int i=0; i<userList.size(); i++ ) {
			UserInfo userInfo = userList.get(i);
			if ( userInfo == null || userInfo == Room.BLOCKED_USER_INFO ) {
				continue;
			} else {
				UserId userId = GameContext.getInstance().findUserIdBySessionKey(userInfo.getUserSessionKey());
				if ( userId != null ) {
					emptyRoom = false;
				}
				break;
			}
		}
		if ( emptyRoom ) {
			logger.debug("Delete room {} because it is empty.", room.getRoomSessionKey());
			
			Pipeline pipeline = JedisFactory.getJedis().pipelined();
			//pipeline.multi();
			pipeline.del(room.getRoomSessionKey().toString());
			pipeline.zrem(room.getCurrentSetName(), room.getRoomSessionKey().toString());
			pipeline.srem(localRoomSetName, room.getRoomSessionKey().toString());
			//pipeline.exec();
			pipeline.sync();
			
			roomMaps.remove(room.getRoomSessionKey());
			
			room.setRoomStatus(RoomStatus.DELETED);
			return true;
		} else {
			return false;
		}
	} finally {
		room.unlock();
	}
}
 
Example 6
Source File: TaskManager.java    From gameserver with Apache License 2.0 4 votes vote down vote up
/**
	 * An user finish a task. The task id will be removed from todo set
	 * and added to finished set.
	 * 
	 * @param user
	 * @param taskId
	 * @return
	 */
	public boolean finishTask(User user, String taskId) {
		//Get the persistent Jedis instance
		boolean result = true;
		Jedis jedisDB = JedisFactory.getJedisDB();
		String todoSet = getTodoSetName(user);
		String finishedSet = getFinishedSetName(user);
		
		//Delete it from todo list and add it to finish list
		Pipeline pipeline = jedisDB.pipelined();
		pipeline.srem(todoSet, taskId);
		pipeline.sadd(finishedSet, taskId);
		pipeline.sync();
		
		//Delete all data related to the task
		deleteTaskData(user, taskId);
				
		//Remove from user's tasklist if exist
		TaskPojo task = this.getTaskById(taskId);
		user.removeTask(task);
		user.addTaskFinished(task);
		
		if ( task.getType() == TaskType.TASK_ACHIVEMENT ) {
			this.takeTaskReward(user, taskId, 0);
			if ( task.isBroadcast() ) {
				String roleName = UserManager.getDisplayRoleName(user.getRoleName());
				String content = Text.text("notice.achievement", roleName, task.getName());
				ChatManager.getInstance().processChatToWorldAsyn(null, content);
			}
		} else {
			boolean success = false;
			if ( task.getType() == TaskType.TASK_ACTIVITY && 
					StringUtil.checkNotEmpty(task.getGiftDesc()) ) {
				success = this.takeTaskReward(user, taskId, 0);
			}
//			if ( success && task.isBroadcast() ) {
//				String roleName = UserManager.getDisplayRoleName(user.getRoleName());
//				String content = Text.text("notice.task", roleName, task.getName());
//				ChatManager.getInstance().processChatToWorldAsyn(null, content);
//			}
		}
//		boolean alreadyFinished = jedisDB.sismember(finishedSet, taskId);
//		if ( alreadyFinished ) {	
//			logger.debug("#finishTask: The task(id:{}) is already finished.", taskId);
//			return false;
//		} else {
//
//		}
		
		//Send the BseModiTask to client
		//Move this block of code the script.task.Step#step() method
		//wangqi 2012-02-09
		/*
		BseModiTask.Builder modiBuilder = BseModiTask.newBuilder();
		modiBuilder.setTaskID(StringUtil.toInt(taskId, 0));
		modiBuilder.setStep(task.getStep());
		XinqiMessage xinqiMsg = new XinqiMessage();
		xinqiMsg.payload = modiBuilder.build();
		
		GameContext.getInstance().writeResponse(user.getSession(), xinqiMsg);
		*/
		
		logger.debug("User {} finish the task(id:{}).", user.getRoleName(), taskId);
		
		return result;
	}