├── .gitignore ├── LICENSE ├── README.md ├── alipay.png ├── flycache-core ├── .gitignore ├── doc │ └── sql │ │ └── node_group.sql ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── github │ │ └── flylib │ │ └── flycache │ │ ├── FlycacheCoreApp.java │ │ ├── config │ │ ├── Config.java │ │ ├── MyBatisConfig.java │ │ └── MyBatisMapperScannerConfig.java │ │ ├── controller │ │ └── IndexController.java │ │ ├── entity │ │ └── NodeGroupEntity.java │ │ ├── hash │ │ ├── ByteUtils.java │ │ ├── ConsistentHash.java │ │ ├── HashAlgorithm.java │ │ └── Node.java │ │ ├── postgre │ │ └── JSONTypeHandler.java │ │ ├── redis │ │ ├── JedisPoolShardFactory.java │ │ ├── JedisSettings.java │ │ ├── MyJedisPoolConfig.java │ │ └── RedisClient.java │ │ ├── repository │ │ └── NodeRepositery.java │ │ ├── service │ │ └── NodeGroupService.java │ │ ├── spring │ │ └── AppContextHolder.java │ │ └── util │ │ └── ShardUtil.java │ └── resources │ └── application.properties ├── redPacket.png └── wechat.png /.gitignore: -------------------------------------------------------------------------------- 1 | # maven ignore 2 | target/ 3 | *.jar 4 | *.war 5 | *.zip 6 | *.tar 7 | 8 | # eclipse ignore 9 | .settings/ 10 | .project 11 | .classpath 12 | 13 | # idea ignore 14 | .idea/ 15 | *.ipr 16 | *.iml 17 | *.iws 18 | 19 | # temp ignore 20 | logs/ 21 | *.doc 22 | *.log 23 | *.cache 24 | *.diff 25 | *.patch 26 | *.tmp 27 | 28 | # system ignore 29 | .DS_Store 30 | Thumbs.db 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # flycache 2 | 3 | ## 简介 4 | flycache是redis分布式分片存储的一个系统,支持弹性伸缩。 基于Java实现的一致性hash 5 | 6 | 7 | flycache: Based on Java consistent-hashing Redis elastic shard storage. 8 | 9 | ## 功能 10 | 1. 弹性伸缩,提供控制面板,管理员可以增加和删除Redis节点 11 | 2. Redis运行状态监控,报警 12 | 3. Redis故障或者网络故障的灾难应对 13 | 14 | ## 原理 15 | 1. consistent-hashing一致性hash 16 | 2. zookeeper保持一致性和监听 17 | 18 | ## 文章 19 | http://blog.csdn.net/lsm135/article/details/79081776 20 | 21 | ## 测试 22 | [http://localhost:20200/test1](http://localhost:20200/test1) 23 | 24 | [http://localhost:20200/nodeGroup](http://localhost:20200/nodeGroup) 25 | 26 | 如果您愿意捐助一下项目,可以通过微信/支付宝捐助哟~ 27 | 28 | |支付宝 | 微信 | 余额宝领红包| 29 | | ------------- |:-------------:|:-------------:| 30 | | ![](https://github.com/flylib/flycache/blob/master/alipay.png) | ![](https://github.com/flylib/flycache/blob/master/wechat.png) | ![](https://github.com/flylib/flycache/blob/master/redPacket.png) | 31 | 32 | -------------------------------------------------------------------------------- /alipay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bootsrc/flycache/632bbd824f0a549f7703703b7d2a60016527f95a/alipay.png -------------------------------------------------------------------------------- /flycache-core/.gitignore: -------------------------------------------------------------------------------- 1 | # maven ignore 2 | target/ 3 | *.jar 4 | *.war 5 | *.zip 6 | *.tar 7 | 8 | # eclipse ignore 9 | .settings/ 10 | .project 11 | .classpath 12 | 13 | # idea ignore 14 | .idea/ 15 | *.ipr 16 | *.iml 17 | *.iws 18 | 19 | # temp ignore 20 | logs/ 21 | *.doc 22 | *.log 23 | *.cache 24 | *.diff 25 | *.patch 26 | *.tmp 27 | 28 | # system ignore 29 | .DS_Store 30 | Thumbs.db 31 | -------------------------------------------------------------------------------- /flycache-core/doc/sql/node_group.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat PGSQL Data Transfer 3 | 4 | Source Server : local-postgres 5 | Source Server Version : 100100 6 | Source Host : localhost:5432 7 | Source Database : flycache 8 | Source Schema : public 9 | 10 | Target Server Type : PGSQL 11 | Target Server Version : 100100 12 | File Encoding : 65001 13 | 14 | Date: 2018-01-23 18:30:55 15 | */ 16 | 17 | 18 | -- ---------------------------- 19 | -- Table structure for node_group 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS "public"."node_group"; 22 | CREATE TABLE "public"."node_group" ( 23 | "id" varchar(60) COLLATE "default" NOT NULL, 24 | "creater" varchar(60) COLLATE "default", 25 | "node" varchar COLLATE "default", 26 | "time" varchar(60) COLLATE "default" 27 | ) 28 | WITH (OIDS=FALSE) 29 | 30 | ; 31 | 32 | -- ---------------------------- 33 | -- Records of node_group 34 | -- ---------------------------- 35 | INSERT INTO "public"."node_group" VALUES ('999', 'lsm', '[{"host": "localhost", "port": "6379", "remark": ""}, {"host": "localhost", "port": "6380", "remark": ""}, {"host": "localhost", "port": "6381", "remark": ""}]', '2018-01-23 00:00:01'); 36 | 37 | -- ---------------------------- 38 | -- Alter Sequences Owned By 39 | -- ---------------------------- 40 | 41 | -- ---------------------------- 42 | -- Primary Key structure for table node_group 43 | -- ---------------------------- 44 | ALTER TABLE "public"."node_group" ADD PRIMARY KEY ("id"); 45 | -------------------------------------------------------------------------------- /flycache-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | io.github.flylib 8 | flycache-core 9 | 1.0-SNAPSHOT 10 | 11 | 12 | org.springframework.boot 13 | spring-boot-starter-parent 14 | 1.5.8.RELEASE 15 | 16 | 17 | 18 | 19 | UTF-8 20 | UTF-8 21 | 1.8 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-maven-plugin 32 | 33 | 34 | 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-web 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-actuator 45 | 46 | 47 | org.apache.tomcat.embed 48 | tomcat-embed-jasper 49 | provided 50 | 51 | 52 | javax.servlet 53 | jstl 54 | 55 | 56 | com.alibaba 57 | fastjson 58 | 1.2.41 59 | 60 | 61 | org.apache.commons 62 | commons-lang3 63 | 3.7 64 | 65 | 66 | redis.clients 67 | jedis 68 | 2.9.0 69 | 70 | 71 | org.springframework.boot 72 | spring-boot-starter-jdbc 73 | 74 | 75 | org.springframework.boot 76 | spring-boot-starter-jdbc 77 | 78 | 79 | org.apache.tomcat 80 | tomcat-jdbc 81 | 82 | 83 | 84 | 85 | com.alibaba 86 | druid 87 | 1.1.6 88 | 89 | 90 | org.mybatis.spring.boot 91 | mybatis-spring-boot-starter 92 | 1.3.1 93 | 94 | 95 | org.postgresql 96 | postgresql 97 | 42.1.4 98 | 99 | 100 | -------------------------------------------------------------------------------- /flycache-core/src/main/java/io/github/flylib/flycache/FlycacheCoreApp.java: -------------------------------------------------------------------------------- 1 | package io.github.flylib.flycache; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author liushaoming 8 | * @Package io.github.flylib.flycache 9 | * @Description: 10 | * @date 2018-1-19 9:53 11 | */ 12 | @SpringBootApplication 13 | public class FlycacheCoreApp { 14 | public static void main(String[] args){ 15 | SpringApplication.run(FlycacheCoreApp.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /flycache-core/src/main/java/io/github/flylib/flycache/config/Config.java: -------------------------------------------------------------------------------- 1 | package io.github.flylib.flycache.config; 2 | 3 | import com.alibaba.druid.pool.DruidDataSource; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.core.env.Environment; 8 | 9 | import javax.sql.DataSource; 10 | 11 | /** 12 | * @author liushaoming 13 | * @Package io.github.flylib.flycache.config 14 | * @Description: 15 | * @date 2018-1-23 14:34 16 | */ 17 | @Configuration 18 | public class Config { 19 | @Autowired 20 | private Environment env; 21 | 22 | @Bean 23 | public DataSource dataSource() { 24 | DruidDataSource dataSource = new DruidDataSource(); 25 | dataSource.setUrl(env.getProperty("spring.datasource.url")); 26 | dataSource.setUsername(env.getProperty("spring.datasource.username"));//用户名 27 | dataSource.setPassword(env.getProperty("spring.datasource.password"));//密码 28 | dataSource.setInitialSize(2); 29 | dataSource.setMaxActive(20); 30 | dataSource.setMinIdle(0); 31 | dataSource.setMaxWait(60000); 32 | dataSource.setValidationQuery("SELECT 1"); 33 | dataSource.setTestOnBorrow(false); 34 | dataSource.setTestWhileIdle(true); 35 | dataSource.setPoolPreparedStatements(false); 36 | return dataSource; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /flycache-core/src/main/java/io/github/flylib/flycache/config/MyBatisConfig.java: -------------------------------------------------------------------------------- 1 | package io.github.flylib.flycache.config; 2 | 3 | import org.apache.ibatis.session.SqlSessionFactory; 4 | import org.mybatis.spring.SqlSessionFactoryBean; 5 | import org.mybatis.spring.SqlSessionTemplate; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.jdbc.datasource.DataSourceTransactionManager; 10 | import org.springframework.transaction.PlatformTransactionManager; 11 | import org.springframework.transaction.annotation.EnableTransactionManagement; 12 | import org.springframework.transaction.annotation.TransactionManagementConfigurer; 13 | 14 | import javax.sql.DataSource; 15 | 16 | /** 17 | * @author liushaoming 18 | * @Package io.github.flylib.flycache.config 19 | * @Description: 20 | * @date 2018-1-23 16:48 21 | */ 22 | @Configuration 23 | //加上这个注解,使得支持事务 24 | @EnableTransactionManagement 25 | public class MyBatisConfig implements TransactionManagementConfigurer { 26 | @Autowired 27 | private DataSource dataSource; 28 | 29 | @Override 30 | public PlatformTransactionManager annotationDrivenTransactionManager() { 31 | return new DataSourceTransactionManager(dataSource); 32 | } 33 | 34 | @Bean(name = "sqlSessionFactory") 35 | public SqlSessionFactory sqlSessionFactoryBean() { 36 | SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); 37 | bean.setDataSource(dataSource); 38 | 39 | try { 40 | return bean.getObject(); 41 | } catch (Exception e) { 42 | e.printStackTrace(); 43 | throw new RuntimeException(e); 44 | } 45 | } 46 | 47 | @Bean 48 | public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { 49 | return new SqlSessionTemplate(sqlSessionFactory); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /flycache-core/src/main/java/io/github/flylib/flycache/config/MyBatisMapperScannerConfig.java: -------------------------------------------------------------------------------- 1 | package io.github.flylib.flycache.config; 2 | 3 | import org.mybatis.spring.mapper.MapperScannerConfigurer; 4 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | /** 9 | * @author liushaoming 10 | * @Package io.github.flylib.flycache.config 11 | * @Description: 12 | * @date 2018-1-23 16:51 13 | * 14 | * 扫描mybatis的接口 15 | */ 16 | @Configuration 17 | // 因为这个对象的扫描,需要在MyBatisConfig的后面注入,所以加上下面的注解 18 | @AutoConfigureAfter(MyBatisConfig.class) 19 | public class MyBatisMapperScannerConfig { 20 | @Bean 21 | public MapperScannerConfigurer mapperScannerConfigurer() { 22 | MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer(); 23 | //获取之前注入的beanName为sqlSessionFactory的对象 24 | mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory"); 25 | //指定xml配置文件的路径 26 | // mapperScannerConfigurer.setBasePackage("com.framework.msg.mapper"); 27 | mapperScannerConfigurer.setBasePackage("io.github.flylib.flycache.repository"); 28 | return mapperScannerConfigurer; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /flycache-core/src/main/java/io/github/flylib/flycache/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package io.github.flylib.flycache.controller; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.JSONArray; 5 | import io.github.flylib.flycache.entity.NodeGroupEntity; 6 | import io.github.flylib.flycache.redis.JedisPoolShardFactory; 7 | import io.github.flylib.flycache.redis.RedisClient; 8 | import io.github.flylib.flycache.service.NodeGroupService; 9 | import io.github.flylib.flycache.spring.AppContextHolder; 10 | import io.github.flylib.flycache.hash.Node; 11 | import io.github.flylib.flycache.util.ShardUtil; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.stereotype.Controller; 16 | import org.springframework.web.bind.annotation.RequestMapping; 17 | import org.springframework.web.bind.annotation.ResponseBody; 18 | import redis.clients.jedis.JedisPool; 19 | 20 | import java.util.List; 21 | 22 | /** 23 | * @author liushaoming 24 | * @Package io.github.flylib.flycache.controller 25 | * @Description: 26 | * @date 2018-1-19 9:55 27 | */ 28 | @Controller 29 | public class IndexController { 30 | private final Logger log = LoggerFactory.getLogger(IndexController.class); 31 | 32 | @Autowired 33 | private NodeGroupService nodeGroupService; 34 | 35 | @ResponseBody 36 | @RequestMapping("") 37 | public String demo() { 38 | return "demo response from flycache-core.-------"; 39 | } 40 | 41 | @ResponseBody 42 | @RequestMapping("testRedis") 43 | public String testRedis() { 44 | JedisPoolShardFactory jedisPoolShardFactory = AppContextHolder.getBean(JedisPoolShardFactory.class); 45 | Node node = new Node(); 46 | node.setHost("127.0.0.1"); 47 | node.setPort("6379"); 48 | node.setRemark(""); 49 | JedisPool jedisPool = jedisPoolShardFactory.getJedisPool(node); 50 | RedisClient redisClient = new RedisClient(); 51 | redisClient.setJedisPool(jedisPool); 52 | String key = "testCache"; 53 | redisClient.set(key, "mmmmmmm"); 54 | String value = redisClient.get(key); 55 | System.out.println(value); 56 | return value; 57 | } 58 | 59 | @ResponseBody 60 | @RequestMapping("test1") 61 | public String test1() { 62 | ShardUtil.initNodes(); 63 | return "test1 done"; 64 | } 65 | 66 | @ResponseBody 67 | @RequestMapping("nodeGroup") 68 | public String nodeGroup() { 69 | List entityList = nodeGroupService.all(); 70 | 71 | 72 | if (entityList != null && entityList.size() > 0) { 73 | for (NodeGroupEntity entity : entityList) { 74 | String jsonStr = entity.getNode(); 75 | List nodeList = JSON.parseArray(jsonStr, Node.class); 76 | log.info("nodeList={}", nodeList); 77 | } 78 | } 79 | 80 | String listStr = JSONArray.toJSONString(entityList); 81 | return listStr; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /flycache-core/src/main/java/io/github/flylib/flycache/entity/NodeGroupEntity.java: -------------------------------------------------------------------------------- 1 | package io.github.flylib.flycache.entity; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | /** 7 | * @author liushaoming 8 | * @Package io.github.flylib.flycache.entity 9 | * @Description: 10 | * @date 2018-1-23 17:08 11 | */ 12 | public class NodeGroupEntity { 13 | private String id; 14 | private String creater; 15 | private String node; 16 | private String time; 17 | 18 | public String getId() { 19 | return id; 20 | } 21 | 22 | public void setId(String id) { 23 | this.id = id; 24 | } 25 | 26 | public String getCreater() { 27 | return creater; 28 | } 29 | 30 | public void setCreater(String creater) { 31 | this.creater = creater; 32 | } 33 | 34 | public String getNode() { 35 | return node; 36 | } 37 | 38 | public void setNode(String node) { 39 | this.node = node; 40 | } 41 | 42 | public String getTime() { 43 | return time; 44 | } 45 | 46 | public void setTime(String time) { 47 | this.time = time; 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return "NodeGroupEntity{" + 53 | "id='" + id + '\'' + 54 | ", creater='" + creater + '\'' + 55 | ", node=" + node + 56 | ", time='" + time + '\'' + 57 | '}'; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /flycache-core/src/main/java/io/github/flylib/flycache/hash/ByteUtils.java: -------------------------------------------------------------------------------- 1 | package io.github.flylib.flycache.hash; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.nio.ByteBuffer; 5 | import java.nio.charset.Charset; 6 | 7 | 8 | /** 9 | * @author liushaoming 10 | *

11 | * Utilities for byte process 12 | */ 13 | public final class ByteUtils { 14 | public static final String DEFAULT_CHARSET_NAME = "utf-8"; 15 | public static final Charset DEFAULT_CHARSET = Charset 16 | .forName(DEFAULT_CHARSET_NAME); 17 | /** 18 | * if it is testing,check key argument even if use binary protocol. The user 19 | * must never change this value at all. 20 | */ 21 | public static boolean testing; 22 | 23 | private ByteUtils() { 24 | } 25 | 26 | public static boolean isNumber(String string) { 27 | if (string == null || string.isEmpty()) { 28 | return false; 29 | } 30 | int i = 0; 31 | if (string.charAt(0) == '-') { 32 | if (string.length() > 1) { 33 | i++; 34 | } else { 35 | return false; 36 | } 37 | } 38 | for (; i < string.length(); i++) { 39 | if (!Character.isDigit(string.charAt(i))) { 40 | return false; 41 | } 42 | } 43 | return true; 44 | } 45 | 46 | public static final byte[] getBytes(String k) { 47 | if (k == null || k.length() == 0) { 48 | throw new IllegalArgumentException("Key must not be blank"); 49 | } 50 | try { 51 | return k.getBytes(DEFAULT_CHARSET_NAME); 52 | } catch (UnsupportedEncodingException e) { 53 | throw new RuntimeException(e); 54 | } 55 | } 56 | 57 | 58 | private static int maxKeyLength = 250; 59 | 60 | 61 | public static final int normalizeCapacity(int requestedCapacity) { 62 | switch (requestedCapacity) { 63 | case 0: 64 | case 1 << 0: 65 | case 1 << 1: 66 | case 1 << 2: 67 | case 1 << 3: 68 | case 1 << 4: 69 | case 1 << 5: 70 | case 1 << 6: 71 | case 1 << 7: 72 | case 1 << 8: 73 | case 1 << 9: 74 | case 1 << 10: 75 | case 1 << 11: 76 | case 1 << 12: 77 | case 1 << 13: 78 | case 1 << 14: 79 | case 1 << 15: 80 | case 1 << 16: 81 | case 1 << 17: 82 | case 1 << 18: 83 | case 1 << 19: 84 | case 1 << 21: 85 | case 1 << 22: 86 | case 1 << 23: 87 | case 1 << 24: 88 | case 1 << 25: 89 | case 1 << 26: 90 | case 1 << 27: 91 | case 1 << 28: 92 | case 1 << 29: 93 | case 1 << 30: 94 | case Integer.MAX_VALUE: 95 | return requestedCapacity; 96 | } 97 | 98 | int newCapacity = 1; 99 | while (newCapacity < requestedCapacity) { 100 | newCapacity <<= 1; 101 | if (newCapacity < 0) { 102 | return Integer.MAX_VALUE; 103 | } 104 | } 105 | return newCapacity; 106 | } 107 | 108 | public static final boolean stepBuffer(ByteBuffer buffer, int remaining) { 109 | if (buffer.remaining() >= remaining) { 110 | buffer.position(buffer.position() + remaining); 111 | return true; 112 | } else { 113 | return false; 114 | } 115 | } 116 | 117 | public static String getString(byte[] bytes) { 118 | try { 119 | return new String(bytes, DEFAULT_CHARSET_NAME); 120 | } catch (UnsupportedEncodingException e) { 121 | throw new RuntimeException(e); 122 | } 123 | } 124 | 125 | public static void byte2hex(byte b, StringBuffer buf) { 126 | char[] hexChars = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 127 | 'A', 'B', 'C', 'D', 'E', 'F'}; 128 | int high = ((b & 0xf0) >> 4); 129 | int low = (b & 0x0f); 130 | buf.append(hexChars[high]); 131 | buf.append(hexChars[low]); 132 | } 133 | 134 | public static void int2hex(int a, StringBuffer str) { 135 | str.append(Integer.toHexString(a)); 136 | } 137 | 138 | public static void short2hex(int a, StringBuffer str) { 139 | str.append(Integer.toHexString(a)); 140 | } 141 | 142 | public static void getBytes(long i, int index, byte[] buf) { 143 | long q; 144 | int r; 145 | int pos = index; 146 | byte sign = 0; 147 | 148 | if (i < 0) { 149 | sign = '-'; 150 | i = -i; 151 | } 152 | 153 | // Get 2 digits/iteration using longs until quotient fits into an int 154 | while (i > Integer.MAX_VALUE) { 155 | q = i / 100; 156 | // really: r = i - (q * 100); 157 | r = (int) (i - ((q << 6) + (q << 5) + (q << 2))); 158 | i = q; 159 | buf[--pos] = DigitOnes[r]; 160 | buf[--pos] = DigitTens[r]; 161 | } 162 | 163 | // Get 2 digits/iteration using ints 164 | int q2; 165 | int i2 = (int) i; 166 | while (i2 >= 65536) { 167 | q2 = i2 / 100; 168 | // really: r = i2 - (q * 100); 169 | r = i2 - ((q2 << 6) + (q2 << 5) + (q2 << 2)); 170 | i2 = q2; 171 | buf[--pos] = DigitOnes[r]; 172 | buf[--pos] = DigitTens[r]; 173 | } 174 | 175 | // Fall thru to fast mode for smaller numbers 176 | // assert(i2 <= 65536, i2); 177 | for (; ; ) { 178 | q2 = (i2 * 52429) >>> (16 + 3); 179 | r = i2 - ((q2 << 3) + (q2 << 1)); // r = i2-(q2*10) ... 180 | buf[--pos] = digits[r]; 181 | i2 = q2; 182 | if (i2 == 0) 183 | break; 184 | } 185 | if (sign != 0) { 186 | buf[--pos] = sign; 187 | } 188 | } 189 | 190 | /** 191 | * Places characters representing the integer i into the character array 192 | * buf. The characters are placed into the buffer backwards starting with 193 | * the least significant digit at the specified index (exclusive), and 194 | * working backwards from there. 195 | *

196 | * Will fail if i == Integer.MIN_VALUE 197 | */ 198 | static void getBytes(int i, int index, byte[] buf) { 199 | int q, r; 200 | int pos = index; 201 | byte sign = 0; 202 | 203 | if (i < 0) { 204 | sign = '-'; 205 | i = -i; 206 | } 207 | 208 | // Generate two digits per iteration 209 | while (i >= 65536) { 210 | q = i / 100; 211 | // really: r = i - (q * 100); 212 | r = i - ((q << 6) + (q << 5) + (q << 2)); 213 | i = q; 214 | buf[--pos] = DigitOnes[r]; 215 | buf[--pos] = DigitTens[r]; 216 | } 217 | 218 | // Fall thru to fast mode for smaller numbers 219 | // assert(i <= 65536, i); 220 | for (; ; ) { 221 | q = (i * 52429) >>> (16 + 3); 222 | r = i - ((q << 3) + (q << 1)); // r = i-(q*10) ... 223 | buf[--pos] = digits[r]; 224 | i = q; 225 | if (i == 0) 226 | break; 227 | } 228 | if (sign != 0) { 229 | buf[--pos] = sign; 230 | } 231 | } 232 | 233 | /** 234 | * All possible chars for representing a number as a String 235 | */ 236 | final static byte[] digits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', 237 | '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 238 | 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 239 | 'z'}; 240 | 241 | final static byte[] DigitTens = {'0', '0', '0', '0', '0', '0', '0', '0', 242 | '0', '0', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '2', 243 | '2', '2', '2', '2', '2', '2', '2', '2', '2', '3', '3', '3', '3', 244 | '3', '3', '3', '3', '3', '3', '4', '4', '4', '4', '4', '4', '4', 245 | '4', '4', '4', '5', '5', '5', '5', '5', '5', '5', '5', '5', '5', 246 | '6', '6', '6', '6', '6', '6', '6', '6', '6', '6', '7', '7', '7', 247 | '7', '7', '7', '7', '7', '7', '7', '8', '8', '8', '8', '8', '8', 248 | '8', '8', '8', '8', '9', '9', '9', '9', '9', '9', '9', '9', '9', 249 | '9',}; 250 | 251 | final static byte[] DigitOnes = {'0', '1', '2', '3', '4', '5', '6', '7', 252 | '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 253 | '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', 254 | '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', 255 | '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 256 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', 257 | '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', 258 | '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', 259 | '9',}; 260 | 261 | final static int[] sizeTable = {9, 99, 999, 9999, 99999, 999999, 9999999, 262 | 99999999, 999999999, Integer.MAX_VALUE}; 263 | 264 | // Requires positive x 265 | public static final int stringSize(int x) { 266 | for (int i = 0; ; i++) 267 | if (x <= sizeTable[i]) 268 | return i + 1; 269 | } 270 | 271 | // Requires positive x 272 | public static final int stringSize(long x) { 273 | long p = 10; 274 | for (int i = 1; i < 19; i++) { 275 | if (x < p) 276 | return i; 277 | p = 10 * p; 278 | } 279 | return 19; 280 | } 281 | 282 | final static int[] byte_len_array = new int[256]; 283 | 284 | static { 285 | for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; ++i) { 286 | int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i); 287 | byte_len_array[i & 0xFF] = size; 288 | } 289 | } 290 | } -------------------------------------------------------------------------------- /flycache-core/src/main/java/io/github/flylib/flycache/hash/ConsistentHash.java: -------------------------------------------------------------------------------- 1 | package io.github.flylib.flycache.hash; 2 | 3 | import java.util.Set; 4 | import java.util.TreeMap; 5 | 6 | /** 7 | * @author liushaoming 8 | * 一致性hash的实现 9 | * Java implementation of consistent-hashing 10 | */ 11 | public class ConsistentHash { 12 | /** 13 | * Vitual node replicates count of node; 14 | */ 15 | private int virtualCount = DEFAULT_VIRTUAL_COUNT; //平均虚拟节点数 16 | 17 | private HashAlgorithm alg = HashAlgorithm.KETAMA_HASH;//采用的HASH算法 18 | 19 | private Set nodeSet; //节点列表 20 | 21 | private final TreeMap nodeMap = new TreeMap(); 22 | 23 | private static final int DEFAULT_VIRTUAL_COUNT = 5; 24 | 25 | private static class SingletonHolder { 26 | private static ConsistentHash instance = new ConsistentHash(); 27 | } 28 | 29 | private ConsistentHash() { 30 | } 31 | 32 | /** 33 | * Get singleton of ConsistentHash 34 | * 获取ConsistentHash的单例对象 35 | * 36 | * @return 37 | */ 38 | public static ConsistentHash getInstance() { 39 | return SingletonHolder.instance; 40 | } 41 | 42 | /** 43 | * 构建一致性HASH环 44 | */ 45 | public void buildHashCircle() { 46 | if (nodeSet == null) return; 47 | for (Node node : nodeSet) { 48 | for (int i = 0; i < virtualCount; i++) { 49 | long nodeKey = this.alg.hash(node.toString() + "-" + i); 50 | nodeMap.put(nodeKey, node); 51 | } 52 | } 53 | } 54 | 55 | /** 56 | * 沿环的顺时针找到虚拟节点 57 | * 58 | * @param key 59 | * @return 60 | */ 61 | public Node findNodeByKey(String key) { 62 | final Long hash = this.alg.hash(key); 63 | Long target = hash; 64 | if (!nodeMap.containsKey(hash)) { 65 | target = nodeMap.ceilingKey(hash); 66 | if (target == null && !nodeMap.isEmpty()) { 67 | target = nodeMap.firstKey(); 68 | } 69 | } 70 | return nodeMap.get(target); 71 | } 72 | 73 | /** 74 | * 设置每个节点的虚拟节点个数,该参数默认是100 75 | * 76 | * @param virtualCount 虚拟节点数 77 | */ 78 | public void setVirtualCount(int virtualCount) { 79 | this.virtualCount = virtualCount; 80 | } 81 | 82 | /** 83 | * 设置一致性HASH的算法,默认采用 KETAMA_HASH 84 | * 对于一致性HASH而言选择的HASH算法首先要考虑发散度其次再考虑性能 85 | * 86 | * @param alg 具体支持的算法 87 | * @see HashAlgorithm 88 | */ 89 | public void setAlg(HashAlgorithm alg) { 90 | this.alg = alg; 91 | } 92 | 93 | /** 94 | * 配置实际的节点,允许同一个IP上多个节点,但是应该用name区分开 95 | * 96 | * @param nodeList 节点列表 97 | */ 98 | public void setNodeSet(Set nodeList) { 99 | this.nodeSet = nodeList; 100 | } 101 | 102 | /** 103 | * 获取环形HASH 104 | * 105 | * @return 106 | */ 107 | public TreeMap getNodeMap() { 108 | return nodeMap; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /flycache-core/src/main/java/io/github/flylib/flycache/hash/HashAlgorithm.java: -------------------------------------------------------------------------------- 1 | package io.github.flylib.flycache.hash; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.nio.ByteBuffer; 5 | import java.nio.ByteOrder; 6 | import java.security.MessageDigest; 7 | import java.security.NoSuchAlgorithmException; 8 | import java.util.zip.CRC32; 9 | 10 | public enum HashAlgorithm { 11 | 12 | /** 13 | * Native hash (String.hashCode()). 14 | */ 15 | NATIVE_HASH, 16 | /** 17 | * CRC32_HASH as used by the perl API. This will be more consistent both 18 | * across multiple API users as well as java versions, but is mostly likely 19 | * significantly slower. 20 | */ 21 | CRC32_HASH, 22 | /** 23 | * FNV hashes are designed to be fast while maintaining a low collision 24 | * rate. The FNV speed allows one to quickly hash lots of data while 25 | * maintaining a reasonable collision rate. 26 | *

27 | * // * @see http://www.isthe.com/chongo/tech/comp/fnv/ 28 | * // * @see http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash 29 | */ 30 | FNV1_64_HASH, 31 | /** 32 | * Variation of FNV. 33 | */ 34 | FNV1A_64_HASH, 35 | /** 36 | * 32-bit FNV1. 37 | */ 38 | FNV1_32_HASH, 39 | /** 40 | * 32-bit FNV1a. 41 | */ 42 | FNV1A_32_HASH, 43 | /** 44 | * MD5-based hash algorithm used by ketama. 45 | */ 46 | KETAMA_HASH, 47 | 48 | /** 49 | * From mysql source 50 | */ 51 | MYSQL_HASH, 52 | 53 | ELF_HASH, 54 | 55 | RS_HASH, 56 | 57 | /** 58 | * From lua source,it is used for long key 59 | */ 60 | LUA_HASH, 61 | /** 62 | * MurMurHash算法,是非加密HASH算法,性能很高, 63 | * 比传统的CRC32,MD5,SHA-1(这两个算法都是加密HASH算法,复杂度本身就很高,带来的性能上的损害也不可避免) 64 | * 等HASH算法要快很多,这个算法的碰撞率很低. 65 | * http://murmurhash.googlepages.com/ 66 | */ 67 | MurMurHash, 68 | /** 69 | * The Jenkins One-at-a-time hash ,please see 70 | * http://www.burtleburtle.net/bob/hash/doobs.html 71 | */ 72 | ONE_AT_A_TIME; 73 | 74 | private static final long FNV_64_INIT = 0xcbf29ce484222325L; 75 | private static final long FNV_64_PRIME = 0x100000001b3L; 76 | 77 | private static final long FNV_32_INIT = 2166136261L; 78 | private static final long FNV_32_PRIME = 16777619; 79 | 80 | /** 81 | * Compute the hash for the given key. 82 | * 83 | * @return a positive integer hash 84 | */ 85 | public long hash(final String k) { 86 | long rv = 0; 87 | switch (this) { 88 | case NATIVE_HASH: 89 | rv = k.hashCode(); 90 | break; 91 | case CRC32_HASH: 92 | // return (crc32(shift) >> 16) & 0x7fff; 93 | CRC32 crc32 = new CRC32(); 94 | crc32.update(ByteUtils.getBytes(k)); 95 | rv = crc32.getValue() >> 16 & 0x7fff; 96 | break; 97 | case FNV1_64_HASH: { 98 | // Thanks to pierre@demartines.com for the pointer 99 | rv = FNV_64_INIT; 100 | int len = k.length(); 101 | for (int i = 0; i < len; i++) { 102 | rv *= FNV_64_PRIME; 103 | rv ^= k.charAt(i); 104 | } 105 | } 106 | break; 107 | case MurMurHash: 108 | ByteBuffer buf = ByteBuffer.wrap(k.getBytes()); 109 | int seed = 0x1234ABCD; 110 | 111 | ByteOrder byteOrder = buf.order(); 112 | buf.order(ByteOrder.LITTLE_ENDIAN); 113 | 114 | long m = 0xc6a4a7935bd1e995L; 115 | int r = 47; 116 | 117 | rv = seed ^ (buf.remaining() * m); 118 | 119 | long ky; 120 | while (buf.remaining() >= 8) { 121 | ky = buf.getLong(); 122 | 123 | ky *= m; 124 | ky ^= ky >>> r; 125 | ky *= m; 126 | 127 | rv ^= ky; 128 | rv *= m; 129 | } 130 | 131 | if (buf.remaining() > 0) { 132 | ByteBuffer finish = ByteBuffer.allocate(8).order( 133 | ByteOrder.LITTLE_ENDIAN); 134 | // for big-endian version, do this first: 135 | // finish.position(8-buf.remaining()); 136 | finish.put(buf).rewind(); 137 | rv ^= finish.getLong(); 138 | rv *= m; 139 | } 140 | 141 | rv ^= rv >>> r; 142 | rv *= m; 143 | rv ^= rv >>> r; 144 | buf.order(byteOrder); 145 | break; 146 | case FNV1A_64_HASH: { 147 | rv = FNV_64_INIT; 148 | int len = k.length(); 149 | for (int i = 0; i < len; i++) { 150 | rv ^= k.charAt(i); 151 | rv *= FNV_64_PRIME; 152 | } 153 | } 154 | break; 155 | case FNV1_32_HASH: { 156 | rv = FNV_32_INIT; 157 | int len = k.length(); 158 | for (int i = 0; i < len; i++) { 159 | rv *= FNV_32_PRIME; 160 | rv ^= k.charAt(i); 161 | } 162 | } 163 | break; 164 | case FNV1A_32_HASH: { 165 | rv = FNV_32_INIT; 166 | int len = k.length(); 167 | for (int i = 0; i < len; i++) { 168 | rv ^= k.charAt(i); 169 | rv *= FNV_32_PRIME; 170 | } 171 | } 172 | break; 173 | case KETAMA_HASH: 174 | byte[] bKey = computeMd5(k); 175 | rv = (long) (bKey[3] & 0xFF) << 24 | (long) (bKey[2] & 0xFF) << 16 176 | | (long) (bKey[1] & 0xFF) << 8 | bKey[0] & 0xFF; 177 | break; 178 | 179 | case MYSQL_HASH: 180 | int nr2 = 4; 181 | for (int i = 0; i < k.length(); i++) { 182 | rv ^= ((rv & 63) + nr2) * k.charAt(i) + (rv << 8); 183 | nr2 += 3; 184 | } 185 | break; 186 | case ELF_HASH: 187 | long x = 0; 188 | for (int i = 0; i < k.length(); i++) { 189 | rv = (rv << 4) + k.charAt(i); 190 | if ((x = rv & 0xF0000000L) != 0) { 191 | rv ^= x >> 24; 192 | rv &= ~x; 193 | } 194 | } 195 | rv = rv & 0x7FFFFFFF; 196 | break; 197 | case RS_HASH: 198 | long b = 378551; 199 | long a = 63689; 200 | for (int i = 0; i < k.length(); i++) { 201 | rv = rv * a + k.charAt(i); 202 | a *= b; 203 | } 204 | rv = rv & 0x7FFFFFFF; 205 | break; 206 | case LUA_HASH: 207 | int step = (k.length() >> 5) + 1; 208 | rv = k.length(); 209 | for (int len = k.length(); len >= step; len -= step) { 210 | rv = rv ^ (rv << 5) + (rv >> 2) + k.charAt(len - 1); 211 | } 212 | case ONE_AT_A_TIME: 213 | try { 214 | int hash = 0; 215 | for (byte bt : k.getBytes("utf-8")) { 216 | hash += (bt & 0xFF); 217 | hash += (hash << 10); 218 | hash ^= (hash >>> 6); 219 | } 220 | hash += (hash << 3); 221 | hash ^= (hash >>> 11); 222 | hash += (hash << 15); 223 | return hash; 224 | } catch (UnsupportedEncodingException e) { 225 | throw new IllegalStateException("Hash function error", e); 226 | } 227 | default: 228 | assert false; 229 | } 230 | 231 | return rv & 0xffffffffL; /* Truncate to 32-bits */ 232 | } 233 | 234 | /** 235 | * Get the md5 of the given key. 236 | */ 237 | public static byte[] computeMd5(String k) { 238 | MessageDigest md5; 239 | try { 240 | md5 = MessageDigest.getInstance("MD5"); 241 | } catch (NoSuchAlgorithmException e) { 242 | throw new RuntimeException("MD5 not supported", e); 243 | } 244 | md5.reset(); 245 | md5.update(ByteUtils.getBytes(k)); 246 | return md5.digest(); 247 | } 248 | 249 | // public static void main(String[] args) { 250 | // HashAlgorithm alg=HashAlgorithm.LUA_HASH; 251 | // long h=0; 252 | // long start=System.currentTimeMillis(); 253 | // for(int i=0;i<100000;i++) { 254 | // h=alg.hash("dddddd"); 255 | //// System.out.println(h); 256 | // } 257 | // System.out.println(System.currentTimeMillis()-start); 258 | // } 259 | } -------------------------------------------------------------------------------- /flycache-core/src/main/java/io/github/flylib/flycache/hash/Node.java: -------------------------------------------------------------------------------- 1 | package io.github.flylib.flycache.hash; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | /** 6 | * 节点的IP实现 7 | */ 8 | public class Node { 9 | private String host; 10 | private String port; 11 | private String remark; 12 | 13 | public Node() { 14 | this.port = "6379"; 15 | this.remark = ""; 16 | } 17 | 18 | public Node(String host, String port, String remark) { 19 | this(); 20 | this.host = host; 21 | this.port = port; 22 | this.remark = remark; 23 | } 24 | 25 | public String getHost() { 26 | return host; 27 | } 28 | 29 | public void setHost(String host) { 30 | this.host = host; 31 | } 32 | 33 | public String getPort() { 34 | return port; 35 | } 36 | 37 | public void setPort(String port) { 38 | this.port = port; 39 | } 40 | 41 | public String getRemark() { 42 | return remark; 43 | } 44 | 45 | public void setRemark(String remark) { 46 | this.remark = remark; 47 | } 48 | 49 | @Override 50 | public String toString() { 51 | return host + ":" + port + "_" + remark; 52 | } 53 | 54 | @Override 55 | public boolean equals(Object o) { 56 | if (o == null) { 57 | return false; 58 | } 59 | Node nodeObj = (Node) o; 60 | if (StringUtils.isNotEmpty(host) && StringUtils.isNotEmpty(remark) && StringUtils.isNotEmpty(port)) { 61 | return host.equals(nodeObj.getHost()) && remark.equals(nodeObj.getRemark()) && port.equals(nodeObj.getPort()); 62 | } 63 | 64 | return this.toString().equals(nodeObj.toString()); 65 | } 66 | 67 | @Override 68 | public int hashCode() { 69 | int result = host != null ? host.hashCode() : 0; 70 | result = 31 * result + (port != null ? port.hashCode() : 0); 71 | result = 31 * result + (remark != null ? remark.hashCode() : 0); 72 | return result; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /flycache-core/src/main/java/io/github/flylib/flycache/postgre/JSONTypeHandler.java: -------------------------------------------------------------------------------- 1 | package io.github.flylib.flycache.postgre; 2 | 3 | import org.apache.ibatis.type.BaseTypeHandler; 4 | import org.apache.ibatis.type.JdbcType; 5 | import org.apache.ibatis.type.MappedJdbcTypes; 6 | import org.apache.ibatis.type.MappedTypes; 7 | import org.postgresql.util.PGobject; 8 | 9 | import java.sql.CallableStatement; 10 | import java.sql.PreparedStatement; 11 | import java.sql.ResultSet; 12 | import java.sql.SQLException; 13 | 14 | /** 15 | * @author liushaoming 16 | * @Package io.github.flylib.flycache.postgre 17 | * @Description: 18 | * @date 2018-1-23 17:35 19 | */ 20 | @MappedJdbcTypes(JdbcType.OTHER) // 可有可无 21 | @MappedTypes(Object.class) 22 | public class JSONTypeHandler extends BaseTypeHandler { 23 | private static final PGobject jsonObject = new PGobject(); 24 | @Override 25 | public void setNonNullParameter(PreparedStatement ps, int i, Object parameter, JdbcType jdbcType) throws SQLException { 26 | jsonObject.setType("jsonb"); 27 | jsonObject.setValue(parameter.toString()); 28 | ps.setObject(i, jsonObject); 29 | } 30 | 31 | @Override 32 | public Object getNullableResult(ResultSet rs, int columnIndex) throws SQLException { 33 | return rs.getString(columnIndex); 34 | } 35 | 36 | @Override 37 | public Object getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { 38 | return cs.getString(columnIndex); 39 | } 40 | 41 | @Override 42 | public Object getNullableResult(ResultSet rs, String columnName) throws SQLException { 43 | return rs.getString(columnName); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /flycache-core/src/main/java/io/github/flylib/flycache/redis/JedisPoolShardFactory.java: -------------------------------------------------------------------------------- 1 | package io.github.flylib.flycache.redis; 2 | 3 | import io.github.flylib.flycache.hash.Node; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Component; 6 | import redis.clients.jedis.JedisPool; 7 | import redis.clients.jedis.JedisPoolConfig; 8 | 9 | import java.util.Set; 10 | 11 | /** 12 | * @author liushaoming 13 | * @Package io.github.flylib.flycache.redis 14 | * @Description: 15 | * @date 2018-1-19 11:12 16 | */ 17 | @Component 18 | public class JedisPoolShardFactory { 19 | @Autowired 20 | private JedisPoolConfig poolConfig; 21 | @Autowired 22 | private JedisSettings jedisSettings; 23 | 24 | public JedisPool getJedisPool(Node node) { 25 | 26 | int timeout = jedisSettings.getTimeout(); 27 | int database = jedisSettings.getDb(); 28 | JedisPool jedisPool = new JedisPool(poolConfig, node.getHost(), new Integer(node.getPort()), timeout, (String)null, database, (String)null); 29 | 30 | return jedisPool; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /flycache-core/src/main/java/io/github/flylib/flycache/redis/JedisSettings.java: -------------------------------------------------------------------------------- 1 | package io.github.flylib.flycache.redis; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * @author liushaoming 9 | * @Package io.github.flylib.flycache.redis 10 | * @Description: 11 | * @date 2018-1-19 11:43 12 | */ 13 | @Configuration 14 | public class JedisSettings { 15 | @Value("${redis.timeout}") 16 | private int timeout; 17 | 18 | @Value("${redis.password}") 19 | private String password; 20 | 21 | @Value("${redis.db}") 22 | private int db; 23 | 24 | public int getTimeout() { 25 | return timeout; 26 | } 27 | 28 | public void setTimeout(int timeout) { 29 | this.timeout = timeout; 30 | } 31 | 32 | public String getPassword() { 33 | return password; 34 | } 35 | 36 | public void setPassword(String password) { 37 | this.password = password; 38 | } 39 | 40 | public int getDb() { 41 | return db; 42 | } 43 | 44 | public void setDb(int db) { 45 | this.db = db; 46 | } 47 | 48 | @Bean 49 | public JedisSettings newJedisSettings(){ 50 | JedisSettings jedisSettings=new JedisSettings(); 51 | jedisSettings.setTimeout(timeout); 52 | jedisSettings.setPassword(password); 53 | jedisSettings.setDb(db); 54 | return jedisSettings; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /flycache-core/src/main/java/io/github/flylib/flycache/redis/MyJedisPoolConfig.java: -------------------------------------------------------------------------------- 1 | package io.github.flylib.flycache.redis; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import redis.clients.jedis.JedisPoolConfig; 7 | 8 | /** 9 | * @author liushaoming 10 | * @Package io.github.flylib.flycache.redis 11 | * @Description: 12 | * @date 2018-1-19 11:33 13 | */ 14 | @Configuration 15 | public class MyJedisPoolConfig { 16 | @Value("${redisPool.maxIdle}") 17 | private int maxIdle; 18 | 19 | @Value("${redisPool.maxTotal}") 20 | private int maxTotal; 21 | 22 | @Value("${redisPool.testOnBorrow}") 23 | private boolean testOnBorrow; 24 | 25 | public int getMaxIdle() { 26 | return maxIdle; 27 | } 28 | 29 | public void setMaxIdle(int maxIdle) { 30 | this.maxIdle = maxIdle; 31 | } 32 | 33 | public int getMaxTotal() { 34 | return maxTotal; 35 | } 36 | 37 | public void setMaxTotal(int maxTotal) { 38 | this.maxTotal = maxTotal; 39 | } 40 | 41 | public boolean isTestOnBorrow() { 42 | return testOnBorrow; 43 | } 44 | 45 | public void setTestOnBorrow(boolean testOnBorrow) { 46 | this.testOnBorrow = testOnBorrow; 47 | } 48 | 49 | @Bean 50 | public JedisPoolConfig newJedisPoolConfig() { 51 | JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); 52 | jedisPoolConfig.setMaxIdle(maxIdle); 53 | jedisPoolConfig.setMaxTotal(maxTotal); 54 | jedisPoolConfig.setTestOnBorrow(testOnBorrow); 55 | return jedisPoolConfig; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /flycache-core/src/main/java/io/github/flylib/flycache/redis/RedisClient.java: -------------------------------------------------------------------------------- 1 | package io.github.flylib.flycache.redis; 2 | 3 | import java.util.Map; 4 | import java.util.Set; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.InitializingBean; 9 | 10 | import redis.clients.jedis.Jedis; 11 | import redis.clients.jedis.JedisPool; 12 | 13 | /** 14 | * @author liushaoming 15 | * @Package io.github.flylib.flycache.redis 16 | * @Description: 17 | * @date 2018-1-19 10:18 18 | */ 19 | public class RedisClient { 20 | private Logger logger = LoggerFactory.getLogger(RedisClient.class); 21 | private JedisPool jedisPool; 22 | 23 | public RedisClient() { 24 | 25 | } 26 | 27 | public RedisClient(JedisPool jedisPool) { 28 | this.jedisPool = jedisPool; 29 | } 30 | 31 | public JedisPool getJedisPool() { 32 | return jedisPool; 33 | } 34 | 35 | public void setJedisPool(JedisPool jedisPool) { 36 | this.jedisPool = jedisPool; 37 | } 38 | 39 | /** 40 | * 41 | * @param jedis 42 | */ 43 | private static void closeJedis(Jedis jedis) { 44 | if (jedis != null) { 45 | jedis.close(); 46 | } 47 | } 48 | 49 | public String flushDB() { 50 | Jedis jedis = null; 51 | String result = null; 52 | try { 53 | jedis = jedisPool.getResource(); 54 | result = jedis.flushDB(); 55 | } catch (Exception e) { 56 | e.printStackTrace(); 57 | } finally { 58 | closeJedis(jedis); 59 | } 60 | return result; 61 | } 62 | 63 | /** 64 | *

65 | * 通过key获取储存在redis中的value 66 | *

67 | *

68 | * 并释放连接 69 | *

70 | * 71 | * @param key 72 | * @return 成功返回value 失败返回null 73 | */ 74 | public String get(String key) { 75 | Jedis jedis = null; 76 | String value = null; 77 | try { 78 | jedis = jedisPool.getResource(); 79 | value = jedis.get(key); 80 | } catch (Exception e) { 81 | e.printStackTrace(); 82 | } finally { 83 | closeJedis(jedis); 84 | } 85 | return value; 86 | } 87 | 88 | /** 89 | *

90 | * 向redis存入key和value,并释放连接资源 91 | *

92 | *

93 | * 如果key已经存在 则覆盖 94 | *

95 | * 96 | * @param key 97 | * @param value 98 | * @return 成功 返回OK 失败返回 0 99 | */ 100 | public String set(String key, String value) { 101 | Jedis jedis = null; 102 | try { 103 | jedis = jedisPool.getResource(); 104 | return jedis.set(key, value); 105 | } catch (Exception e) { 106 | e.printStackTrace(); 107 | return "0"; 108 | } finally { 109 | closeJedis(jedis); 110 | } 111 | } 112 | 113 | /** 114 | *

115 | * 返回满足pattern表达式的所有key 116 | *

117 | *

118 | * keys(*) 119 | *

120 | *

121 | * 返回所有的key 122 | *

123 | * 124 | * @param pattern 125 | * @return 126 | */ 127 | public Set keys(String pattern) { 128 | Jedis jedis = null; 129 | Set res = null; 130 | try { 131 | jedis = jedisPool.getResource(); 132 | res = jedis.keys(pattern); 133 | } catch (Exception e) { 134 | e.printStackTrace(); 135 | } finally { 136 | closeJedis(jedis); 137 | } 138 | return res; 139 | } 140 | 141 | /** 142 | *

143 | * 删除指定的key,也可以传入一个包含key的数组 144 | *

145 | * 146 | * @param keys 一个key 也可以使 string 数组 147 | * @return 返回删除成功的个数 148 | */ 149 | public Long del(String... keys) { 150 | Jedis jedis = null; 151 | try { 152 | jedis = jedisPool.getResource(); 153 | return jedis.del(keys); 154 | } catch (Exception e) { 155 | e.printStackTrace(); 156 | return 0L; 157 | } finally { 158 | closeJedis(jedis); 159 | } 160 | } 161 | 162 | /** 163 | *

164 | * 通过key 和 field 获取指定的 value 165 | *

166 | * 167 | * @param key 168 | * @param field 169 | * @return 没有返回null 170 | */ 171 | public String hget(String key, String field) { 172 | Jedis jedis = null; 173 | String res = null; 174 | try { 175 | jedis = jedisPool.getResource(); 176 | res = jedis.hget(key, field); 177 | } catch (Exception e) { 178 | e.printStackTrace(); 179 | } finally { 180 | closeJedis(jedis); 181 | } 182 | return res; 183 | } 184 | 185 | /** 186 | *

187 | * 通过key获取所有的field和value 188 | *

189 | * 190 | * @param key 191 | * @return 192 | */ 193 | public Map hgetAll(String key) { 194 | Jedis jedis = null; 195 | Map res = null; 196 | try { 197 | jedis = jedisPool.getResource(); 198 | res = jedis.hgetAll(key); 199 | } catch (Exception e) { 200 | e.printStackTrace(); 201 | } finally { 202 | closeJedis(jedis); 203 | } 204 | return res; 205 | } 206 | 207 | /** 208 | *

209 | * 通过key 删除指定的 field 210 | *

211 | * 212 | * @param key 213 | * @param fields 可以是 一个 field 也可以是 一个数组 214 | * @return 215 | */ 216 | public Long hdel(String key, String... fields) { 217 | Jedis jedis = null; 218 | Long res = null; 219 | try { 220 | jedis = jedisPool.getResource(); 221 | res = jedis.hdel(key, fields); 222 | } catch (Exception e) { 223 | e.printStackTrace(); 224 | } finally { 225 | closeJedis(jedis); 226 | } 227 | return res; 228 | } 229 | 230 | /** 231 | *

232 | * 通过key给field设置指定的值,如果key不存在,则先创建 233 | *

234 | * 235 | * @param key 236 | * @param field 字段 237 | * @param value 238 | * @return 如果存在返回0 异常返回null 239 | */ 240 | public Long hset(String key, String field, String value) { 241 | Jedis jedis = null; 242 | Long res = null; 243 | try { 244 | jedis = jedisPool.getResource(); 245 | res = jedis.hset(key, field, value); 246 | } catch (Exception e) { 247 | e.printStackTrace(); 248 | } finally { 249 | closeJedis(jedis); 250 | } 251 | return res; 252 | } 253 | } -------------------------------------------------------------------------------- /flycache-core/src/main/java/io/github/flylib/flycache/repository/NodeRepositery.java: -------------------------------------------------------------------------------- 1 | package io.github.flylib.flycache.repository; 2 | 3 | import io.github.flylib.flycache.entity.NodeGroupEntity; 4 | import io.github.flylib.flycache.postgre.JSONTypeHandler; 5 | import org.apache.ibatis.annotations.*; 6 | import org.apache.ibatis.type.JdbcType; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author liushaoming 12 | * @Package io.github.flylib.flycache.repository 13 | * @Description: 14 | * @date 2018-1-23 15:07 15 | */ 16 | @Mapper 17 | 18 | public interface NodeRepositery { 19 | // @Select("select * from node_group;") 20 | // @Results({ 21 | // @Result(id = true, property = "id", column = "id"), 22 | // @Result(property = "creater", column = "creater"), 23 | // @Result(property = "node", column = "node", javaType = Object.class, jdbcType = JdbcType.OTHER, 24 | // typeHandler = JSONTypeHandler.class), 25 | // @Result(property = "time", column = "time", javaType = String.class) 26 | // }) 27 | @Select("select * from node_group;") 28 | public List all(); 29 | } 30 | -------------------------------------------------------------------------------- /flycache-core/src/main/java/io/github/flylib/flycache/service/NodeGroupService.java: -------------------------------------------------------------------------------- 1 | package io.github.flylib.flycache.service; 2 | 3 | import io.github.flylib.flycache.entity.NodeGroupEntity; 4 | import io.github.flylib.flycache.repository.NodeRepositery; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author liushaoming 12 | * @Package io.github.flylib.flycache.service 13 | * @Description: 14 | * @date 2018-1-23 17:14 15 | */ 16 | @Service 17 | public class NodeGroupService { 18 | @Autowired 19 | private NodeRepositery nodeRepositery; 20 | 21 | public List all() { 22 | List entityList = nodeRepositery.all(); 23 | 24 | return entityList; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /flycache-core/src/main/java/io/github/flylib/flycache/spring/AppContextHolder.java: -------------------------------------------------------------------------------- 1 | package io.github.flylib.flycache.spring; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.ApplicationContextAware; 6 | import org.springframework.stereotype.Component; 7 | 8 | @Component 9 | public class AppContextHolder implements ApplicationContextAware { 10 | private static ApplicationContext applicationContext = null; 11 | 12 | @Override 13 | public void setApplicationContext(ApplicationContext arg0) throws BeansException { 14 | if (AppContextHolder.applicationContext == null) { 15 | AppContextHolder.applicationContext = arg0; 16 | } 17 | } 18 | 19 | // 获取applicationContext 20 | public static ApplicationContext getApplicationContext() { 21 | return applicationContext; 22 | } 23 | 24 | // 通过name获取 Bean. 25 | public static Object getBean(String name) { 26 | return getApplicationContext().getBean(name); 27 | } 28 | 29 | // 通过class获取Bean. 30 | public static T getBean(Class clazz) { 31 | return getApplicationContext().getBean(clazz); 32 | } 33 | 34 | // 通过name,以及Clazz返回指定的Bean 35 | public static T getBean(String name, Class clazz) { 36 | return getApplicationContext().getBean(name, clazz); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /flycache-core/src/main/java/io/github/flylib/flycache/util/ShardUtil.java: -------------------------------------------------------------------------------- 1 | package io.github.flylib.flycache.util; 2 | 3 | import io.github.flylib.flycache.hash.ConsistentHash; 4 | import io.github.flylib.flycache.hash.Node; 5 | import io.github.flylib.flycache.redis.JedisPoolShardFactory; 6 | import io.github.flylib.flycache.redis.RedisClient; 7 | import io.github.flylib.flycache.spring.AppContextHolder; 8 | import redis.clients.jedis.JedisPool; 9 | 10 | import java.util.HashSet; 11 | import java.util.Set; 12 | 13 | /** 14 | * @author liushaoming 15 | * @Package io.github.flylib.flycache.util 16 | * @Description: 17 | * @date 2018-1-22 18:09 18 | */ 19 | public class ShardUtil { 20 | public static void initNodes() { 21 | JedisPoolShardFactory jedisPoolShardFactory = AppContextHolder.getBean(JedisPoolShardFactory.class); 22 | 23 | Set nodeSet = new HashSet(); 24 | nodeSet.add(new Node("127.0.0.1", "6379", "")); 25 | nodeSet.add(new Node("127.0.0.1", "6380", "")); 26 | nodeSet.add(new Node("127.0.0.1", "6381", "")); 27 | resetAllRedis(nodeSet, jedisPoolShardFactory); 28 | ConsistentHash consistentHash = ConsistentHash.getInstance(); 29 | consistentHash.setVirtualCount(4); 30 | consistentHash.setNodeSet(nodeSet); 31 | consistentHash.buildHashCircle(); 32 | String namePrefix = "lsm-"; 33 | 34 | for (int index = 0; index < 300; index++) { 35 | String key = namePrefix + index; 36 | Node node = consistentHash.findNodeByKey(key); 37 | JedisPool jedisPool = jedisPoolShardFactory.getJedisPool(node); 38 | RedisClient redisClient = new RedisClient(); 39 | redisClient.setJedisPool(jedisPool); 40 | redisClient.set(key, "ValueOf---" + key); 41 | } 42 | } 43 | 44 | /** 45 | * Execute 'flushDB' on all Redis node in nodeSet 46 | * 在所有的Redis的当前db上执行"flushDB"操作 47 | * @param nodeSet 48 | * @param jedisPoolShardFactory 49 | */ 50 | private static void resetAllRedis(Set nodeSet, JedisPoolShardFactory jedisPoolShardFactory) { 51 | if (nodeSet != null && nodeSet.size() > 0) { 52 | for (Node node : nodeSet) { 53 | JedisPool jedisPool = jedisPoolShardFactory.getJedisPool(node); 54 | RedisClient redisClient = new RedisClient(jedisPool); 55 | redisClient.flushDB(); 56 | } 57 | } 58 | } 59 | 60 | // public static void main(String[] args) { 61 | // initNodes(); 62 | // } 63 | } 64 | -------------------------------------------------------------------------------- /flycache-core/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=20200 2 | spring.mvc.view.prefix=/WEB-INF/view/ 3 | spring.mvc.view.suffix=.jsp 4 | 5 | ## 6 | redisPool.maxIdle=300 7 | redisPool.maxTotal=6000 8 | redisPool.testOnBorrow=false 9 | 10 | # 11 | redis.host=localhost 12 | redis.port=6379 13 | redis.timeout=2000 14 | redis.password= 15 | redis.db=6 16 | 17 | # mysql -myBatis 18 | spring.datasource.driver-class-name=org.postgresql.Driver 19 | 20 | spring.datasource.url=jdbc:postgresql://localhost:5432/flycache?characterEncoding=utf-8 21 | spring.datasource.username=postgres 22 | spring.datasource.password=postgre1 23 | -------------------------------------------------------------------------------- /redPacket.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bootsrc/flycache/632bbd824f0a549f7703703b7d2a60016527f95a/redPacket.png -------------------------------------------------------------------------------- /wechat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bootsrc/flycache/632bbd824f0a549f7703703b7d2a60016527f95a/wechat.png --------------------------------------------------------------------------------