redis.clients.jedis.commands.JedisCommands Java Examples

The following examples show how to use redis.clients.jedis.commands.JedisCommands. 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: DynoProxy.java    From conductor with Apache License 2.0 6 votes vote down vote up
public Set<String> hkeys(String key) {
    logger.trace("hkeys {}", key);
    JedisCommands client = dynoClient;
    Set<String> keys = new HashSet<>();
    int cursor = 0;
    do {
        ScanResult<Entry<String, String>> sr = client.hscan(key, "" + cursor);
        cursor = Integer.parseInt(sr.getCursor());
        List<Entry<String, String>> result = sr.getResult();
        for (Entry<String, String> e : result) {
            keys.add(e.getKey());
        }
    } while (cursor > 0);

    return keys;
}
 
Example #2
Source File: DynoProxy.java    From conductor with Apache License 2.0 6 votes vote down vote up
public Set<String> smembers(String key) {
    logger.trace("smembers {}", key);
    JedisCommands client = dynoClient;
    Set<String> r = new HashSet<>();
    int cursor = 0;
    ScanParams sp = new ScanParams();
    sp.count(50);

    do {
        ScanResult<String> scanResult = client.sscan(key, "" + cursor, sp);
        cursor = Integer.parseInt(scanResult.getCursor());
        r.addAll(scanResult.getResult());

    } while (cursor > 0);

    return r;

}
 
Example #3
Source File: RedisJobStore.java    From quartz-redis-jobstore with Apache License 2.0 6 votes vote down vote up
@Override
public boolean removeTriggers(final List<TriggerKey> triggerKeys) throws JobPersistenceException {
    return doWithLock(new LockCallback<Boolean>() {
        @Override
        public Boolean doWithLock(JedisCommands jedis) throws JobPersistenceException {
            boolean removed = triggerKeys.size() > 0;
            for (TriggerKey triggerKey : triggerKeys) {
                try {
                    removed = storage.removeTrigger(triggerKey, jedis) && removed;
                } catch (ClassNotFoundException e) {
                    throw new JobPersistenceException(e.getMessage(), e);
                }
            }
            return removed;
        }
    }, "Could not remove trigger.");
}
 
Example #4
Source File: DynomiteJedisProvider.java    From conductor with Apache License 2.0 6 votes vote down vote up
@Override
public JedisCommands get() {
    ConnectionPoolConfigurationImpl connectionPoolConfiguration =
            new ConnectionPoolConfigurationImpl(configuration.getClusterName())
            .withTokenSupplier(tokenMapSupplier)
            .setLocalRack(configuration.getAvailabilityZone())
            .setLocalDataCenter(configuration.getRegion())
            .setSocketTimeout(0)
            .setConnectTimeout(0)
            .setMaxConnsPerHost(
                    configuration.getMaxConnectionsPerHost()
            );

    return new DynoJedisClient.Builder()
            .withHostSupplier(hostSupplier)
            .withApplicationName(configuration.getAppId())
            .withDynomiteClusterName(configuration.getClusterName())
            .withCPConfig(connectionPoolConfiguration)
            .build();
}
 
Example #5
Source File: DynoQueueDAOTest.java    From conductor with Apache License 2.0 6 votes vote down vote up
@Before
public void init() {
	JedisCommands jedisMock = new JedisMock();
	queueDAO = new DynoQueueDAO(jedisMock, jedisMock, new ShardSupplier() {

		@Override
		public Set<String> getQueueShards() {
			return new HashSet<>(Collections.singletonList("a"));
		}

		@Override
		public String getCurrentShard() {
			return "a";
		}

		@Override
		public String getShardForHost(Host host) {
			return "a";
		}
	}, new TestConfiguration());
}
 
Example #6
Source File: RedisJobStore.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
/**
 * Remove (delete) the <code>{@link org.quartz.Trigger}</code> with the
 * given key, and store the new given one - which must be associated
 * with the same job.
 *
 * @param triggerKey the key of the trigger to be replaced
 * @param newTrigger The new <code>Trigger</code> to be stored.
 * @return <code>true</code> if a <code>Trigger</code> with the given
 * name & group was found and removed from the store.
 */
@Override
public boolean replaceTrigger(final TriggerKey triggerKey, final OperableTrigger newTrigger) throws JobPersistenceException {
    return doWithLock(new LockCallback<Boolean>() {
        @Override
        public Boolean doWithLock(JedisCommands jedis) throws JobPersistenceException {
            try {
                return storage.replaceTrigger(triggerKey, newTrigger, jedis);
            } catch (ClassNotFoundException e) {
                throw new JobPersistenceException(e.getMessage(), e);
            }
        }
    }, "Could not remove trigger.");
}
 
Example #7
Source File: RedisJobStore.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve the given <code>{@link org.quartz.Trigger}</code>.
 *
 * @param calName The name of the <code>Calendar</code> to be retrieved.
 * @return The desired <code>Calendar</code>, or null if there is no
 * match.
 */
@Override
public Calendar retrieveCalendar(final String calName) throws JobPersistenceException {
    return doWithLock(new LockCallback<Calendar>() {
        @Override
        public Calendar doWithLock(JedisCommands jedis) throws JobPersistenceException {
            return storage.retrieveCalendar(calName, jedis);
        }
    }, "Could not retrieve calendar.");
}
 
Example #8
Source File: RedisJobStore.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
/**
 * 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 which are being fired by the scheduler
 * @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(final List<OperableTrigger> triggers) throws JobPersistenceException {
    return doWithLock(new LockCallback<List<TriggerFiredResult>>() {
        @Override
        public List<TriggerFiredResult> doWithLock(JedisCommands jedis) throws JobPersistenceException {
            try {
                return storage.triggersFired(triggers, jedis);
            } catch (ClassNotFoundException e) {
                throw new JobPersistenceException(e.getMessage(), e);
            }
        }
    }, "Could not set triggers as fired.");
}
 
Example #9
Source File: DynoQueueDAO.java    From conductor with Apache License 2.0 5 votes vote down vote up
@Deprecated
public DynoQueueDAO(JedisCommands dynoClient, JedisCommands dynoClientRead, ShardSupplier ss, Configuration config) {
    this.dynoClient = dynoClient;
    this.dynoClientRead = dynoClient;
    this.ss = ss;
    this.config = config;
    init();
}
 
Example #10
Source File: RedisJobStore.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
/**
 * Clear (delete!) all scheduling data - all {@link org.quartz.Job}s, {@link org.quartz.Trigger}s
 * {@link org.quartz.Calendar}s.
 *
 * @throws org.quartz.JobPersistenceException
 */
@Override
public void clearAllSchedulingData() throws JobPersistenceException {
    doWithLock(new LockCallbackWithoutResult() {
        @Override
        public Void doWithLock(JedisCommands jedis) throws JobPersistenceException {
            try {
                storage.clearAllSchedulingData(jedis);
            } catch (ClassNotFoundException e) {
                throw new JobPersistenceException("Could not clear scheduling data.");
            }
            return null;
        }
    }, "Could not clear scheduling data.");
}
 
Example #11
Source File: RedisJobStore.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
/**
 * Determine whether a {@link org.quartz.Trigger} with the given identifier already
 * exists within the scheduler.
 *
 * @param triggerKey the identifier to check for
 * @return true if a Trigger exists with the given identifier
 * @throws org.quartz.JobPersistenceException
 */
@Override
public boolean checkExists(final TriggerKey triggerKey) throws JobPersistenceException {
    return doWithLock(new LockCallback<Boolean>() {
        @Override
        public Boolean doWithLock(JedisCommands jedis) throws JobPersistenceException {
            return storage.checkExists(triggerKey, jedis);
        }
    }, "Could not check if trigger exists: " + triggerKey);
}
 
Example #12
Source File: RedisJobStore.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
/**
 * Determine whether a {@link org.quartz.Job} with the given identifier already
 * exists within the scheduler.
 *
 * @param jobKey the identifier to check for
 * @return true if a Job exists with the given identifier
 * @throws org.quartz.JobPersistenceException
 */
@Override
public boolean checkExists(final JobKey jobKey) throws JobPersistenceException {
    return doWithLock(new LockCallback<Boolean>() {
        @Override
        public Boolean doWithLock(JedisCommands jedis) throws JobPersistenceException {
            return storage.checkExists(jobKey, jedis);
        }
    }, "Could not check if job exists: " + jobKey);
}
 
Example #13
Source File: RedisJobStore.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve the given <code>{@link org.quartz.Trigger}</code>.
 *
 * @param triggerKey the key of the desired trigger
 * @return The desired <code>Trigger</code>, or null if there is no
 * match.
 */
@Override
public OperableTrigger retrieveTrigger(final TriggerKey triggerKey) throws JobPersistenceException {
    return doWithLock(new LockCallback<OperableTrigger>() {
        @Override
        public OperableTrigger doWithLock(JedisCommands jedis) throws JobPersistenceException {
            return storage.retrieveTrigger(triggerKey, jedis);
        }
    }, "Could not retrieve trigger.");
}
 
Example #14
Source File: RedisJobStore.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
/**
 * Get the number of <code>{@link org.quartz.Calendar}</code> s that are
 * stored in the <code>JobsStore</code>.
 */
@Override
public int getNumberOfCalendars() throws JobPersistenceException {
    return doWithLock(new LockCallback<Integer>() {
        @Override
        public Integer doWithLock(JedisCommands jedis) throws JobPersistenceException {
            return storage.getNumberOfCalendars(jedis);
        }
    }, "Could not get number of jobs.");
}
 
Example #15
Source File: RedisExecutionDAOTest.java    From conductor with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
    Configuration config = new TestConfiguration();
    JedisCommands jedisMock = new JedisMock();
    DynoProxy dynoClient = new DynoProxy(jedisMock);

    executionDAO = new RedisExecutionDAO(dynoClient, objectMapper, config);
}
 
Example #16
Source File: RedisRateLimitDaoTest.java    From conductor with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
    Configuration config = new TestConfiguration();
    JedisCommands jedisMock = new JedisMock();
    DynoProxy dynoClient = new DynoProxy(jedisMock);

    rateLimitingDao = new RedisRateLimitingDAO(dynoClient, objectMapper, config);
}
 
Example #17
Source File: RedisMetadataDAOTest.java    From conductor with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
	Configuration config = new TestConfiguration();
	JedisCommands jedisMock = new JedisMock();
	DynoProxy dynoClient = new DynoProxy(jedisMock);
	
	redisMetadataDAO = new RedisMetadataDAO(dynoClient, objectMapper, config);
}
 
Example #18
Source File: RedisJobStore.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
/**
 * Get the number of <code>{@link org.quartz.Job}</code> s that are
 * stored in the <code>JobsStore</code>.
 */
@Override
public int getNumberOfJobs() throws JobPersistenceException {
    return  doWithLock(new LockCallback<Integer>() {
        @Override
        public Integer doWithLock(JedisCommands jedis) throws JobPersistenceException {
            return storage.getNumberOfJobs(jedis);
        }
    }, "Could not get number of jobs.");
}
 
Example #19
Source File: RedisJobStore.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
/**
 * Get the number of <code>{@link org.quartz.Trigger}</code> s that are
 * stored in the <code>JobsStore</code>.
 */
@Override
public int getNumberOfTriggers() throws JobPersistenceException {
    return doWithLock(new LockCallback<Integer>() {
        @Override
        public Integer doWithLock(JedisCommands jedis) throws JobPersistenceException {
            return storage.getNumberOfTriggers(jedis);
        }
    }, "Could not get number of jobs.");
}
 
Example #20
Source File: RedisJobStore.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
private JedisCommands getResource() throws JobPersistenceException {
    if (jedisCluster != null) {
        return jedisCluster;
    } else {
        return jedisPool.getResource();
    }
}
 
Example #21
Source File: RedisJobStore.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
/**
 * Inform the <code>JobStore</code> that the scheduler no longer plans to
 * fire the given <code>Trigger</code>, that it had previously acquired
 * (reserved).
 *
 * @param trigger the trigger to be released
 */
@Override
public void releaseAcquiredTrigger(final OperableTrigger trigger) {
    try {
        doWithLock(new LockCallbackWithoutResult() {
            @Override
            public Void doWithLock(JedisCommands jedis) throws JobPersistenceException {
                storage.releaseAcquiredTrigger(trigger, jedis);
                return null;
            }
        }, "Could not release acquired trigger.");
    } catch (JobPersistenceException e) {
        logger.error("Could not release acquired trigger.", e);
    }
}
 
Example #22
Source File: RedisJobStore.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
/**
 * Get a handle to the next trigger to be fired, and mark it as 'reserved'
 * by the calling scheduler.
 *
 * @param noLaterThan If > 0, the JobStore should only return a Trigger
 *                    that will fire no later than the time represented in this value as
 *                    milliseconds.
 * @param maxCount the maximum number of triggers to return
 * @param timeWindow  @see #releaseAcquiredTrigger(Trigger)
 */
@Override
public List<OperableTrigger> acquireNextTriggers(final long noLaterThan, final int maxCount, final long timeWindow) throws JobPersistenceException {
    return doWithLock(new LockCallback<List<OperableTrigger>>() {
        @Override
        public List<OperableTrigger> doWithLock(JedisCommands jedis) throws JobPersistenceException {
            try {
                return storage.acquireNextTriggers(noLaterThan, maxCount, timeWindow, jedis);
            } catch (ClassNotFoundException e) {
                throw new JobPersistenceException(e.getMessage(), e);
            }
        }
    }, "Could not acquire next triggers.");
}
 
Example #23
Source File: RedisJobStore.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
/**
 * Get the names of all of the <code>{@link org.quartz.Job}</code>
 * groups.
 * <p/>
 * <p>
 * If there are no known group names, the result should be a zero-length
 * array (not <code>null</code>).
 * </p>
 */
@Override
public List<String> getJobGroupNames() throws JobPersistenceException {
    return doWithLock(new LockCallback<List<String>>() {
        @Override
        public List<String> doWithLock(JedisCommands jedis) throws JobPersistenceException {
            return storage.getJobGroupNames(jedis);
        }
    }, "Could not retrieve job group names.");
}
 
Example #24
Source File: RedisJobStore.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
/**
 * Get the names of all of the <code>{@link org.quartz.Trigger}</code>
 * groups.
 * <p/>
 * <p>
 * If there are no known group names, the result should be a zero-length
 * array (not <code>null</code>).
 * </p>
 */
@Override
public List<String> getTriggerGroupNames() throws JobPersistenceException {
    return doWithLock(new LockCallback<List<String>>() {
        @Override
        public List<String> doWithLock(JedisCommands jedis) throws JobPersistenceException {
            return storage.getTriggerGroupNames(jedis);
        }
    }, "Could not retrieve trigger group names.");
}
 
Example #25
Source File: RedisJobStore.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
/**
 * Get the names of all of the <code>{@link org.quartz.Calendar}</code> s
 * in the <code>JobStore</code>.
 * <p/>
 * <p>
 * If there are no Calendars in the given group name, the result should be
 * a zero-length array (not <code>null</code>).
 * </p>
 */
@Override
public List<String> getCalendarNames() throws JobPersistenceException {
    return doWithLock(new LockCallback<List<String>>() {
        @Override
        public List<String> doWithLock(JedisCommands jedis) throws JobPersistenceException {
            return storage.getCalendarNames(jedis);
        }
    }, "Could not retrieve calendar names.");
}
 
Example #26
Source File: RedisJobStore.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
/**
 * Get all of the Triggers that are associated to the given Job.
 * <p/>
 * <p>
 * If there are no matches, a zero-length array should be returned.
 * </p>
 *
 * @param jobKey the key of the job for which to retrieve triggers
 */
@Override
public List<OperableTrigger> getTriggersForJob(final JobKey jobKey) throws JobPersistenceException {
    return doWithLock(new LockCallback<List<OperableTrigger>>() {
        @Override
        public List<OperableTrigger> doWithLock(JedisCommands jedis) throws JobPersistenceException {
            return storage.getTriggersForJob(jobKey, jedis);
        }
    }, "Could not retrieve triggers for job.");
}
 
Example #27
Source File: RedisJobStore.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
/**
 * Get the current state of the identified <code>{@link org.quartz.Trigger}</code>.
 *
 * @param triggerKey the key of the trigger for which to retrieve state
 * @see org.quartz.Trigger.TriggerState
 */
@Override
public Trigger.TriggerState getTriggerState(final TriggerKey triggerKey) throws JobPersistenceException {
    return doWithLock(new LockCallback<Trigger.TriggerState>() {
        @Override
        public Trigger.TriggerState doWithLock(JedisCommands jedis) throws JobPersistenceException {
            return storage.getTriggerState(triggerKey, jedis);
        }
    }, "Could not retrieve trigger state.");
}
 
Example #28
Source File: RedisJobStore.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
/**
 * Pause the <code>{@link org.quartz.Trigger}</code> with the given key.
 *
 * @param triggerKey the key for the trigger to be paused
 * @see #resumeTrigger(org.quartz.TriggerKey)
 */
@Override
public void pauseTrigger(final TriggerKey triggerKey) throws JobPersistenceException {
    doWithLock(new LockCallbackWithoutResult() {
        @Override
        public Void doWithLock(JedisCommands jedis) throws JobPersistenceException {
            storage.pauseTrigger(triggerKey, jedis);
            return null;
        }
    }, "Could not pause trigger.");
}
 
Example #29
Source File: RedisJobStore.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
/**
 * Pause the <code>{@link org.quartz.Job}</code> with the given name - by
 * pausing all of its current <code>Trigger</code>s.
 *
 * @param jobKey the key of the job to be paused
 * @see #resumeJob(org.quartz.JobKey)
 */
@Override
public void pauseJob(final JobKey jobKey) throws JobPersistenceException {
    doWithLock(new LockCallbackWithoutResult() {
        @Override
        public Void doWithLock(JedisCommands jedis) throws JobPersistenceException {
            storage.pauseJob(jobKey, jedis);
            return null;
        }
    }, "Could not pause job.");
}
 
Example #30
Source File: RedisJobStore.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
@Override
public Set<String> getPausedTriggerGroups() throws JobPersistenceException {
    return doWithLock(new LockCallback<Set<String>>() {
        @Override
        public Set<String> doWithLock(JedisCommands jedis) throws JobPersistenceException {
            return storage.getPausedTriggerGroups(jedis);
        }
    }, "Could not retrieve paused trigger groups.");
}