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


Java Pipeline.sadd方法代碼示例

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


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

示例1: testSync

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Test
public void testSync() throws Exception {
  int rnd = ThreadLocalRandom.current().nextInt(0, presetElements.size());
  String key = presetElementKeys.get(rnd);
  String value = String.valueOf(presetElements.get(key));

  Pipeline pipeline = jedis.pipelined();

  Snapshot snapshot = commandTracker.snapshot();
  Snapshot discardSnapshot = discardTracker.snapshot();
  Snapshot txsnapshot = execTracker.snapshot();
  Snapshot pipelineSnapshot = pipelineTracker.snapshot();
  pipelineSnapshot.increment();
  Response<Long> added = pipeline.sadd(key, value);
  pipeline.sync();
  assertEquals(1, (long) added.get());
  pipelineSnapshot.validate();
  txsnapshot.validate();
  snapshot.validate();
  discardSnapshot.validate();
}
 
開發者ID:ApptuitAI,項目名稱:JInsight,代碼行數:22,代碼來源:JedisPipelineInstrumentationTest.java

示例2: testCloseSyncs

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Test
public void testCloseSyncs() throws Exception {
  int rnd = ThreadLocalRandom.current().nextInt(0, presetElements.size());
  String key = presetElementKeys.get(rnd);
  String value = String.valueOf(presetElements.get(key));

  Pipeline pipeline = jedis.pipelined();

  Snapshot snapshot = commandTracker.snapshot();
  Snapshot discardSnapshot = discardTracker.snapshot();
  Snapshot txsnapshot = execTracker.snapshot();
  Snapshot pipelineSnapshot = pipelineTracker.snapshot();
  pipelineSnapshot.increment();
  Response<Long> added = pipeline.sadd(key, value);
  pipeline.close();
  assertEquals(1, (long) added.get());
  pipelineSnapshot.validate();
  txsnapshot.validate();
  snapshot.validate();
  discardSnapshot.validate();
}
 
開發者ID:ApptuitAI,項目名稱:JInsight,代碼行數:22,代碼來源:JedisPipelineInstrumentationTest.java

示例3: doUpsertSet

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
private void doUpsertSet(Record record, List<ErrorRecord> tempRecords, Pipeline pipeline, String key, Field value)
    throws StageException {
  if (value != null && value.getType() == Field.Type.LIST) {
    List<Field> values = value.getValueAsList();
    for (Field element : values) {
      if (element != null) {
        String val = element.getValueAsString();
        pipeline.sadd(key, val);
        tempRecords.add(new ErrorRecord(record, "Set", key, val));
      }
    }
  } else {
    LOG.error(Errors.REDIS_04.getMessage(), value.getType(), "value should be List");
    errorRecordHandler.onError(
        new OnRecordErrorException(
            record,
            Errors.REDIS_04,
            value.getType(),
            "value should be List"
        )
    );
  }
}
 
開發者ID:streamsets,項目名稱:datacollector,代碼行數:24,代碼來源:RedisTarget.java

示例4: 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

示例5: 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

示例6: testLongSetPerformance1_1

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
public void testLongSetPerformance1_1() {
	JedisAdapter jedis = new JedisAdapter(host, port, config);

	//Store a long list
	int count = 500000;
	byte[] key = "longlist".getBytes();
	jedis.del(key);
	
	byte[][] longList = createLongList(count);
	Pipeline pipeline = jedis.pipelined();
	for ( int i=0; i<longList.length; i++ ) {
		pipeline.sadd(key, longList[i]);
	}
	pipeline.sync();
	Set<byte[]> userList = jedis.smembers(key);
	assertTrue(userList.size()>0);
	
	//Getting the list.
	long startM = 0l, endM = 0l;
	startM = System.currentTimeMillis();
	int max = 10;
	for ( int i=0; i<max; i++ ) {
		userList = jedis.smembers(key);
	}
	endM = System.currentTimeMillis();
	System.out.println("Redis longset:"+userList.size()+" loop " + max + " perform: " + (endM-startM)/max);
}
 
開發者ID:wangqi,項目名稱:gameserver,代碼行數:28,代碼來源:JedisTest.java

示例7: 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

示例8: setLastEntries

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
@Override
public void setLastEntries(Feed feed, List<String> entries) {
	try (Jedis jedis = pool.getResource()) {
		String key = buildRedisEntryKey(feed);

		Pipeline pipe = jedis.pipelined();
		pipe.del(key);
		for (String entry : entries) {
			pipe.sadd(key, entry);
		}
		pipe.expire(key, (int) TimeUnit.DAYS.toSeconds(7));
		pipe.sync();
	}
}
 
開發者ID:Athou,項目名稱:commafeed,代碼行數:15,代碼來源:RedisCacheService.java

示例9: 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

示例10: writeEventsForId

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
private Response<Long> writeEventsForId(Pipeline pipeline, AggregateId id, List<Event> eventsForId) {
    return pipeline.sadd(id.toString(), serialiseEvents(eventsForId));
}
 
開發者ID:opencredo,項目名稱:concursus,代碼行數:4,代碼來源:RedisEventLog.java

示例11: 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

示例12: finishTask

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
/**
	 * 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;
	}
 
開發者ID:wangqi,項目名稱:gameserver,代碼行數:74,代碼來源:TaskManager.java

示例13: invalidate

import redis.clients.jedis.Pipeline; //導入方法依賴的package包/類
private void invalidate(Pipeline pipeline, KeyType key) {
    String itemKey = itemKey(key);
    pipeline.hdel(cacheKey, itemKey);
    pipeline.sadd(cacheMissingKey(), keyTypeSerializationHelper.encode(key));
}
 
開發者ID:lithiumtech,項目名稱:rdbi,代碼行數:6,代碼來源:RedisHashCache.java


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