本文整理汇总了Java中redis.clients.jedis.JedisCluster.smembers方法的典型用法代码示例。如果您正苦于以下问题:Java JedisCluster.smembers方法的具体用法?Java JedisCluster.smembers怎么用?Java JedisCluster.smembers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redis.clients.jedis.JedisCluster
的用法示例。
在下文中一共展示了JedisCluster.smembers方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import redis.clients.jedis.JedisCluster; //导入方法依赖的package包/类
public Object get(String cluster, String key) throws Exception {
List<D_RedisClusterNode> nodes = clusterNodeService.getAllClusterNodes(cluster);
Set<HostAndPort> masters = new HashSet<HostAndPort>();
nodes.forEach(node->{
masters.add(new HostAndPort(node.getHost(), node.getPort()));
});
Object value = null;
JedisCluster jedis = new JedisCluster(masters);
try {
String type = jedis.type(key);
switch (type) {
case "string":
value = jedis.get(key);
break;
case "list":
value = jedis.lrange(key, 0, -1);
break;
case "set":
value = jedis.smembers(key);
break;
case "zset":
value = jedis.zrange(key, 0, -1);
break;
case "hash":
value = jedis.hgetAll(key);
break;
default:
break;
}
} finally {
jedis.close();
}
return value;
}
示例2: storeCalendar
import redis.clients.jedis.JedisCluster; //导入方法依赖的package包/类
/**
* Store a {@link 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, JedisCluster 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);
}
jedis.hmset(calendarHashKey, calendarMap);
jedis.sadd(redisSchema.calendarsSet(), calendarHashKey);
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);
}
}
}
}
示例3: removeJob
import redis.clients.jedis.JedisCluster; //导入方法依赖的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, JedisCluster 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);
// remove the job and any associated data
Long delJobHashKeyResponse = jedis.del(jobHashKey);
// remove the blocked job key
jedis.del(jobBlockedKey);
// remove the job's data map
jedis.del(jobDataMapHashKey);
// remove the job from the set of all jobs
jedis.srem(redisSchema.jobsSet(), jobHashKey);
// remove the job from the set of blocked jobs
jedis.srem(redisSchema.blockedJobsSet(), jobHashKey);
// remove the job from its group
jedis.srem(jobGroupSetKey, jobHashKey);
// retrieve the keys for all triggers associated with this job, then delete that set
Set<String> jobTriggerSetResponse = jedis.smembers(jobTriggerSetKey);
jedis.del(jobTriggerSetKey);
Long jobGroupSetSizeResponse = jedis.scard(jobGroupSetKey);
if (jobGroupSetSizeResponse == 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
for (String triggerHashKey : jobTriggerSetResponse) {
// 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
jedis.srem(redisSchema.triggersSet(), triggerHashKey);
// remove the trigger's group from the set of all trigger groups
jedis.srem(redisSchema.triggerGroupsSet(), triggerGroupSetKey);
// remove this trigger from its group
jedis.srem(triggerGroupSetKey, triggerHashKey);
// delete the trigger
jedis.del(triggerHashKey);
}
return delJobHashKeyResponse == 1;
}
示例4: triggersFired
import redis.clients.jedis.JedisCluster; //导入方法依赖的package包/类
/**
* Inform the <code>JobStore</code> that the scheduler is now firing the
* given <code>Trigger</code> (executing its associated <code>Job</code>),
* that it had previously acquired (reserved).
*
* @param triggers a list of triggers
* @param jedis a thread-safe Redis connection
* @return may return null if all the triggers or their calendars no longer exist, or
* if the trigger was not successfully put into the 'executing'
* state. Preference is to return an empty list if none of the triggers
* could be fired.
*/
@Override
public List<TriggerFiredResult> triggersFired(List<OperableTrigger> triggers, JedisCluster jedis) throws JobPersistenceException, ClassNotFoundException {
List<TriggerFiredResult> results = new ArrayList<>();
for (OperableTrigger trigger : triggers) {
final String triggerHashKey = redisSchema.triggerHashKey(trigger.getKey());
logger.debug(String.format("Trigger %s fired.", triggerHashKey));
Boolean triggerExistsResponse = jedis.exists(triggerHashKey);
Double triggerAcquiredResponse = jedis.zscore(redisSchema.triggerStateKey(RedisTriggerState.ACQUIRED), triggerHashKey);
if (!triggerExistsResponse || triggerAcquiredResponse == null) {
// the trigger does not exist or the trigger is not acquired
if (!triggerExistsResponse) {
logger.debug(String.format("Trigger %s does not exist.", triggerHashKey));
} else {
logger.debug(String.format("Trigger %s was not acquired.", triggerHashKey));
}
continue;
}
Calendar calendar = null;
final String calendarName = trigger.getCalendarName();
if (calendarName != null) {
calendar = retrieveCalendar(calendarName, jedis);
if (calendar == null) {
continue;
}
}
final Date previousFireTime = trigger.getPreviousFireTime();
trigger.triggered(calendar);
JobDetail job = retrieveJob(trigger.getJobKey(), jedis);
TriggerFiredBundle triggerFiredBundle = new TriggerFiredBundle(job, trigger, calendar, false, new Date(), previousFireTime, previousFireTime, trigger.getNextFireTime());
// handling jobs for which concurrent execution is disallowed
if (isJobConcurrentExecutionDisallowed(job.getJobClass())) {
final String jobHashKey = redisSchema.jobHashKey(trigger.getJobKey());
final String jobTriggerSetKey = redisSchema.jobTriggersSetKey(job.getKey());
for (String nonConcurrentTriggerHashKey : jedis.smembers(jobTriggerSetKey)) {
Double score = jedis.zscore(redisSchema.triggerStateKey(RedisTriggerState.WAITING), nonConcurrentTriggerHashKey);
if (score != null) {
setTriggerState(RedisTriggerState.BLOCKED, score, nonConcurrentTriggerHashKey, jedis);
} else {
score = jedis.zscore(redisSchema.triggerStateKey(RedisTriggerState.PAUSED), nonConcurrentTriggerHashKey);
if (score != null) {
setTriggerState(RedisTriggerState.PAUSED_BLOCKED, score, nonConcurrentTriggerHashKey, jedis);
}
}
}
jedis.set(redisSchema.jobBlockedKey(job.getKey()), schedulerInstanceId);
jedis.sadd(redisSchema.blockedJobsSet(), jobHashKey);
}
// release the fired trigger
if (trigger.getNextFireTime() != null) {
final long nextFireTime = trigger.getNextFireTime().getTime();
jedis.hset(triggerHashKey, TRIGGER_NEXT_FIRE_TIME, Long.toString(nextFireTime));
logger.debug(String.format("Releasing trigger %s with next fire time %s. Setting state to WAITING.", triggerHashKey, nextFireTime));
setTriggerState(RedisTriggerState.WAITING, (double) nextFireTime, triggerHashKey, jedis);
} else {
jedis.hset(triggerHashKey, TRIGGER_NEXT_FIRE_TIME, "");
unsetTriggerState(triggerHashKey, jedis);
}
results.add(new TriggerFiredResult(triggerFiredBundle));
}
return results;
}