{"id":50878355,"url":"https://github.com/WellJay/spring-data-redis-tools","last_synced_at":"2026-07-03T02:01:15.799Z","repository":{"id":35660934,"uuid":"39935983","full_name":"WellJay/spring-data-redis-tools","owner":"WellJay","description":"🔒spring data redis 封装工具类包含分布式锁(distributedLock)、分布式唯一键(distributedId)","archived":false,"fork":false,"pushed_at":"2020-08-26T08:18:04.000Z","size":128,"stargazers_count":49,"open_issues_count":1,"forks_count":23,"subscribers_count":7,"default_branch":"master","last_synced_at":"2023-03-03T05:18:05.549Z","etag":null,"topics":["distributed-id","distributed-lock","redis","redis-tool","spring-data-redis"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WellJay.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}},"created_at":"2015-07-30T06:57:11.000Z","updated_at":"2023-02-24T03:26:53.000Z","dependencies_parsed_at":"2022-08-17T20:31:05.191Z","dependency_job_id":null,"html_url":"https://github.com/WellJay/spring-data-redis-tools","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"purl":"pkg:github/WellJay/spring-data-redis-tools","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WellJay%2Fspring-data-redis-tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WellJay%2Fspring-data-redis-tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WellJay%2Fspring-data-redis-tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WellJay%2Fspring-data-redis-tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WellJay","download_url":"https://codeload.github.com/WellJay/spring-data-redis-tools/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WellJay%2Fspring-data-redis-tools/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35069183,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-03T02:00:05.635Z","response_time":110,"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":["distributed-id","distributed-lock","redis","redis-tool","spring-data-redis"],"created_at":"2026-06-15T12:00:25.790Z","updated_at":"2026-07-03T02:01:15.789Z","avatar_url":"https://github.com/WellJay.png","language":"Java","funding_links":[],"categories":["分布式开发"],"sub_categories":["微服务框架"],"readme":"# spring-data-redis-tools\n- RedisTemplate封装工具类 `redisTools`\n- 可视化分布式ID生成器 `distributedId` (eg:JD202501010001)\n- 可靠分布式锁工具类 `distributedLock`（lua脚本实现原子性解决断电问题、valueId避免错误释放问题）\n- [Redis技术总结思维导图](#user-content-redis技术总结)   \n***\n## Maven\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n    \u003cartifactId\u003espring-boot-starter-data-redis\u003c/artifactId\u003e\n\u003c/dependency\u003e\n```\n## RedisConfiguration\n```java\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.cache.CacheManager;\nimport org.springframework.cache.annotation.EnableCaching;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\nimport org.springframework.data.redis.cache.RedisCacheManager;\nimport org.springframework.data.redis.connection.jedis.JedisConnectionFactory;\nimport org.springframework.data.redis.core.RedisTemplate;\nimport org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;\nimport org.springframework.data.redis.serializer.StringRedisSerializer;\nimport redis.clients.jedis.JedisPoolConfig;\n\n/**\n * @author wellJay\n */\n@Configuration\n@EnableCaching\npublic class RedisConfiguration {\n    //过期时间一天\n    private static final int DEFAULT_EXPIRE_TIME = 3600 * 24;\n\n    //从配置文件读取redis参数\n    @Autowired\n    private CloudConfigProperties cloudConfigProperties;\n\n    /**\n     * jedisPoolConfig config\n     */\n    @Bean\n    public JedisPoolConfig jedisPoolConfig() {\n        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();\n        jedisPoolConfig.setMaxIdle(cloudConfigProperties.getRedis().getMaxIdle());\n        jedisPoolConfig.setMinIdle(cloudConfigProperties.getRedis().getMinIdle());\n        jedisPoolConfig.setTestOnBorrow(cloudConfigProperties.getRedis().getTestOnBorrow());\n        jedisPoolConfig.setTestOnReturn(cloudConfigProperties.getRedis().getTestOnReturn());\n        return jedisPoolConfig;\n    }\n\n    /**\n     * JedisConnectionFactory\n     */\n    @Bean\n    public JedisConnectionFactory jedisConnectionFactory(JedisPoolConfig jedisPoolConfig) {\n        JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory();\n        jedisConnectionFactory.setHostName(cloudConfigProperties.getRedis().getHost());\n        jedisConnectionFactory.setPort(cloudConfigProperties.getRedis().getPort());\n        jedisConnectionFactory.setPassword(cloudConfigProperties.getRedis().getPassword());\n        jedisConnectionFactory.setTimeout(cloudConfigProperties.getRedis().getTimeout());\n        jedisConnectionFactory.setUsePool(true);\n        jedisConnectionFactory.setPoolConfig(jedisPoolConfig);\n        return jedisConnectionFactory;\n    }\n    \n    /**\n     * RedisTemplate\n     * 从执行时间上来看，JdkSerializationRedisSerializer是最高效的（毕竟是JDK原生的），但是是序列化的结果字符串是最长的。\n     * JSON由于其数据格式的紧凑性，序列化的长度是最小的，时间比前者要多一些。\n     * 所以个人的选择是倾向使用JacksonJsonRedisSerializer作为POJO的序列器。 \n     */\n    @Bean\n    public RedisTemplate redisTemplate(JedisConnectionFactory jedisConnectionFactory) {\n        RedisTemplate\u003c?, ?\u003e redisTemplate = new RedisTemplate();\n        redisTemplate.setConnectionFactory(jedisConnectionFactory);\n        redisTemplate.setDefaultSerializer(new StringRedisSerializer());\n        //设置普通value序列化方式\n        redisTemplate.setValueSerializer(new StringRedisSerializer());\n        redisTemplate.setHashValueSerializer(new JdkSerializationRedisSerializer());\n        return redisTemplate;\n    }\n\n    @Bean\n    public CacheManager cacheManager(RedisTemplate redisTemplate) {\n        RedisCacheManager redisCacheManager = new RedisCacheManager(redisTemplate);\n        redisCacheManager.setDefaultExpiration(DEFAULT_EXPIRE_TIME);\n        return redisCacheManager;\n    }\n}\n```\n\n## How To Use\n1、注入util方式，适用于复杂的业务处理\n```java\n@Autowired\nprivate RedisCacheUtil redisCacheUtil;\n```\n2、Spring注解方式适用于简单的数据缓存\n```java\n@Cacheable(value = Constants.RedisKey.XXX_KEY)\n```\n## Redis技术总结\n![](Redis技术总结.png)\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FWellJay%2Fspring-data-redis-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FWellJay%2Fspring-data-redis-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FWellJay%2Fspring-data-redis-tools/lists"}