{"id":15583452,"url":"https://github.com/davidmarquis/redis-scheduler","last_synced_at":"2025-07-25T06:09:16.566Z","repository":{"id":12504802,"uuid":"15174429","full_name":"davidmarquis/redis-scheduler","owner":"davidmarquis","description":"Java implementation of a lightweight distributed task scheduler based on Redis with support for Jedis, Lettuce and Spring Data Redis","archived":false,"fork":false,"pushed_at":"2023-08-11T09:19:44.000Z","size":63,"stargazers_count":82,"open_issues_count":2,"forks_count":30,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-25T04:01:55.104Z","etag":null,"topics":["java","jedis","lettuce","redis","scheduler","spring-data-redis","tasks"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"Nukkit/Nukkit","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidmarquis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-12-13T21:22:25.000Z","updated_at":"2024-05-15T09:58:49.000Z","dependencies_parsed_at":"2024-11-01T13:14:51.532Z","dependency_job_id":null,"html_url":"https://github.com/davidmarquis/redis-scheduler","commit_stats":{"total_commits":26,"total_committers":1,"mean_commits":26.0,"dds":0.0,"last_synced_commit":"db8086c2b4d178c820277bb24fa81de7d3102e76"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/davidmarquis/redis-scheduler","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidmarquis%2Fredis-scheduler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidmarquis%2Fredis-scheduler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidmarquis%2Fredis-scheduler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidmarquis%2Fredis-scheduler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidmarquis","download_url":"https://codeload.github.com/davidmarquis/redis-scheduler/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidmarquis%2Fredis-scheduler/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266963486,"owners_count":24013059,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","jedis","lettuce","redis","scheduler","spring-data-redis","tasks"],"created_at":"2024-10-02T20:08:26.324Z","updated_at":"2025-07-25T06:09:16.525Z","avatar_url":"https://github.com/davidmarquis.png","language":"Java","funding_links":[],"categories":["任务调度"],"sub_categories":["语音合成"],"readme":"redis-scheduler\n===============\n\nDistributed Scheduler using Redis for Java applications.\n\nWhat is this?\n-------------\n\n`redis-scheduler` is a Java implementation of a distributed scheduler using Redis. It has the following features:\n\n - **Useable in a distributed environment**: Uses Redis transactions for effectively preventing a task to be run on\n multiple instances of the same application.\n - **Lightweight**: Uses a single thread.\n - **Configurable polling**: Polling delay can be configured to tweak execution precision (at the cost of performance)\n - **Multiple schedulers support**: You can create multiple schedulers in the same logical application if you need to.\n - **Support for multiple client libraries**: Drivers exist for [Jedis](https://github.com/xetorthio/jedis), [Lettuce](https://lettuce.io/) and [Spring Data's RedisTemplate](https://projects.spring.io/spring-data-redis/)\n\nHigh level concepts\n-------------------\n\n#### Scheduled Task\n\nA scheduled task is a job that you need to execute in the future at a particular time.\nIn `redis-scheduler`, a task is represented solely by an arbitrary string identifier that has no particular meaning to the library.\nIt's your application that has to make sense of this identifier.\n\n#### Scheduler\n\n`RedisTaskScheduler`: This interface is where you submit your tasks for future execution.  Once submitted, a task will only be\nexecuted at or after the trigger time you provide.\n\n#### `TaskTriggerListener` interface\n\nThis is the main interface you must implement to actually run the tasks once they are due for execution. The library will\ncall the `taskTriggered` method for each task that is due for execution.\n\n\nBuilding the project\n--------------------\n\n``` bash\nmvn package\n```\n\nMaven dependency\n----------------\n\nThis artifact is published on Maven Central:\n\n``` xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.davidmarquis\u003c/groupId\u003e\n    \u003cartifactId\u003eredis-scheduler\u003c/artifactId\u003e\n    \u003cversion\u003e3.0.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nYou'll need to add one of the specific dependencies to use the different available drivers:\n\nTo use with Lettuce:\n\n``` xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.lettuce\u003c/groupId\u003e\n    \u003cartifactId\u003elettuce-core\u003c/artifactId\u003e\n    \u003cversion\u003e5.0.3.RELEASE\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nTo use with Jedis:\n\n``` xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eredis.clients\u003c/groupId\u003e\n    \u003cartifactId\u003ejedis\u003c/artifactId\u003e\n    \u003cversion\u003e2.9.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nTo use with Spring Data Redis:\n\n``` xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.springframework.data\u003c/groupId\u003e\n    \u003cartifactId\u003espring-data-redis\u003c/artifactId\u003e\n    \u003cversion\u003e1.8.11.RELEASE\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n\nUsage with Lettuce\n------------------\n\nThe scheduler must be instantiated with the `LettuceDriver`:\n\n``` java\nRedisClient client = RedisClient.create(RedisURI.create(\"localhost\", 6379));\nRedisTaskScheduler scheduler = new RedisTaskScheduler(new LettuceDriver(client), new YourTaskTriggerListener());\n\nscheduler.start();\n```\n\nUsage with Jedis\n----------------\n\nThe scheduler must be instantiated with the `JedisDriver`:\n\n``` java\nJedisPool pool = new JedisPool(\"localhost\", 6379);\nRedisTaskScheduler scheduler = new RedisTaskScheduler(new JedisDriver(pool), new YourTaskTriggerListener());\n\nscheduler.start();\n```\n\nUsage with Spring\n-----------------\n\nFirst declare the base beans for Redis connectivity (if not already done in your project). This part can be different\nfor your project.\n\n``` xml\n\u003cbean id=\"jedisConnectionFactory\" class=\"org.springframework.data.redis.connection.jedis.JedisConnectionFactory\"\u003e\n    \u003cproperty name=\"hostName\" value=\"localhost\"/\u003e\n    \u003cproperty name=\"port\" value=\"6379\"/\u003e\n\u003c/bean\u003e\n\n\u003cbean id=\"redisTemplate\" class=\"org.springframework.data.redis.core.RedisTemplate\"\u003e\n    \u003cproperty name=\"connectionFactory\" ref=\"jedisConnectionFactory\"/\u003e\n    \u003cproperty name=\"keySerializer\"\u003e\n        \u003cbean class=\"org.springframework.data.redis.serializer.StringRedisSerializer\"/\u003e\n    \u003c/property\u003e\n\u003c/bean\u003e\n\n\u003cbean id=\"springTemplateDriver\" class=\"com.github.davidmarquis.redisscheduler.drivers.spring.RedisTemplateDriver\"\u003e\n    \u003cconstructor-arg name=\"redisTemplate\" ref=\"redisTemplate\"/\u003e\n\u003c/bean\u003e\n```\n\nFinally, declare the scheduler instance:\n\n``` xml\n\u003cbean id=\"scheduler\" class=\"com.github.davidmarquis.redisscheduler.RedisTaskScheduler\"\u003e\n    \u003cconstructor-arg name=\"driver\" ref=\"springTemplateDriver\"/\u003e\n    \u003cconstructor-arg name=\"listener\"\u003e\n        \u003cbean class=\"your.own.implementation.of.TaskTriggerListener\"/\u003e\n    \u003c/constructor-arg\u003e\n\u003c/bean\u003e\n```\n\nAs noted above, `RedisTaskScheduler` expects an implementation of the `TaskTriggerListener` interface which it will notify when a task is due for execution. You must implement this interface yourself and provide it to the scheduler as a constructor argument.\n\nSee the the test Spring context in `test/resources/application-context-test.xml` for a complete working example of the setup.\n\n\nScheduling a task in the future\n-------------------------------\n\n``` java\nscheduler.schedule(\"mytask\", new GregorianCalendar(2015, Calendar.JANUARY, 1, 4, 45, 0));\n```\n\nThis would schedule a task with ID \"mytask\" to be run at 4:45AM on January 1st 2015.\n\nBe notified once a task is due for execution\n--------------------------------------------\n\n``` java\npublic class MyTaskTriggerListener implements TaskTriggerListener {\n    public void taskTriggered(String taskId) {\n        System.out.printf(\"Task %s is due for execution.\", taskId);\n    }\n}\n```\n\nCustomizing polling delay\n----------------------------------\n\nBy default, polling delay is set to a few seconds (see implementation `RedisTaskScheduler` for actual value). If\nyou need your tasks to be triggered with more precision, decrease the polling delay using the `pollingDelayMillis` attribute of `RedisTaskScheduler`:\n\nIn Java:\n\n``` java\nscheduler.setPollingDelayMillis(500);\n```\n\nWith Spring:\n\n``` xml\n\u003cbean id=\"scheduler\" class=\"com.github.davidmarquis.redisscheduler.RedisTaskScheduler\"\u003e\n    \u003cproperty name=\"pollingDelayMillis\" value=\"500\"/\u003e\n\u003c/bean\u003e\n```\n\nIncreasing polling delay comes with a cost: higher load on Redis and your connection.\nTry to find the best balance for your needs.\n\nRetry polling when a Redis connection error happens\n---------------------------------------------------\n\nRetries can be configured using the `maxRetriesOnConnectionFailure` property on `RedisTaskScheduler`:\n\nIn Java:\n\n``` java\nscheduler.setMaxRetriesOnConnectionFailure(5);\n```\n\nWith Spring:\n\n``` xml\n\u003cbean id=\"scheduler\" class=\"com.github.davidmarquis.redisscheduler.RedisTaskScheduler\"\u003e\n    \u003cproperty name=\"maxRetriesOnConnectionFailure\" value=\"5\"/\u003e\n\u003c/bean\u003e\n```\n\nAfter the specified number of retries, the polling thread will stop and log an error.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidmarquis%2Fredis-scheduler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidmarquis%2Fredis-scheduler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidmarquis%2Fredis-scheduler/lists"}