├── redis1
├── redis-check-aof.bat
├── start_server.bat
├── stop_cli.bat
├── client.bat
├── dump.rdb
├── redis_benchMark.bat
├── redis-cli.exe
├── redis-server.exe
├── redis-benchmark.exe
├── redis-check-aof.exe
├── redis-check-dump.exe
├── redis.config
├── start_redis_Centos.sh
├── sentinel.conf
└── readme.properties
├── redis2
├── redis-check-aof.bat
├── start_server.bat
├── stop_cli.bat
├── client.bat
├── dump.rdb
├── redis_benchMark.bat
├── redis-cli.exe
├── redis-server.exe
├── redis-benchmark.exe
├── redis-check-aof.exe
├── redis-check-dump.exe
├── redis.config
├── start_redis_Centos.sh
└── sentinel.conf
├── .gitignore
├── proto
└── protoFile.proto
├── README.md
├── src
├── main
│ └── java
│ │ ├── springJredisCache
│ │ ├── JRedisCacheException.java
│ │ ├── Serializations
│ │ │ ├── Serialization.java
│ │ │ ├── FstSer.java
│ │ │ ├── KryoThreadLocalSer.java
│ │ │ └── KryoPoolSer.java
│ │ ├── JCache.java
│ │ ├── JRedisBinaryPubSub.java
│ │ └── JRedisSerializationUtils.java
│ │ └── proto
│ │ ├── RoleVoOrBuilder.java
│ │ ├── ProtoFile.java
│ │ ├── Roleofferinfo.java
│ │ ├── TRoleEqu.java
│ │ └── RoleVo.java
└── test
│ └── java
│ └── testJRedis
│ ├── TestMessagePack.java
│ ├── TestPubSub.java
│ ├── Test.java
│ └── TestD_S.java
├── res
├── springConfig
│ ├── spring-context.xml
│ └── spring-jredis.xml
└── appConfig
│ ├── log4j.xml
│ └── jredis.properties
├── springJredisCache.iml
├── LICENSE
└── pom.xml
/redis1/redis-check-aof.bat:
--------------------------------------------------------------------------------
1 | redis-check-aof.exe
--------------------------------------------------------------------------------
/redis2/redis-check-aof.bat:
--------------------------------------------------------------------------------
1 | redis-check-aof.exe
--------------------------------------------------------------------------------
/redis1/start_server.bat:
--------------------------------------------------------------------------------
1 | redis-server.exe redis.conf
--------------------------------------------------------------------------------
/redis2/start_server.bat:
--------------------------------------------------------------------------------
1 | redis-server.exe redis.conf
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .gitignore support plugin (hsz.mobi)
--------------------------------------------------------------------------------
/redis1/stop_cli.bat:
--------------------------------------------------------------------------------
1 | redis-cli.exe -h 127.0.0.1 -p 9999 shutdown
--------------------------------------------------------------------------------
/redis2/stop_cli.bat:
--------------------------------------------------------------------------------
1 | redis-cli.exe -h 127.0.0.1 -p 10001 shutdown
--------------------------------------------------------------------------------
/redis1/client.bat:
--------------------------------------------------------------------------------
1 | redis-cli.exe -h 115.28.134.193 -p 8888
2 | @pause
--------------------------------------------------------------------------------
/redis2/client.bat:
--------------------------------------------------------------------------------
1 | redis-cli.exe -h 127.0.0.1 -p 10001
2 | @pause
--------------------------------------------------------------------------------
/redis1/dump.rdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenleijava/springJredisCache/HEAD/redis1/dump.rdb
--------------------------------------------------------------------------------
/redis1/redis_benchMark.bat:
--------------------------------------------------------------------------------
1 | redis-benchmark.exe -h 115.28.134.193 -p 8888 -n 10 -c 60
2 | @pause
--------------------------------------------------------------------------------
/redis2/dump.rdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenleijava/springJredisCache/HEAD/redis2/dump.rdb
--------------------------------------------------------------------------------
/redis2/redis_benchMark.bat:
--------------------------------------------------------------------------------
1 | redis-benchmark.exe -h 115.28.134.193 -p 8888 -n 10 -c 60
2 | @pause
--------------------------------------------------------------------------------
/redis1/redis-cli.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenleijava/springJredisCache/HEAD/redis1/redis-cli.exe
--------------------------------------------------------------------------------
/redis2/redis-cli.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenleijava/springJredisCache/HEAD/redis2/redis-cli.exe
--------------------------------------------------------------------------------
/redis1/redis-server.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenleijava/springJredisCache/HEAD/redis1/redis-server.exe
--------------------------------------------------------------------------------
/redis2/redis-server.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenleijava/springJredisCache/HEAD/redis2/redis-server.exe
--------------------------------------------------------------------------------
/redis1/redis-benchmark.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenleijava/springJredisCache/HEAD/redis1/redis-benchmark.exe
--------------------------------------------------------------------------------
/redis1/redis-check-aof.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenleijava/springJredisCache/HEAD/redis1/redis-check-aof.exe
--------------------------------------------------------------------------------
/redis2/redis-benchmark.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenleijava/springJredisCache/HEAD/redis2/redis-benchmark.exe
--------------------------------------------------------------------------------
/redis2/redis-check-aof.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenleijava/springJredisCache/HEAD/redis2/redis-check-aof.exe
--------------------------------------------------------------------------------
/redis1/redis-check-dump.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenleijava/springJredisCache/HEAD/redis1/redis-check-dump.exe
--------------------------------------------------------------------------------
/redis2/redis-check-dump.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/chenleijava/springJredisCache/HEAD/redis2/redis-check-dump.exe
--------------------------------------------------------------------------------
/proto/protoFile.proto:
--------------------------------------------------------------------------------
1 | package proto;
2 |
3 |
4 | option java_multiple_files = true;
5 |
6 |
7 | // 角色vo change!!!
8 | message RoleVo {
9 | required uint32 roleID = 1; //角色ID
10 | optional string roleName = 2; //角色名称
11 | optional uint32 roleSex = 3; //角色性别
12 |
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #基于jedis+spring的简易封装 redis缓存。
2 |
3 | #1.配置redis客户端操作以及spring,启动redis;
4 | #2.测试用例详见Test测试结果如下;
5 | 
6 |
7 | #序列化方案 :
8 | 1.jdk原生序列化方案;
9 | 2.基于kryo序列化方案 ;
10 | 3.基于 FST序列化方案 ;
11 | 4.基于 protobuffer序列化方案 ;
12 | 5.基于redis的订阅/发布方案;
13 | 6.基于messagePack序列化方案;
14 |
15 | #序列化测试性能对比 10w次序列化 反序列化:
16 | 
17 | #fst kryo都是不错的选择!
18 | #其中kyro默认采用了UsafeInput 和UsafeOutPut流 ,直接操作内存,提供更快的序列化方案
19 | #测试protobuffer相当的优秀 只是该序列化方案要在特定的环境中 且只适合pb内置的消息格式,
20 | #不适合大众化的javabean序列化 有局限性;
21 | #kyro是纯java中应该最快的,同fst相比 在10W次的序列化 反序列中测试相差30ms,
22 | #现有项目中使用Kyro序列化方案。
23 | #ps:该组件已经在某手机游戏服务器中得到了验证与应用 请放心使用!
--------------------------------------------------------------------------------
/src/main/java/springJredisCache/JRedisCacheException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. @石头哥哥
3 | * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 | */
5 |
6 | package springJredisCache;
7 |
8 | /**
9 | * JRedisCache 异常类
10 | */
11 | public class JRedisCacheException extends RuntimeException {
12 |
13 | private static final long serialVersionUID = -2282812710637100053L;
14 |
15 | public JRedisCacheException(String s) {
16 | super(s);
17 | }
18 |
19 | public JRedisCacheException(String s, Throwable e) {
20 | super(s, e);
21 | }
22 |
23 | public JRedisCacheException(Throwable e) {
24 | super(e);
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/springJredisCache/Serializations/Serialization.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. @石头哥哥
3 | * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 | */
5 |
6 | package springJredisCache.Serializations;
7 |
8 | /**
9 | * Created by chenlei on 14-10-4.
10 | * PROJECT_NAME: springJredisCache
11 | * PACKAGE_NAME: springJredisCache.Serializations
12 | */
13 | public interface Serialization {
14 |
15 |
16 | /**
17 | *
18 | * @param obj
19 | * @return
20 | */
21 | public byte[] ObjSerialize(Object obj);
22 |
23 | /**
24 | *
25 | * @param bytes
26 | * @return
27 | */
28 |
29 | public Object ObjDeserialize(byte[] bytes);
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/redis1/redis.config:
--------------------------------------------------------------------------------
1 | #是否作为守护进程运行
2 | daemonize yes
3 | #配置 pid 的存放路径及文件名,默认为当前路径下
4 | pidfile redis.pid
5 | #Redis 默认监听端口
6 | port 6379
7 | #客户端闲置多少秒后,断开连接
8 | timeout 300
9 | #日志显示级别
10 | loglevel verbose
11 | #指定日志输出的文件名,也可指定到标准输出端口
12 | logfile stdout
13 | #设置数据库的数量,默认连接的数据库是 0,可以通过 select N 来连接不同的数据库
14 | databases 16
15 | #保存数据到 disk 的策略
16 | #当有一条 Keys 数据被改变是,900 秒刷新到 disk 一次
17 | save 900 1
18 | #当有 10 条 Keys 数据被改变时,300 秒刷新到 disk 一次
19 | save 300 10
20 | #当有 1w 条 keys 数据被改变时,60 秒刷新到 disk 一次
21 | save 60 10000
22 | #当 dump .rdb 数据库的时候是否压缩数据对象
23 | rdbcompression yes
24 | #dump 数据库的数据保存的文件名
25 | dbfilename dump.rdb
26 | #Redis 的工作目录
27 | dir /home/falcon/redis-2.0.0/
28 | ########### Replication #####################
29 | #Redis 的复制配置
30 | # slaveof
31 | # masterauth
32 | ############## SECURITY ###########
33 | # requirepass foobared
34 | ############### LIMITS ##############
35 | #最大客户端连接数
36 | # maxclients 128
37 | #最大内存使用率
38 | # maxmemory
39 | ########## APPEND ONLY MODE #########
40 | #是否开启日志功能
41 | appendonly no
42 | # 刷新日志到 disk 的规则
43 | # appendfsync always
44 | appendfsync everysec
45 | # appendfsync no
46 | ################ VIRTUAL MEMORY ###########
47 | #是否开启 VM 功能
48 | vm-enabled no
49 | # vm-enabled yes
50 | vm-swap-file logs/redis.swap
51 | vm-max-memory 0
52 | vm-page-size 32
53 | vm-pages 134217728
54 | vm-max-threads 4
55 | ############# ADVANCED CONFIG ###############
56 | glueoutputbuf yes
57 | hash-max-zipmap-entries 64
58 | hash-max-zipmap-value 512
59 | #是否重置 Hash 表
60 | activerehashing yes
--------------------------------------------------------------------------------
/redis2/redis.config:
--------------------------------------------------------------------------------
1 | #是否作为守护进程运行
2 | daemonize yes
3 | #配置 pid 的存放路径及文件名,默认为当前路径下
4 | pidfile redis.pid
5 | #Redis 默认监听端口
6 | port 6379
7 | #客户端闲置多少秒后,断开连接
8 | timeout 300
9 | #日志显示级别
10 | loglevel verbose
11 | #指定日志输出的文件名,也可指定到标准输出端口
12 | logfile stdout
13 | #设置数据库的数量,默认连接的数据库是 0,可以通过 select N 来连接不同的数据库
14 | databases 16
15 | #保存数据到 disk 的策略
16 | #当有一条 Keys 数据被改变是,900 秒刷新到 disk 一次
17 | save 900 1
18 | #当有 10 条 Keys 数据被改变时,300 秒刷新到 disk 一次
19 | save 300 10
20 | #当有 1w 条 keys 数据被改变时,60 秒刷新到 disk 一次
21 | save 60 10000
22 | #当 dump .rdb 数据库的时候是否压缩数据对象
23 | rdbcompression yes
24 | #dump 数据库的数据保存的文件名
25 | dbfilename dump.rdb
26 | #Redis 的工作目录
27 | dir /home/falcon/redis-2.0.0/
28 | ########### Replication #####################
29 | #Redis 的复制配置
30 | # slaveof
31 | # masterauth
32 | ############## SECURITY ###########
33 | # requirepass foobared
34 | ############### LIMITS ##############
35 | #最大客户端连接数
36 | # maxclients 128
37 | #最大内存使用率
38 | # maxmemory
39 | ########## APPEND ONLY MODE #########
40 | #是否开启日志功能
41 | appendonly no
42 | # 刷新日志到 disk 的规则
43 | # appendfsync always
44 | appendfsync everysec
45 | # appendfsync no
46 | ################ VIRTUAL MEMORY ###########
47 | #是否开启 VM 功能
48 | vm-enabled no
49 | # vm-enabled yes
50 | vm-swap-file logs/redis.swap
51 | vm-max-memory 0
52 | vm-page-size 32
53 | vm-pages 134217728
54 | vm-max-threads 4
55 | ############# ADVANCED CONFIG ###############
56 | glueoutputbuf yes
57 | hash-max-zipmap-entries 64
58 | hash-max-zipmap-value 512
59 | #是否重置 Hash 表
60 | activerehashing yes
--------------------------------------------------------------------------------
/res/springConfig/spring-context.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | file:res/appConfig/jredis.properties
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/main/java/proto/RoleVoOrBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. @石头哥哥
3 | * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 | */
5 |
6 | // Generated by the protocol buffer compiler. DO NOT EDIT!
7 | // source: protoFile.proto
8 |
9 | package proto;
10 |
11 | public interface RoleVoOrBuilder extends
12 | // @@protoc_insertion_point(interface_extends:proto.RoleVo)
13 | com.google.protobuf.MessageOrBuilder {
14 |
15 | /**
16 | * required uint32 roleID = 1;
17 | *
18 | *
19 | *角色ID
20 | *
21 | */
22 | boolean hasRoleID();
23 | /**
24 | * required uint32 roleID = 1;
25 | *
26 | *
27 | *角色ID
28 | *
29 | */
30 | int getRoleID();
31 |
32 | /**
33 | * optional string roleName = 2;
34 | *
35 | *
36 | *角色名称
37 | *
38 | */
39 | boolean hasRoleName();
40 | /**
41 | * optional string roleName = 2;
42 | *
43 | *
44 | *角色名称
45 | *
46 | */
47 | java.lang.String getRoleName();
48 | /**
49 | * optional string roleName = 2;
50 | *
51 | *
52 | *角色名称
53 | *
54 | */
55 | com.google.protobuf.ByteString
56 | getRoleNameBytes();
57 |
58 | /**
59 | * optional uint32 roleSex = 3;
60 | *
61 | *
62 | *角色性别
63 | *
64 | */
65 | boolean hasRoleSex();
66 | /**
67 | * optional uint32 roleSex = 3;
68 | *
69 | *
70 | *角色性别
71 | *
72 | */
73 | int getRoleSex();
74 | }
75 |
--------------------------------------------------------------------------------
/redis1/start_redis_Centos.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # redis - this script starts and stops the redis-server daemon
4 | #
5 | # chkconfig: - 85 15
6 | # description: Redis is a persistent key-value database
7 | # processname: redis-server
8 | # config: /etc/redis/redis.conf
9 | # config: /etc/sysconfig/redis
10 | # pidfile: /var/run/redis.pid
11 |
12 | # Source function library.
13 | . /etc/rc.d/init.d/functions
14 |
15 | # Source networking configuration.
16 | . /etc/sysconfig/network
17 |
18 | # Check that networking is up.
19 | [ "$NETWORKING" = "no" ] && exit 0
20 |
21 | redis="/usr/local/sbin/redis-server"
22 | prog=$(basename $redis)
23 |
24 | REDIS_CONF_FILE="/etc/redis/redis.conf"
25 |
26 | [ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redis
27 |
28 | lockfile=/var/lock/subsys/redis
29 |
30 | start() {
31 | [ -x $redis ] || exit 5
32 | [ -f $REDIS_CONF_FILE ] || exit 6
33 | echo -n $"Starting $prog: "
34 | daemon $redis $REDIS_CONF_FILE
35 | retval=$?
36 | echo
37 | [ $retval -eq 0 ] && touch $lockfile
38 | return $retval
39 | }
40 |
41 | stop() {
42 | echo -n $"Stopping $prog: "
43 | killproc $prog -QUIT
44 | retval=$?
45 | echo
46 | [ $retval -eq 0 ] && rm -f $lockfile
47 | return $retval
48 | }
49 |
50 | restart() {
51 | stop
52 | start
53 | }
54 |
55 | reload() {
56 | echo -n $"Reloading $prog: "
57 | killproc $redis -HUP
58 | RETVAL=$?
59 | echo
60 | }
61 |
62 | force_reload() {
63 | restart
64 | }
65 |
66 | rh_status() {
67 | status $prog
68 | }
69 |
70 | rh_status_q() {
71 | rh_status >/dev/null 2>&1
72 | }
73 |
74 | case "$1" in
75 | start)
76 | rh_status_q && exit 0
77 | $1
78 | ;;
79 | stop)
80 | rh_status_q || exit 0
81 | $1
82 | ;;
83 | restart|configtest)
84 | $1
85 | ;;
86 | reload)
87 | rh_status_q || exit 7
88 | $1
89 | ;;
90 | force-reload)
91 | force_reload
92 | ;;
93 | status)
94 | rh_status
95 | ;;
96 | condrestart|try-restart)
97 | rh_status_q || exit 0
98 | ;;
99 | *)
100 | echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
101 | exit 2
102 | esac
--------------------------------------------------------------------------------
/redis2/start_redis_Centos.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # redis - this script starts and stops the redis-server daemon
4 | #
5 | # chkconfig: - 85 15
6 | # description: Redis is a persistent key-value database
7 | # processname: redis-server
8 | # config: /etc/redis/redis.conf
9 | # config: /etc/sysconfig/redis
10 | # pidfile: /var/run/redis.pid
11 |
12 | # Source function library.
13 | . /etc/rc.d/init.d/functions
14 |
15 | # Source networking configuration.
16 | . /etc/sysconfig/network
17 |
18 | # Check that networking is up.
19 | [ "$NETWORKING" = "no" ] && exit 0
20 |
21 | redis="/usr/local/sbin/redis-server"
22 | prog=$(basename $redis)
23 |
24 | REDIS_CONF_FILE="/etc/redis/redis.conf"
25 |
26 | [ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redis
27 |
28 | lockfile=/var/lock/subsys/redis
29 |
30 | start() {
31 | [ -x $redis ] || exit 5
32 | [ -f $REDIS_CONF_FILE ] || exit 6
33 | echo -n $"Starting $prog: "
34 | daemon $redis $REDIS_CONF_FILE
35 | retval=$?
36 | echo
37 | [ $retval -eq 0 ] && touch $lockfile
38 | return $retval
39 | }
40 |
41 | stop() {
42 | echo -n $"Stopping $prog: "
43 | killproc $prog -QUIT
44 | retval=$?
45 | echo
46 | [ $retval -eq 0 ] && rm -f $lockfile
47 | return $retval
48 | }
49 |
50 | restart() {
51 | stop
52 | start
53 | }
54 |
55 | reload() {
56 | echo -n $"Reloading $prog: "
57 | killproc $redis -HUP
58 | RETVAL=$?
59 | echo
60 | }
61 |
62 | force_reload() {
63 | restart
64 | }
65 |
66 | rh_status() {
67 | status $prog
68 | }
69 |
70 | rh_status_q() {
71 | rh_status >/dev/null 2>&1
72 | }
73 |
74 | case "$1" in
75 | start)
76 | rh_status_q && exit 0
77 | $1
78 | ;;
79 | stop)
80 | rh_status_q || exit 0
81 | $1
82 | ;;
83 | restart|configtest)
84 | $1
85 | ;;
86 | reload)
87 | rh_status_q || exit 7
88 | $1
89 | ;;
90 | force-reload)
91 | force_reload
92 | ;;
93 | status)
94 | rh_status
95 | ;;
96 | condrestart|try-restart)
97 | rh_status_q || exit 0
98 | ;;
99 | *)
100 | echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
101 | exit 2
102 | esac
--------------------------------------------------------------------------------
/src/test/java/testJRedis/TestMessagePack.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. @石头哥哥
3 | * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 | */
5 |
6 | package testJRedis;
7 |
8 | import org.msgpack.MessagePack;
9 | import org.msgpack.template.Templates;
10 | import org.msgpack.type.Value;
11 | import org.msgpack.unpacker.Converter;
12 |
13 | import java.io.IOException;
14 | import java.util.ArrayList;
15 | import java.util.List;
16 |
17 | /**
18 | * @author 石头哥哥
19 | *
20 | * Date: 2014/9/4
21 | *
22 | * Time: 14:49
23 | *
24 | * Package: springJredisCache
25 | *
26 | *
27 | * 注解:
28 | */
29 | public class TestMessagePack {
30 |
31 |
32 | @org.junit.Test
33 | public void test() throws IOException {
34 |
35 | // Create serialize objects.
36 | List src = new ArrayList();
37 | src.add("msgpack");
38 | src.add("kumofs");
39 | src.add("viver");
40 |
41 | MessagePack msgpack = new MessagePack();
42 | // Serialize
43 | byte[] raw = msgpack.write(src);
44 |
45 | // Deserialize directly using a template
46 | List dst1 = msgpack.read(raw, Templates.tList(Templates.TString));
47 | System.out.println(dst1.get(0));
48 | System.out.println(dst1.get(1));
49 | System.out.println(dst1.get(2));
50 |
51 | // Or, Deserialze to Value then convert type.
52 | Value dynamic = msgpack.read(raw);
53 | List dst2 = new Converter(dynamic)
54 | .read(Templates.tList(Templates.TString));
55 | System.out.println(dst2.get(0));
56 | System.out.println(dst2.get(1));
57 | System.out.println(dst2.get(2));
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/res/appConfig/log4j.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/res/appConfig/jredis.properties:
--------------------------------------------------------------------------------
1 |
2 | #
3 | # Copyright (c) 2014. @\u77F3\u5934\u54E5\u54E5
4 | # THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5 | #
6 |
7 | jredis.master.ip=127.0.0.1
8 | jredis.master.port=10002
9 | jredis.master.timeout = 2000
10 |
11 |
12 |
13 |
14 | jredis.slave.ip=127.0.0.1
15 | jredis.slave.port=9999
16 | jredis.slave.timeout = 2000
17 |
18 |
19 |
20 |
21 |
22 |
23 | #\u6700\u5927\u5206\u914D\u7684\u5BF9\u8C61\u6570,\u5982\u679C\u8D4B\u503C\u4E3A-1\uFF0C\u5219\u8868\u793A\u4E0D\u9650\u5236\uFF1B
24 | #\u5982\u679Cpool\u5DF2\u7ECF\u5206\u914D\u4E86maxActive\u4E2ABinaryJedis\u5B9E\u4F8B\uFF0C\u5219\u6B64\u65F6pool\u7684\u72B6\u6001\u4E3Aexhausted(\u8017\u5C3D)\u3002
25 | #\u5355\u53F0\u670D\u52A1\u5668\u627F\u8F7D\u57283000\u5E76\u53D1\uFF0C\u90A3\u4E48\u9ED8\u8BA4\u6BCF\u4E2Asocket\u5206\u914D\u4E00\u4E2A\u8FDE\u63A5\u5BF9\u8C61
26 | jredis.pool.maxTotal=3000
27 | #\u6700\u5927\u80FD\u591F\u4FDD\u6301idel\u72B6\u6001\u7684\u5BF9\u8C61\u6570 \u63A7\u5236\u4E00\u4E2Apool\u6700\u591A\u6709\u591A\u5C11\u4E2A\u72B6\u6001\u4E3Aidle(\u7A7A\u95F2\u7684)\u7684BinaryJedis\u5B9E\u4F8B\u3002
28 | jredis.pool.maxIdle=1500
29 | #\u5F53\u6C60\u5185\u6CA1\u6709\u8FD4\u56DE\u5BF9\u8C61\u65F6\uFF0C\u6700\u5927\u7B49\u5F85\u65F6\u95F4
30 | #\u8868\u793A\u5F53borrow(\u5F15\u5165)\u4E00\u4E2ABinaryJedis\u5B9E\u4F8B\u65F6\uFF0C\u6700\u5927\u7684\u7B49\u5F85\u65F6\u95F4\uFF0C
31 | #\u5982\u679C\u8D85\u8FC7\u7B49\u5F85\u65F6\u95F4\uFF0C\u5219\u76F4\u63A5\u629B\u51FAJedisConnectionException\uFF1B\u5355\u4F4D \u6BEB\u79D2 = 3s
32 | jredis.pool.maxWaitMillis= -1
33 | #\u5F53\u8C03\u7528borrow Object\u65B9\u6CD5\u65F6\uFF0C\u662F\u5426\u8FDB\u884C\u6709\u6548\u6027\u68C0\u67E5
34 | #\u5728borrow\u4E00\u4E2ABinaryJedis\u5B9E\u4F8B\u65F6\uFF0C\u662F\u5426\u63D0\u524D\u8FDB\u884Cvalidate\u64CD\u4F5C\uFF1B
35 | #\u5982\u679C\u4E3Atrue\uFF0C\u5219\u5F97\u5230\u7684BinaryJedis\u5B9E\u4F8B\u5747\u662F\u53EF\u7528\u7684\uFF1B
36 | jredis.pool.testOnBorrow=true
37 | #\u5F53\u8C03\u7528return Object\u65B9\u6CD5\u65F6\uFF0C\u662F\u5426\u8FDB\u884C\u6709\u6548\u6027\u68C0\u67E5
38 | jredis.pool.testOnReturn=true
39 |
40 |
--------------------------------------------------------------------------------
/src/test/java/testJRedis/TestPubSub.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. @石头哥哥
3 | * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 | */
5 |
6 | package testJRedis;
7 |
8 | import org.apache.log4j.xml.DOMConfigurator;
9 | import org.junit.After;
10 | import org.junit.Before;
11 | import org.springframework.context.support.FileSystemXmlApplicationContext;
12 | import org.springframework.stereotype.Service;
13 | import redis.clients.util.SafeEncoder;
14 | import springJredisCache.JRedisCache;
15 |
16 | import javax.annotation.Resource;
17 |
18 | /**
19 | * @author 石头哥哥
20 | * springJredisCache
21 | * Date:2014/4/2
22 | * Time:15:03
23 | * Package:{@link testJRedis}
24 | * Comment:基于jedis的 发布 订阅 测试
25 | */
26 | @Service("testPubSub")
27 | @SuppressWarnings("unchecked")
28 | public class TestPubSub {
29 |
30 |
31 | @Resource
32 | private JRedisCache jRedisCache;
33 |
34 | private FileSystemXmlApplicationContext springContext;
35 |
36 | private TestPubSub testPubSub;
37 |
38 | @Before
39 | public void IntiRes() {
40 | DOMConfigurator.configure("res/appConfig/log4j.xml");
41 | System.setProperty("java.net.preferIPv4Stack", "true"); //Disable IPv6 in JVM
42 | springContext = new FileSystemXmlApplicationContext("res/springConfig/spring-context.xml");
43 | /**初始化spring容器*/
44 | testPubSub = (TestPubSub) springContext.getBean("testPubSub");
45 |
46 | }
47 |
48 | @org.junit.Test
49 | public void publish() {
50 | for (int num=0;num!=1000;++num ) {
51 | testPubSub.jRedisCache.publish("xxxxsss", "123".getBytes());
52 | testPubSub.jRedisCache.publish("fod_2", SafeEncoder.encode("456"));
53 | }
54 | }
55 |
56 | @org.junit.Test
57 | public void psubscribe() throws InterruptedException {
58 | //订阅 处理 指定的消息
59 | testPubSub.jRedisCache.psubscribe("xxx*", "fod_*");
60 | //testPubSub.jRedisCache.subscribe("xxxxsss", "fod_2");
61 | }
62 |
63 | @After
64 | public void closeApp() {
65 | springContext.close();
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/proto/ProtoFile.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. @石头哥哥
3 | * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 | */
5 |
6 | // Generated by the protocol buffer compiler. DO NOT EDIT!
7 | // source: protoFile.proto
8 |
9 | package proto;
10 |
11 | public final class ProtoFile {
12 | private ProtoFile() {}
13 | public static void registerAllExtensions(
14 | com.google.protobuf.ExtensionRegistry registry) {
15 | }
16 | static final com.google.protobuf.Descriptors.Descriptor
17 | internal_static_proto_RoleVo_descriptor;
18 | static
19 | com.google.protobuf.GeneratedMessage.FieldAccessorTable
20 | internal_static_proto_RoleVo_fieldAccessorTable;
21 |
22 | public static com.google.protobuf.Descriptors.FileDescriptor
23 | getDescriptor() {
24 | return descriptor;
25 | }
26 | private static com.google.protobuf.Descriptors.FileDescriptor
27 | descriptor;
28 | static {
29 | java.lang.String[] descriptorData = {
30 | "\n\017protoFile.proto\022\005proto\";\n\006RoleVo\022\016\n\006ro" +
31 | "leID\030\001 \002(\r\022\020\n\010roleName\030\002 \001(\t\022\017\n\007roleSex\030" +
32 | "\003 \001(\rB\002P\001"
33 | };
34 | com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
35 | new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() {
36 | public com.google.protobuf.ExtensionRegistry assignDescriptors(
37 | com.google.protobuf.Descriptors.FileDescriptor root) {
38 | descriptor = root;
39 | return null;
40 | }
41 | };
42 | com.google.protobuf.Descriptors.FileDescriptor
43 | .internalBuildGeneratedFileFrom(descriptorData,
44 | new com.google.protobuf.Descriptors.FileDescriptor[] {
45 | }, assigner);
46 | internal_static_proto_RoleVo_descriptor =
47 | getDescriptor().getMessageTypes().get(0);
48 | internal_static_proto_RoleVo_fieldAccessorTable = new
49 | com.google.protobuf.GeneratedMessage.FieldAccessorTable(
50 | internal_static_proto_RoleVo_descriptor,
51 | new java.lang.String[] { "RoleID", "RoleName", "RoleSex", });
52 | }
53 |
54 | // @@protoc_insertion_point(outer_class_scope)
55 | }
56 |
--------------------------------------------------------------------------------
/res/springConfig/spring-jredis.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/src/main/java/springJredisCache/Serializations/FstSer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. @石头哥哥
3 | * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 | */
5 |
6 | package springJredisCache.Serializations;
7 |
8 | import org.nustaq.serialization.FSTObjectInput;
9 | import org.nustaq.serialization.FSTObjectOutput;
10 | import springJredisCache.JRedisCacheException;
11 |
12 | import java.io.ByteArrayInputStream;
13 | import java.io.ByteArrayOutputStream;
14 | import java.io.IOException;
15 |
16 | /**
17 | * Created by chenlei on 14-10-4.
18 | * PROJECT_NAME: springJredisCache
19 | * PACKAGE_NAME: springJredisCache.Serializations
20 | * 基于fst的序列化方案
21 | */
22 | public class FstSer implements Serialization{
23 |
24 |
25 | /**
26 | * @param obj
27 | * @return
28 | */
29 | @Override
30 | public byte[] ObjSerialize(Object obj) {
31 | ByteArrayOutputStream byteArrayOutputStream = null;
32 | FSTObjectOutput out = null;
33 | try {
34 | // stream closed in the finally
35 | byteArrayOutputStream = new ByteArrayOutputStream(512);
36 | out = new FSTObjectOutput(byteArrayOutputStream); //32000 buffer size
37 | out.writeObject(obj);
38 | out.flush();
39 | return byteArrayOutputStream.toByteArray();
40 | } catch (IOException ex) {
41 | throw new JRedisCacheException(ex);
42 | } finally {
43 | try {
44 | obj = null;
45 | if (out != null) {
46 | out.close(); //call flush byte buffer
47 | out = null;
48 | }
49 | if (byteArrayOutputStream != null) {
50 |
51 | byteArrayOutputStream.close();
52 | byteArrayOutputStream = null;
53 | }
54 | } catch (IOException ex) {
55 | // ignore close exception
56 | }
57 | }
58 | }
59 |
60 | /**
61 | * @param bytes
62 | * @return
63 | */
64 | @Override
65 | public Object ObjDeserialize(byte[] bytes) {
66 | ByteArrayInputStream byteArrayInputStream = null;
67 | FSTObjectInput in = null;
68 | try {
69 | // stream closed in the finally
70 | byteArrayInputStream = new ByteArrayInputStream(bytes);
71 | in = new FSTObjectInput(byteArrayInputStream);
72 | return in.readObject();
73 | } catch (ClassNotFoundException ex) {
74 | throw new JRedisCacheException(ex);
75 | } catch (IOException ex) {
76 | throw new JRedisCacheException(ex);
77 | } finally {
78 | try {
79 | bytes = null;
80 | if (in != null) {
81 | in.close();
82 | in = null;
83 | }
84 | if (byteArrayInputStream != null) {
85 | byteArrayInputStream.close();
86 | byteArrayInputStream = null;
87 | }
88 | } catch (IOException ex) {
89 | // ignore close exception
90 | }
91 | }
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/src/main/java/springJredisCache/JCache.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. @石头哥哥
3 | * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 | */
5 |
6 | package springJredisCache;
7 |
8 | import javolution.util.FastMap;
9 | import javolution.util.FastTable;
10 |
11 | import java.io.Serializable;
12 | import java.util.ArrayList;
13 |
14 |
15 | /**
16 | * 增加订阅 发布接口
17 | */
18 | public interface JCache {
19 |
20 |
21 | /**
22 | * 发布 消息
23 | *
24 | * @param channel
25 | * @param message
26 | * @return
27 | */
28 | public Long publish(String channel, byte[] message);
29 |
30 | /**
31 | * 订阅指定的消息 订阅得到信息在BinaryJedisPubSub的onMessage(...)方法中进行处理
32 | *
33 | * @param channels
34 | */
35 | public void subscribe(String... channels);
36 |
37 | /**
38 | * 取消所有订阅的channel
39 | */
40 | public void unsubscribe();
41 |
42 | /**
43 | * 取消订阅的channel
44 | * @param channels
45 | */
46 | public void unsubscribe(String... channels);
47 |
48 | /**
49 | * 表达式的方式订阅
50 | * 使用模式匹配的方式设置要订阅的消息 订阅得到信息在BinaryJedisPubSub的onMessage(...)方法中进行处理
51 | *
52 | * @param patterns 订阅的消息类型
53 | */
54 | public void psubscribe(String... patterns);
55 |
56 | /**
57 | * 取消所有订阅的channel
58 | */
59 | public void punsubscribe();
60 |
61 | /**
62 | * 取消订阅的channel
63 | * @param patterns
64 | */
65 | public void punsubscribe(String... patterns);
66 |
67 |
68 | /**
69 | * @return
70 | */
71 | public String info();
72 |
73 |
74 | /**
75 | *
76 | * @param key
77 | * @param filed
78 | * @return
79 | */
80 | public ArrayList> getList(String key,String filed);
81 |
82 | /**
83 | *
84 | * @param key
85 | * @param filed
86 | * @param list
87 | * @return
88 | */
89 | public String putList(String key, String filed ,ArrayList> list);
90 |
91 |
92 | /**
93 | * @param key
94 | * @return
95 | * @
96 | */
97 | public ArrayList> getList(String key);
98 |
99 | /**
100 | * @param key
101 | * @param list
102 | */
103 | public String putList(String key, ArrayList> list);
104 |
105 | /**
106 | * Remove an item from the cache
107 | */
108 | public void removeList(String key);
109 |
110 |
111 | /**
112 | * @param key
113 | * @return
114 | */
115 | public FastTable> getFastTable(String key);
116 |
117 |
118 | /**
119 | * @param key
120 | * @param list
121 | */
122 | public void putFastTable(String key, FastTable> list);
123 |
124 | /**
125 | * @param key
126 | * @return
127 | * @
128 | */
129 | public FastMap, ?> getFastMap(String key);
130 |
131 | /**
132 | * Remove an item from the cache
133 | */
134 | public void removeFastMap(String key);
135 |
136 | /**
137 | * @param key
138 | * @param fastMap
139 | */
140 | public void putFastMap(String key, FastMap, ?> fastMap);
141 |
142 | /**
143 | * Get an item from the cache, nontransactionally
144 | *
145 | * @param key
146 | * @return the cached object or null
147 | * @throws JRedisCacheException
148 | */
149 | public Serializable getObject(String key);
150 |
151 | /**
152 | * Add an item to the cache, nontransactionally, with
153 | * failfast semantics
154 | *
155 | * @param key
156 | * @param value
157 | * @
158 | */
159 | public void putObject(String key, Serializable value);
160 |
161 | /**
162 | * Remove an item from the cache
163 | */
164 | public void removeObject(String key);
165 |
166 | /**
167 | * @return
168 | * @throws JRedisCacheException
169 | */
170 | public FastTable keys();
171 |
172 |
173 |
174 | public void destroy();
175 |
176 |
177 | /**
178 | * Queue
179 | *
180 | * @param key
181 | * @param value
182 | */
183 | public void addQueue(String key, Serializable value);
184 |
185 | /**
186 | * poll from queue
187 | *
188 | * @param key
189 | */
190 | public Serializable pollFromQueue(String key);
191 |
192 |
193 | /**
194 | * peek from queue
195 | *
196 | * @param key
197 | */
198 | public Serializable peekFromQueue(String key);
199 |
200 | }
201 |
--------------------------------------------------------------------------------
/springJredisCache.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | file://$MODULE_DIR$/res/springConfig/spring-jredis.xml
13 | file://$MODULE_DIR$/res/springConfig/spring-context.xml
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/src/main/java/springJredisCache/Serializations/KryoThreadLocalSer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. @石头哥哥
3 | * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 | */
5 |
6 | package springJredisCache.Serializations;
7 |
8 | import com.esotericsoftware.kryo.Kryo;
9 | import com.esotericsoftware.kryo.io.Input;
10 | import com.esotericsoftware.kryo.io.Output;
11 | import de.javakaffee.kryoserializers.*;
12 | import de.javakaffee.kryoserializers.cglib.CGLibProxySerializer;
13 |
14 | import java.lang.reflect.InvocationHandler;
15 | import java.util.Arrays;
16 | import java.util.Collections;
17 | import java.util.GregorianCalendar;
18 |
19 | /**
20 | * Created by chenlei on 14-10-3.
21 | */
22 |
23 | //Kryo is not thread safe. Each thread should have its own Kryo,
24 | // Input, and Output instances. Also, the byte[] Input uses
25 | // may be modified and then returned to its original state during deserialization,
26 | // so the same byte[] "should not be used concurrently in separate threads.
27 | public class KryoThreadLocalSer implements Serialization {
28 |
29 |
30 | private KryoThreadLocalSer() {
31 | }
32 |
33 | /**
34 | * a singleton of kryo thread local
35 | *
36 | * @return
37 | */
38 |
39 | public static KryoThreadLocalSer getInstance() {
40 | return Singleton.kryoThreadLocal;
41 | }
42 |
43 |
44 | /**
45 | * @param obj
46 | * @return
47 | */
48 | @Override
49 | public byte[] ObjSerialize(Object obj) {
50 | try {
51 | KryoHolder kryoHolder = kryoThreadLocal.get();
52 | kryoHolder.output.clear(); //clear Output -->每次调用的时候 重置
53 | kryoHolder.kryo.writeClassAndObject(kryoHolder.output, obj);
54 | return kryoHolder.output.toBytes();// 无法避免拷贝 ~~~
55 | } finally {
56 | obj = null;
57 | }
58 |
59 | }
60 |
61 | /**
62 | * @param bytes
63 | * @return
64 | */
65 | @Override
66 | public Object ObjDeserialize(byte[] bytes) {
67 | try {
68 | KryoHolder kryoHolder = kryoThreadLocal.get();
69 | kryoHolder.input.setBuffer(bytes, 0, bytes.length);//call it ,and then use input object ,discard any array
70 | return kryoHolder.kryo.readClassAndObject(kryoHolder.input);
71 | } finally {
72 | bytes = null; // for gc
73 | }
74 |
75 | }
76 |
77 |
78 | /**
79 | * creat a Singleton
80 | */
81 | private static class Singleton {
82 | private static final KryoThreadLocalSer kryoThreadLocal = new KryoThreadLocalSer();
83 | }
84 |
85 |
86 | private final ThreadLocal kryoThreadLocal = new ThreadLocal() {
87 | @Override
88 | protected KryoHolder initialValue() {
89 | return new KryoHolder(new Kryo());
90 | }
91 | };
92 |
93 |
94 | private class KryoHolder {
95 | private Kryo kryo;
96 | static final int BUFFER_SIZE = 1024;
97 | private Output output = new Output(BUFFER_SIZE, -1); //reuse
98 | private Input input = new Input();
99 |
100 | KryoHolder(Kryo kryo) {
101 | this.kryo = kryo;
102 | this.kryo.setReferences(false);
103 |
104 | // register
105 | this.kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer());
106 | this.kryo.register(Collections.EMPTY_LIST.getClass(), new CollectionsEmptyListSerializer());
107 | this.kryo.register(Collections.EMPTY_MAP.getClass(), new CollectionsEmptyMapSerializer());
108 | this.kryo.register(Collections.EMPTY_SET.getClass(), new CollectionsEmptySetSerializer());
109 | this.kryo.register(Collections.singletonList("").getClass(), new CollectionsSingletonListSerializer());
110 | this.kryo.register(Collections.singleton("").getClass(), new CollectionsSingletonSetSerializer());
111 | this.kryo.register(Collections.singletonMap("", "").getClass(), new CollectionsSingletonMapSerializer());
112 | this.kryo.register(GregorianCalendar.class, new GregorianCalendarSerializer());
113 | this.kryo.register(InvocationHandler.class, new JdkProxySerializer());
114 | // register CGLibProxySerializer, works in combination with the appropriate action in handleUnregisteredClass (see below)
115 | this.kryo.register(CGLibProxySerializer.CGLibProxyMarker.class, new CGLibProxySerializer());
116 | UnmodifiableCollectionsSerializer.registerSerializers(this.kryo);
117 | SynchronizedCollectionsSerializer.registerSerializers(this.kryo);
118 |
119 | }
120 |
121 | }
122 |
123 |
124 | }
125 |
--------------------------------------------------------------------------------
/src/main/java/springJredisCache/JRedisBinaryPubSub.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. @石头哥哥
3 | * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 | */
5 |
6 | package springJredisCache;
7 |
8 | import org.springframework.stereotype.Service;
9 | import redis.clients.jedis.BinaryJedisPubSub;
10 | import redis.clients.util.SafeEncoder;
11 |
12 | import java.util.concurrent.ExecutorService;
13 | import java.util.concurrent.Executors;
14 | import java.util.concurrent.ThreadFactory;
15 | import java.util.concurrent.atomic.AtomicInteger;
16 |
17 | /**
18 | * @author 石头哥哥
19 | * springJredisCache
20 | * Date:2014/4/2
21 | * Time:14:37
22 | * Package:{@link springJredisCache}
23 | * Comment: 处理订阅的消息
24 | * subsribe(一般模式设置频道)和psubsribe(使用模式匹配来设置频道)。不管是那种模式都可以设置个数不定的频道
25 | *
26 | *
27 | * 订阅的监听类 ,订阅某个事件
28 | */
29 | @Service
30 | public class JRedisBinaryPubSub extends BinaryJedisPubSub {
31 |
32 | // 处理订阅消息
33 | private static final ExecutorService handleSubscribe =
34 | Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()
35 | , new PriorityThreadFactory("@+订阅消息处理线程池+@", Thread.NORM_PRIORITY));
36 |
37 |
38 | /**
39 | * 处理订阅的消息
40 | *
41 | * @param channel
42 | * @param message
43 | */
44 | @Override
45 | public void onMessage(final byte[] channel, final byte[] message) {
46 | handleSubscribe.execute(new Runnable() {
47 | @Override
48 | public void run() {
49 | System.out.println(SafeEncoder.encode(channel) + "=" + SafeEncoder.encode(message));
50 | }
51 | });
52 | }
53 |
54 | /**
55 | * 处理按照 表达式的方式订阅的消息后的处理
56 | *
57 | * @param pattern 订阅匹配的 pattern
58 | * @param channel key
59 | * @param message value
60 | * hello*=hello_1=123
61 | *
62 | * 可以将相应的message反序列化为相应的数据类型
63 | */
64 | @Override
65 | public void onPMessage(final byte[] pattern, final byte[] channel, final byte[] message) {
66 | handleSubscribe.execute(new Runnable() {
67 | @Override
68 | public void run() {
69 | System.out.println(SafeEncoder.encode(pattern) + "=" + SafeEncoder.encode(channel) + "=" + SafeEncoder.encode(message));
70 | }
71 | });
72 | }
73 |
74 |
75 | /**
76 | * 取消订阅(注销)
77 | *
78 | * @param channel key
79 | * @param subscribedChannels 当前订阅的数量
80 | */
81 | @Override
82 | public void onUnsubscribe(byte[] channel, int subscribedChannels) {
83 | System.out.println("取消订阅channel:" + SafeEncoder.encode(channel) + "subscribedChannels=" + subscribedChannels);
84 | }
85 |
86 |
87 | /**
88 | * 取消订阅 按表达式的方式订阅的消息 (注销)
89 | *
90 | * @param pattern
91 | * @param subscribedChannels 当前订阅的数量
92 | */
93 | @Override
94 | public void onPUnsubscribe(byte[] pattern, int subscribedChannels) {
95 | System.out.println("取消订阅pattern:" + SafeEncoder.encode(pattern) + "subscribedChannels=" + subscribedChannels);
96 | }
97 |
98 |
99 | /**
100 | * 订阅初始化 在{@link springJredisCache.JCache#subscribe(String...)}
101 | *
102 | * 保留接口 不做处理
103 | * 初始化订阅
104 | *
105 | * @param channel
106 | * @param subscribedChannels 当前订阅的数量
107 | */
108 | @Override
109 | public void onSubscribe(byte[] channel, int subscribedChannels) {
110 | }
111 |
112 | /**
113 | * 订阅初始化 在{@link springJredisCache.JCache#publish(String, byte[])} }
114 | * 保留接口 不做处理
115 | * 初始化按表达式的方式订阅的消息
116 | *
117 | * @param pattern 订阅的消息类型
118 | * @param subscribedChannels 订阅的channel数量 from redis
119 | */
120 | @Override
121 | public void onPSubscribe(byte[] pattern, int subscribedChannels) {
122 |
123 | }
124 |
125 |
126 | /**
127 | * 线程池工厂
128 | */
129 | private static class PriorityThreadFactory implements ThreadFactory {
130 | private final int _prio;
131 | private final String _name;
132 | private final AtomicInteger _threadNumber = new AtomicInteger(1);
133 | private final ThreadGroup _group;
134 |
135 | public PriorityThreadFactory(String name, int prio) {
136 | _prio = prio;
137 | _name = name;
138 | _group = new ThreadGroup(_name);
139 | }
140 |
141 | @Override
142 | public Thread newThread(Runnable r) {
143 | Thread t = new Thread(_group, r, _name + "-" + _threadNumber.getAndIncrement());
144 | t.setPriority(_prio);
145 | return t;
146 | }
147 |
148 | public ThreadGroup getGroup() {
149 | return _group;
150 | }
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/src/main/java/proto/Roleofferinfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. @石头哥哥
3 | * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 | */
5 |
6 | package proto;
7 |
8 | import java.io.Serializable;
9 |
10 | /**
11 | * 记录悬赏活动 排行信息
12 | */
13 | public class Roleofferinfo implements Serializable ,Comparable{
14 | private Integer id;
15 |
16 | private Integer roleid;
17 |
18 | private Integer rolecurrentfen;
19 |
20 | private Integer rolecurrentrank;
21 |
22 | private Long oneCooltime; //冷却时间 难度系数1
23 |
24 | private Long twoCooltime;
25 |
26 | private Long threeCooltime;
27 |
28 | private String rolename;
29 |
30 | private static final long serialVersionUID = 1L;
31 |
32 | public Integer getId() {
33 | return id;
34 | }
35 |
36 | public void setId(Integer id) {
37 | this.id = id;
38 | }
39 |
40 | public Integer getRoleid() {
41 | return roleid;
42 | }
43 |
44 | public void setRoleid(Integer roleid) {
45 | this.roleid = roleid;
46 | }
47 |
48 | public Integer getRolecurrentfen() {
49 | return rolecurrentfen;
50 | }
51 |
52 | public void setRolecurrentfen(Integer rolecurrentfen) {
53 | this.rolecurrentfen = rolecurrentfen;
54 | }
55 |
56 | public Integer getRolecurrentrank() {
57 | return rolecurrentrank;
58 | }
59 |
60 | public void setRolecurrentrank(Integer rolecurrentrank) {
61 | this.rolecurrentrank = rolecurrentrank;
62 | }
63 |
64 | public Long getOneCooltime() {
65 | return oneCooltime;
66 | }
67 |
68 | public void setOneCooltime(Long oneCooltime) {
69 | this.oneCooltime = oneCooltime;
70 | }
71 |
72 | public Long getTwoCooltime() {
73 | return twoCooltime;
74 | }
75 |
76 | public void setTwoCooltime(Long twoCooltime) {
77 | this.twoCooltime = twoCooltime;
78 | }
79 |
80 | public Long getThreeCooltime() {
81 | return threeCooltime;
82 | }
83 |
84 | public void setThreeCooltime(Long threeCooltime) {
85 | this.threeCooltime = threeCooltime;
86 | }
87 |
88 | public String getRolename() {
89 | return rolename;
90 | }
91 |
92 | public void setRolename(String rolename) {
93 | this.rolename = rolename == null ? null : rolename.trim();
94 | }
95 |
96 | @Override
97 | public boolean equals(Object that) {
98 | if (this == that) {
99 | return true;
100 | }
101 | if (that == null) {
102 | return false;
103 | }
104 | if (getClass() != that.getClass()) {
105 | return false;
106 | }
107 | Roleofferinfo other = (Roleofferinfo) that;
108 | return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
109 | && (this.getRoleid() == null ? other.getRoleid() == null : this.getRoleid().equals(other.getRoleid()))
110 | && (this.getRolecurrentfen() == null ? other.getRolecurrentfen() == null : this.getRolecurrentfen().equals(other.getRolecurrentfen()))
111 | && (this.getRolecurrentrank() == null ? other.getRolecurrentrank() == null : this.getRolecurrentrank().equals(other.getRolecurrentrank()))
112 | && (this.getOneCooltime() == null ? other.getOneCooltime() == null : this.getOneCooltime().equals(other.getOneCooltime()))
113 | && (this.getTwoCooltime() == null ? other.getTwoCooltime() == null : this.getTwoCooltime().equals(other.getTwoCooltime()))
114 | && (this.getThreeCooltime() == null ? other.getThreeCooltime() == null : this.getThreeCooltime().equals(other.getThreeCooltime()))
115 | && (this.getRolename() == null ? other.getRolename() == null : this.getRolename().equals(other.getRolename()));
116 | }
117 |
118 | @Override
119 | public int hashCode() {
120 | final int prime = 31;
121 | int result = 1;
122 | result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
123 | result = prime * result + ((getRoleid() == null) ? 0 : getRoleid().hashCode());
124 | result = prime * result + ((getRolecurrentfen() == null) ? 0 : getRolecurrentfen().hashCode());
125 | result = prime * result + ((getRolecurrentrank() == null) ? 0 : getRolecurrentrank().hashCode());
126 | result = prime * result + ((getOneCooltime() == null) ? 0 : getOneCooltime().hashCode());
127 | result = prime * result + ((getTwoCooltime() == null) ? 0 : getTwoCooltime().hashCode());
128 | result = prime * result + ((getThreeCooltime() == null) ? 0 : getThreeCooltime().hashCode());
129 | result = prime * result + ((getRolename() == null) ? 0 : getRolename().hashCode());
130 | return result;
131 | }
132 |
133 | /**
134 | * 实现比较接口
135 | * @param o
136 | * @return
137 | */
138 | @Override
139 | public int compareTo(Roleofferinfo o) {
140 | int temp = (this.getRolecurrentfen() - o.getRolecurrentfen());
141 | if (temp > 0) {
142 | return 1;
143 | } else if (temp == 0) {
144 | return 0;
145 | } else {
146 | return -1;
147 | }
148 | }
149 | }
--------------------------------------------------------------------------------
/redis1/sentinel.conf:
--------------------------------------------------------------------------------
1 | # Example sentinel.conf
2 |
3 | # port
4 | # The port that this sentinel instance will run on
5 | port 26379
6 |
7 | # sentinel monitor
8 | #
9 | # Tells Sentinel to monitor this slave, and to consider it in O_DOWN
10 | # (Objectively Down) state only if at least sentinels agree.
11 | #
12 | # Note: master name should not include special characters or spaces.
13 | # The valid charset is A-z 0-9 and the three characters ".-_".
14 | sentinel monitor mymaster 127.0.0.1 6379 2
15 |
16 | # sentinel auth-pass
17 | #
18 | # Set the password to use to authenticate with the master and slaves.
19 | # Useful if there is a password set in the Redis instances to monitor.
20 | #
21 | # Note that the master password is also used for slaves, so it is not
22 | # possible to set a different password in masters and slaves instances
23 | # if you want to be able to monitor these instances with Sentinel.
24 | #
25 | # However you can have Redis instances without the authentication enabled
26 | # mixed with Redis instances requiring the authentication (as long as the
27 | # password set is the same for all the instances requiring the password) as
28 | # the AUTH command will have no effect in Redis instances with authentication
29 | # switched off.
30 | #
31 | # Example:
32 | #
33 | # sentinel auth-pass mymaster MySUPER--secret-0123passw0rd
34 |
35 | # sentinel down-after-milliseconds
36 | #
37 | # Number of milliseconds the master (or any attached slave or sentinel) should
38 | # be unreachable (as in, not acceptable reply to PING, continuously, for the
39 | # specified period) in order to consider it in S_DOWN state (Subjectively
40 | # Down).
41 | #
42 | # Default is 30 seconds.
43 | sentinel down-after-milliseconds mymaster 30000
44 |
45 | # sentinel can-failover
46 | #
47 | # Specify if this Sentinel can start the failover for this master.
48 | sentinel can-failover mymaster yes
49 |
50 | # sentinel parallel-syncs
51 | #
52 | # How many slaves we can reconfigure to point to the new slave simultaneously
53 | # during the failover. Use a low number if you use the slaves to serve query
54 | # to avoid that all the slaves will be unreachable at about the same
55 | # time while performing the synchronization with the master.
56 | sentinel parallel-syncs mymaster 1
57 |
58 | # sentinel failover-timeout
59 | #
60 | # Specifies the failover timeout in milliseconds. When this time has elapsed
61 | # without any progress in the failover process, it is considered concluded by
62 | # the sentinel even if not all the attached slaves were correctly configured
63 | # to replicate with the new master (however a "best effort" SLAVEOF command
64 | # is sent to all the slaves before).
65 | #
66 | # Also when 25% of this time has elapsed without any advancement, and there
67 | # is a leader switch (the sentinel did not started the failover but is now
68 | # elected as leader), the sentinel will continue the failover doing a
69 | # "takeover".
70 | #
71 | # Default is 15 minutes.
72 | sentinel failover-timeout mymaster 900000
73 |
74 | # SCRIPTS EXECUTION
75 | #
76 | # sentinel notification-script and sentinel reconfig-script are used in order
77 | # to configure scripts that are called to notify the system administrator
78 | # or to reconfigure clients after a failover. The scripts are executed
79 | # with the following rules for error handling:
80 | #
81 | # If script exists with "1" the execution is retried later (up to a maximum
82 | # number of times currently set to 10).
83 | #
84 | # If script exists with "2" (or an higher value) the script execution is
85 | # not retried.
86 | #
87 | # If script terminates because it receives a signal the behavior is the same
88 | # as exit code 1.
89 | #
90 | # A script has a maximum running time of 60 seconds. After this limit is
91 | # reached the script is terminated with a SIGKILL and the execution retried.
92 |
93 | # NOTIFICATION SCRIPT
94 | #
95 | # sentinel notification-script
96 | #
97 | # Call the specified notification script for any sentienl event that is
98 | # generated in the WARNING level (for instance -sdown, -odown, and so forth).
99 | # This script should notify the system administrator via email, SMS, or any
100 | # other messaging system, that there is something wrong with the monitored
101 | # Redis systems.
102 | #
103 | # The script is called with just two arguments: the first is the event type
104 | # and the second the event description.
105 | #
106 | # The script must exist and be executable in order for sentinel to start if
107 | # this option is provided.
108 | #
109 | # Example:
110 | #
111 | # sentinel notification-script mymaster /var/redis/notify.sh
112 |
113 | # CLIENTS RECONFIGURATION SCRIPT
114 | #
115 | # sentinel client-reconfig-script
116 | #
117 | # When the failover starts, ends, or is aborted, a script can be called in
118 | # order to perform application-specific tasks to notify the clients that the
119 | # configuration has changed and the master is at a different address.
120 | #
121 | # The script is called in the following cases:
122 | #
123 | # Failover started (a slave is already promoted)
124 | # Failover finished (all the additional slaves already reconfigured)
125 | # Failover aborted (in that case the script was previously called when the
126 | # failover started, and now gets called again with swapped
127 | # addresses).
128 | #
129 | # The following arguments are passed to the script:
130 | #
131 | #
132 | #
133 | # is "start", "end" or "abort"
134 | # is either "leader" or "observer"
135 | #
136 | # The arguments from-ip, from-port, to-ip, to-port are used to communicate
137 | # the old address of the master and the new address of the elected slave
138 | # (now a master) in the case state is "start" or "end".
139 | #
140 | # For abort instead the "from" is the address of the promoted slave and
141 | # "to" is the address of the original master address, since the failover
142 | # was aborted.
143 | #
144 | # This script should be resistant to multiple invocations.
145 | #
146 | # Example:
147 | #
148 | # sentinel client-reconfig-script mymaster /var/redis/reconfig.sh
149 |
150 |
151 |
--------------------------------------------------------------------------------
/redis2/sentinel.conf:
--------------------------------------------------------------------------------
1 | # Example sentinel.conf
2 |
3 | # port
4 | # The port that this sentinel instance will run on
5 | port 26379
6 |
7 | # sentinel monitor
8 | #
9 | # Tells Sentinel to monitor this slave, and to consider it in O_DOWN
10 | # (Objectively Down) state only if at least sentinels agree.
11 | #
12 | # Note: master name should not include special characters or spaces.
13 | # The valid charset is A-z 0-9 and the three characters ".-_".
14 | sentinel monitor mymaster 127.0.0.1 6379 2
15 |
16 | # sentinel auth-pass
17 | #
18 | # Set the password to use to authenticate with the master and slaves.
19 | # Useful if there is a password set in the Redis instances to monitor.
20 | #
21 | # Note that the master password is also used for slaves, so it is not
22 | # possible to set a different password in masters and slaves instances
23 | # if you want to be able to monitor these instances with Sentinel.
24 | #
25 | # However you can have Redis instances without the authentication enabled
26 | # mixed with Redis instances requiring the authentication (as long as the
27 | # password set is the same for all the instances requiring the password) as
28 | # the AUTH command will have no effect in Redis instances with authentication
29 | # switched off.
30 | #
31 | # Example:
32 | #
33 | # sentinel auth-pass mymaster MySUPER--secret-0123passw0rd
34 |
35 | # sentinel down-after-milliseconds
36 | #
37 | # Number of milliseconds the master (or any attached slave or sentinel) should
38 | # be unreachable (as in, not acceptable reply to PING, continuously, for the
39 | # specified period) in order to consider it in S_DOWN state (Subjectively
40 | # Down).
41 | #
42 | # Default is 30 seconds.
43 | sentinel down-after-milliseconds mymaster 30000
44 |
45 | # sentinel can-failover
46 | #
47 | # Specify if this Sentinel can start the failover for this master.
48 | sentinel can-failover mymaster yes
49 |
50 | # sentinel parallel-syncs
51 | #
52 | # How many slaves we can reconfigure to point to the new slave simultaneously
53 | # during the failover. Use a low number if you use the slaves to serve query
54 | # to avoid that all the slaves will be unreachable at about the same
55 | # time while performing the synchronization with the master.
56 | sentinel parallel-syncs mymaster 1
57 |
58 | # sentinel failover-timeout
59 | #
60 | # Specifies the failover timeout in milliseconds. When this time has elapsed
61 | # without any progress in the failover process, it is considered concluded by
62 | # the sentinel even if not all the attached slaves were correctly configured
63 | # to replicate with the new master (however a "best effort" SLAVEOF command
64 | # is sent to all the slaves before).
65 | #
66 | # Also when 25% of this time has elapsed without any advancement, and there
67 | # is a leader switch (the sentinel did not started the failover but is now
68 | # elected as leader), the sentinel will continue the failover doing a
69 | # "takeover".
70 | #
71 | # Default is 15 minutes.
72 | sentinel failover-timeout mymaster 900000
73 |
74 | # SCRIPTS EXECUTION
75 | #
76 | # sentinel notification-script and sentinel reconfig-script are used in order
77 | # to configure scripts that are called to notify the system administrator
78 | # or to reconfigure clients after a failover. The scripts are executed
79 | # with the following rules for error handling:
80 | #
81 | # If script exists with "1" the execution is retried later (up to a maximum
82 | # number of times currently set to 10).
83 | #
84 | # If script exists with "2" (or an higher value) the script execution is
85 | # not retried.
86 | #
87 | # If script terminates because it receives a signal the behavior is the same
88 | # as exit code 1.
89 | #
90 | # A script has a maximum running time of 60 seconds. After this limit is
91 | # reached the script is terminated with a SIGKILL and the execution retried.
92 |
93 | # NOTIFICATION SCRIPT
94 | #
95 | # sentinel notification-script
96 | #
97 | # Call the specified notification script for any sentienl event that is
98 | # generated in the WARNING level (for instance -sdown, -odown, and so forth).
99 | # This script should notify the system administrator via email, SMS, or any
100 | # other messaging system, that there is something wrong with the monitored
101 | # Redis systems.
102 | #
103 | # The script is called with just two arguments: the first is the event type
104 | # and the second the event description.
105 | #
106 | # The script must exist and be executable in order for sentinel to start if
107 | # this option is provided.
108 | #
109 | # Example:
110 | #
111 | # sentinel notification-script mymaster /var/redis/notify.sh
112 |
113 | # CLIENTS RECONFIGURATION SCRIPT
114 | #
115 | # sentinel client-reconfig-script
116 | #
117 | # When the failover starts, ends, or is aborted, a script can be called in
118 | # order to perform application-specific tasks to notify the clients that the
119 | # configuration has changed and the master is at a different address.
120 | #
121 | # The script is called in the following cases:
122 | #
123 | # Failover started (a slave is already promoted)
124 | # Failover finished (all the additional slaves already reconfigured)
125 | # Failover aborted (in that case the script was previously called when the
126 | # failover started, and now gets called again with swapped
127 | # addresses).
128 | #
129 | # The following arguments are passed to the script:
130 | #
131 | #
132 | #
133 | # is "start", "end" or "abort"
134 | # is either "leader" or "observer"
135 | #
136 | # The arguments from-ip, from-port, to-ip, to-port are used to communicate
137 | # the old address of the master and the new address of the elected slave
138 | # (now a master) in the case state is "start" or "end".
139 | #
140 | # For abort instead the "from" is the address of the promoted slave and
141 | # "to" is the address of the original master address, since the failover
142 | # was aborted.
143 | #
144 | # This script should be resistant to multiple invocations.
145 | #
146 | # Example:
147 | #
148 | # sentinel client-reconfig-script mymaster /var/redis/reconfig.sh
149 |
150 |
151 |
--------------------------------------------------------------------------------
/src/test/java/testJRedis/Test.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. @石头哥哥
3 | * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 | */
5 |
6 | package testJRedis;
7 |
8 | import org.apache.log4j.xml.DOMConfigurator;
9 | import org.junit.After;
10 | import org.junit.Before;
11 | import org.springframework.context.support.FileSystemXmlApplicationContext;
12 | import org.springframework.stereotype.Service;
13 | import proto.TRoleEqu;
14 | import springJredisCache.JRedisCache;
15 | import springJredisCache.JRedisSerializationUtils;
16 | import springJredisCache.Serializations.KryoThreadLocalSer;
17 |
18 | import javax.annotation.Resource;
19 | import java.util.ArrayList;
20 | import java.util.Arrays;
21 | import java.util.List;
22 |
23 | /**
24 | * @author 石头哥哥
25 | * Date:1/19/14
26 | * Time:8:40 PM
27 | * Package:testJRedis
28 | * Comment:
29 | */
30 | @Service("test")
31 | @SuppressWarnings("unchecked")
32 | public class Test {
33 |
34 | @Resource
35 | private JRedisCache jRedisCache;
36 |
37 | private FileSystemXmlApplicationContext springContext;
38 |
39 | @Before
40 | public void IntiRes() {
41 | DOMConfigurator.configure("res/appConfig/log4j.xml");
42 | System.setProperty("java.net.preferIPv4Stack", "true"); //Disable IPv6 in JVM
43 | springContext = new FileSystemXmlApplicationContext("res/springConfig/spring-context.xml");
44 |
45 |
46 | List list = Arrays.asList("");
47 |
48 | List stringList = new ArrayList();
49 |
50 |
51 | // JRedisSerializationUtils.fastDeserialize(JRedisSerializationUtils.fastSerialize(list));
52 | //
53 | // JRedisSerializationUtils.kryoDeserialize(JRedisSerializationUtils.kryoSerialize(list));
54 |
55 |
56 | System.out.println
57 | ((list instanceof ArrayList) ? "list is ArrayList"
58 | : "list not ArrayList?");
59 |
60 | System.out.println
61 | ((stringList instanceof ArrayList) ? "list is ArrayList"
62 | : "list not ArrayList?");
63 |
64 | KryoThreadLocalSer.getInstance().ObjDeserialize( KryoThreadLocalSer.getInstance().ObjSerialize(list));
65 |
66 |
67 | }
68 |
69 |
70 | @org.junit.Test
71 | public void testJRedis() throws InterruptedException {
72 | /**初始化spring容器*/
73 | Test test = (Test) springContext.getBean("test");
74 |
75 |
76 | // RoleVo.Builder builder=RoleVo.newBuilder();
77 | // builder.setRoleID(1);
78 | // builder.setRoleName("石头哥哥");
79 | // builder.setRoleSex(1);
80 | // RoleVo vo=builder.build();
81 | //
82 | //
83 | //
84 | // ArrayList list=new ArrayList();
85 | // list.add(1);
86 | // list.add(2);
87 | // list.add(3);
88 | //
89 | // //set
90 | // test.jRedisCache.putList("list", list);
91 | // for(int i=0;i!=10000;++i){
92 | // // get
93 | // list= (ArrayList)test. jRedisCache.getList("list");
94 | //
95 | // for(int value:list){
96 | // System.out.println("get value from redis:" + value);
97 | // }
98 | // }
99 | String key = "rolename";
100 | String filed = "role";
101 | ArrayList equArrayList = new ArrayList();
102 | for (int i = 0; i != 500000; ++i) {
103 | equArrayList.add(new TRoleEqu());
104 | }
105 |
106 | //1024*40 500数据 40960
107 | //1000 81038 1k数据 81038
108 | //1024*1024 1048576 1w条数据 810038
109 | /**
110 | *
111 | >>>>>>>>>>>>>>>>>>>>>>>>>>
112 | serialize:833
113 | Deserialize:1137
114 | >>>>>>>>>>>>>>>>>>>>>>>>>>
115 | >>>>>>>>>>>>>>>>>>>>>>>>>>
116 | serialize:308
117 | Deserialize:539
118 | >>>>>>>>>>>>>>>>>>>>>>>>>>
119 | >>>>>>>>>>>>>>>>>>>>>>>>>>
120 | serialize:367
121 | Deserialize:376
122 | >>>>>>>>>>>>>>>>>>>>>>>>>>
123 |
124 |
125 | >>>>>>>>>>>>>>>>>>>>>>>>>>
126 | serialize:1317
127 | Deserialize:347
128 | >>>>>>>>>>>>>>>>>>>>>>>>>>
129 | >>>>>>>>>>>>>>>>>>>>>>>>>>
130 | serialize:406
131 | Deserialize:2074
132 | >>>>>>>>>>>>>>>>>>>>>>>>>>
133 | >>>>>>>>>>>>>>>>>>>>>>>>>>
134 | serialize:377
135 | Deserialize:359
136 | >>>>>>>>>>>>>>>>>>>>>>>>>>
137 |
138 |
139 | */
140 |
141 |
142 | for (int i = 0; i != 3; ++i) {
143 | System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>");
144 | long start1 = System.currentTimeMillis();
145 | byte[] kryo_bytes = JRedisSerializationUtils.kryoSerialize(equArrayList);
146 |
147 | System.out.println("serialize:" + (System.currentTimeMillis() - start1));
148 |
149 | long start2 = System.currentTimeMillis();
150 | ArrayList kryo_list = (ArrayList) JRedisSerializationUtils.kryoDeserialize(kryo_bytes);
151 |
152 | System.out.println("Deserialize:" + (System.currentTimeMillis() - start2));
153 | System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>");
154 | }
155 |
156 |
157 | test.jRedisCache.putList(key, filed, equArrayList);
158 |
159 |
160 | ArrayList equArrayList2 = (ArrayList) test.jRedisCache.getList(key, filed);
161 |
162 | //
163 | equArrayList2.clear();
164 | equArrayList.clear();
165 | //
166 | // test.jRedisCache.removeList(key);
167 |
168 | // FastTable roleofferinfos= (FastTable)test. jRedisCache.getFastTable(key);
169 | // System.out.println("get value from redis:" + roleofferinfos);
170 |
171 |
172 | }
173 |
174 | @After
175 | public void closeApp() {
176 | springContext.close();
177 | }
178 |
179 |
180 | }
181 |
--------------------------------------------------------------------------------
/src/main/java/springJredisCache/Serializations/KryoPoolSer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. @石头哥哥
3 | * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 | */
5 |
6 | package springJredisCache.Serializations;
7 |
8 | import com.esotericsoftware.kryo.Kryo;
9 | import com.esotericsoftware.kryo.io.Input;
10 | import com.esotericsoftware.kryo.io.Output;
11 | import de.javakaffee.kryoserializers.*;
12 | import de.javakaffee.kryoserializers.cglib.CGLibProxySerializer;
13 | import javolution.util.FastTable;
14 | import springJredisCache.JRedisCacheException;
15 |
16 | import java.lang.reflect.InvocationHandler;
17 | import java.util.Arrays;
18 | import java.util.Collections;
19 | import java.util.GregorianCalendar;
20 |
21 | /**
22 | * Created by chenlei on 14-10-4.
23 | * PROJECT_NAME: springJredisCache
24 | * PACKAGE_NAME: springJredisCache.Serializations
25 | */
26 | public class KryoPoolSer {
27 |
28 |
29 | /**
30 | * Kryo 的包装
31 | */
32 | private static class KryoHolder {
33 | private Kryo kryo;
34 | static final int BUFFER_SIZE = 1024;
35 | private Output output = new Output(BUFFER_SIZE, -1); //reuse
36 | private Input input = new Input();
37 |
38 | KryoHolder(Kryo kryo) {
39 | this.kryo = kryo;
40 |
41 | // register
42 | this.kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer());
43 | this.kryo.register(Collections.EMPTY_LIST.getClass(), new CollectionsEmptyListSerializer());
44 | this.kryo.register(Collections.EMPTY_MAP.getClass(), new CollectionsEmptyMapSerializer());
45 | this.kryo.register(Collections.EMPTY_SET.getClass(), new CollectionsEmptySetSerializer());
46 | this.kryo.register(Collections.singletonList("").getClass(), new CollectionsSingletonListSerializer());
47 | this.kryo.register(Collections.singleton("").getClass(), new CollectionsSingletonSetSerializer());
48 | this.kryo.register(Collections.singletonMap("", "").getClass(), new CollectionsSingletonMapSerializer());
49 | this.kryo.register(GregorianCalendar.class, new GregorianCalendarSerializer());
50 | this.kryo.register(InvocationHandler.class, new JdkProxySerializer());
51 | // register CGLibProxySerializer, works in combination with the appropriate action in handleUnregisteredClass (see below)
52 | this.kryo.register(CGLibProxySerializer.CGLibProxyMarker.class, new CGLibProxySerializer());
53 | UnmodifiableCollectionsSerializer.registerSerializers(this.kryo);
54 | SynchronizedCollectionsSerializer.registerSerializers(this.kryo);
55 |
56 | //其他第三方
57 | // // joda datetime
58 | // kryo.register(DateTime.class, new JodaDateTimeSerializer());
59 | // // wicket
60 | // kryo.register(MiniMap.class, new MiniMapSerializer());
61 | // // guava ImmutableList
62 | // ImmutableListSerializer.registerSerializers(kryo);
63 | }
64 |
65 |
66 | }
67 |
68 |
69 | interface KryoPool {
70 |
71 | /**
72 | * get o kryo object
73 | *
74 | * @return
75 | */
76 | KryoHolder get();
77 |
78 | /**
79 | * return object
80 | *
81 | * @param kryo
82 | */
83 | void offer(KryoHolder kryo);
84 | }
85 |
86 |
87 | //基于kryo序列换方案
88 |
89 | /**
90 | * 由于kryo创建的代价相对较高 ,这里使用空间换时间
91 | * 对KryoHolder对象进行重用
92 | * KryoHolder会出现峰值,应该不会造成内存泄漏哦
93 | */
94 | public static class KryoPoolImpl implements KryoPool {
95 | /**
96 | * default is 1500
97 | * online server limit 3K
98 | */
99 | // private static int DEFAULT_MAX_KRYO_SIZE = 1500;
100 |
101 | /**
102 | * thread safe list
103 | */
104 | private final FastTable kryoFastTable = new FastTable().atomic();
105 |
106 |
107 | /**
108 | *
109 | */
110 | private KryoPoolImpl() {
111 |
112 | }
113 |
114 | /**
115 | * @return
116 | */
117 | public static KryoPool getInstance() {
118 | return Singleton.pool;
119 | }
120 |
121 | /**
122 | * get o KryoHolder object
123 | *
124 | * @return
125 | */
126 | @Override
127 | public KryoHolder get() {
128 | KryoHolder kryoHolder = kryoFastTable.pollFirst(); // Retrieves and removes the head of the queue represented by this table
129 | return kryoHolder == null ? creatInstnce() : kryoHolder;
130 | }
131 |
132 | /**
133 | * create a new kryo object to application use
134 | *
135 | * @return
136 | */
137 | public KryoHolder creatInstnce() {
138 | Kryo kryo = new Kryo();
139 | kryo.setReferences(false);//
140 | return new KryoHolder(kryo);
141 | }
142 |
143 | /**
144 | * return object
145 | * Inserts the specified element at the tail of this queue.
146 | *
147 | * @param kryoHolder
148 | */
149 | @Override
150 | public void offer(KryoHolder kryoHolder) {
151 | kryoFastTable.addLast(kryoHolder);
152 | }
153 |
154 | /**
155 | * creat a Singleton
156 | */
157 | private static class Singleton {
158 | private static final KryoPool pool = new KryoPoolImpl();
159 | }
160 | }
161 |
162 |
163 | /**
164 | * 将对象序列化为字节数组
165 | *
166 | * @param obj
167 | * @return 字节数组
168 | * @throws springJredisCache.JRedisCacheException
169 | */
170 | public byte[] ObjSerialize(Object obj) {
171 | KryoHolder kryoHolder = null;
172 | if (obj == null) throw new JRedisCacheException("obj can not be null");
173 | try {
174 | kryoHolder = KryoPoolImpl.getInstance().get();
175 | kryoHolder.output.clear(); //clear Output -->每次调用的时候 重置
176 | kryoHolder.kryo.writeClassAndObject(kryoHolder.output, obj);
177 | return kryoHolder.output.toBytes();// 无法避免拷贝 ~~~
178 | } catch (JRedisCacheException e) {
179 | throw new JRedisCacheException("Serialize obj exception");
180 | } finally {
181 | KryoPoolImpl.getInstance().offer(kryoHolder);
182 | obj = null; //GC
183 | }
184 | }
185 |
186 |
187 | /**
188 | * 将字节数组反序列化为对象
189 | *
190 | * @param bytes 字节数组
191 | * @return object
192 | * @throws JRedisCacheException
193 | */
194 | public Object ObjDeserialize(byte[] bytes) throws JRedisCacheException {
195 | KryoHolder kryoHolder = null;
196 | if (bytes == null) throw new JRedisCacheException("bytes can not be null");
197 | try {
198 | kryoHolder = KryoPoolImpl.getInstance().get();
199 | kryoHolder.input.setBuffer(bytes, 0, bytes.length);//call it ,and then use input object ,discard any array
200 | return kryoHolder.kryo.readClassAndObject(kryoHolder.input);
201 | } catch (JRedisCacheException e) {
202 | throw new JRedisCacheException("Deserialize bytes exception");
203 | } finally {
204 | KryoPoolImpl.getInstance().offer(kryoHolder);
205 | bytes = null; // for gc
206 | }
207 | }
208 |
209 |
210 | /**
211 | * 将字节数组反序列化为对象
212 | *
213 | * @param bytes 字节数组
214 | * @return object
215 | * @throws JRedisCacheException
216 | */
217 | public Object kryoDeserialize(byte[] bytes, int length) throws JRedisCacheException {
218 | KryoHolder kryoHolder = null;
219 | if (bytes == null) throw new JRedisCacheException("bytes can not be null");
220 | try {
221 | kryoHolder = KryoPoolImpl.getInstance().get();
222 | kryoHolder.input.setBuffer(bytes, 0, length);//call it ,and then use input object ,discard any array
223 | return kryoHolder.kryo.readClassAndObject(kryoHolder.input);
224 | } catch (JRedisCacheException e) {
225 | throw new JRedisCacheException("Deserialize bytes exception");
226 | } finally {
227 | KryoPoolImpl.getInstance().offer(kryoHolder);
228 | bytes = null; // for gc
229 | }
230 | }
231 | }
232 |
--------------------------------------------------------------------------------
/src/test/java/testJRedis/TestD_S.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. @石头哥哥
3 | * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 | */
5 |
6 | package testJRedis;
7 |
8 | import com.esotericsoftware.kryo.Kryo;
9 | import com.esotericsoftware.kryo.io.Input;
10 | import com.esotericsoftware.kryo.io.Output;
11 | import proto.TRoleEqu;
12 | import springJredisCache.JRedisSerializationUtils;
13 |
14 | import java.io.Serializable;
15 | import java.util.ArrayList;
16 |
17 | /**
18 | * @author 石头哥哥
19 | * dcServer1.7
20 | * Date:14-2-11
21 | * Time:下午3:36
22 | * Package:{@link springJredisCache}
23 | * Comment: 序列化 反序列化 测试
24 | */
25 | public class TestD_S implements Serializable {
26 |
27 | private String username;
28 | private String password;
29 | private int age;
30 | private ArrayList list;
31 |
32 | public TestD_S() {
33 | list = new ArrayList();
34 | list.add(1);
35 | list.add(2);
36 | list.add(3);
37 | }
38 |
39 |
40 | public static void main(String[] args) throws Exception {
41 |
42 | final TRoleEqu vo = new TRoleEqu();
43 | vo.setOwnerid(1);
44 | vo.setEquid(1);
45 |
46 |
47 | Thread t1 = new Thread(new Runnable() {
48 | @Override
49 | public void run() {
50 | System.out.println("序列化 , 反序列化 100W 次对比测试:");
51 | for (int j = 0; j != 50; ++j) {
52 | // long time2 = System.currentTimeMillis();
53 | // for (int i = 0; i < 100000; i++) {
54 | // try {
55 | // JRedisSerializationUtils.fastDeserialize(JRedisSerializationUtils.fastSerialize(vo));
56 | // } catch (Exception e) {
57 | // e.printStackTrace();
58 | // }
59 | // }
60 | // System.out.println("1>>>fast序列化方案[序列化10W次]:"
61 | // + (System.currentTimeMillis() - time2));
62 |
63 | long time1 = System.currentTimeMillis();
64 | for (int i = 0; i < 1000000; i++) {
65 | JRedisSerializationUtils.kryoDeserialize(JRedisSerializationUtils.kryoSerialize(vo));
66 | }
67 | System.out.println("池化kryo处理方案1>>>kryo序列化方案[序列化100W次]:"
68 | + (System.currentTimeMillis() - time1));
69 |
70 | System.out.println("------------------------------------------------------------------------------");
71 | }
72 | }
73 | });
74 |
75 |
76 | final TRoleEqu vo2 = new TRoleEqu();
77 | vo2.setOwnerid(1);
78 | vo2.setEquid(1);
79 |
80 |
81 | Thread t2 = new Thread(new Runnable() {
82 | @Override
83 | public void run() {
84 | System.out.println("序列化 , 反序列化 100W 次对比测试:");
85 | for (int j = 0; j != 50; ++j) {
86 |
87 | long time1 = System.currentTimeMillis();
88 | for (int i = 0; i < 1000000; i++) {
89 | JRedisSerializationUtils.kryoDeserialize(JRedisSerializationUtils.kryoSerialize(vo2));
90 | }
91 | System.out.println("池化kryo处理方案测试2>>>kryo序列化方案[序列化100W次]:"
92 | + (System.currentTimeMillis() - time1));
93 |
94 | // long time2 = System.currentTimeMillis();
95 | // for (int i = 0; i < 100000; i++) {
96 | // try {
97 | // JRedisSerializationUtils.fastDeserialize(JRedisSerializationUtils.fastSerialize(vo2));
98 | // } catch (Exception e) {
99 | // e.printStackTrace();
100 | // }
101 | // }
102 | // System.out.println("2>>>fast序列化方案[序列化10W次]:"
103 | // + (System.currentTimeMillis() - time2));
104 |
105 | System.out.println("------------------------------------------------------------------------------");
106 | }
107 | }
108 | });
109 |
110 |
111 |
112 | final TRoleEqu vo3 = new TRoleEqu();
113 | vo3.setOwnerid(1);
114 | vo3.setEquid(1);
115 | System.out.println("序列化 , 反序列化 100W 次对比测试:");
116 |
117 | Thread t3=new Thread(new Runnable() {
118 | @Override
119 | public void run() {
120 | for (int j = 0; j != 50; ++j) {
121 | long time1 = System.currentTimeMillis();
122 | for (int i = 0; i < 1000000; i++) {
123 | Kryo kryo=new Kryo();
124 | Output output = new Output(1024, -1) ;
125 | kryo.writeClassAndObject(output,vo3);
126 | Input input=new Input();
127 | input.setBuffer(output.toBytes());
128 | kryo.readClassAndObject(input);
129 | //JRedisSerializationUtils.kryoDeserialize(JRedisSerializationUtils.kryoSerialize(vo2));
130 | }
131 | System.out.println("每次new一个Kyro实例>>>kryo序列化方案[序列化100W次]:"
132 | + (System.currentTimeMillis() - time1));
133 |
134 | // long time2 = System.currentTimeMillis();
135 | // for (int i = 0; i < 100000; i++) {
136 | // try {
137 | // JRedisSerializationUtils.fastDeserialize(JRedisSerializationUtils.fastSerialize(vo2));
138 | // } catch (Exception e) {
139 | // e.printStackTrace();
140 | // }
141 | // }
142 | // System.out.println("2--only >>fast序列化方案[序列化10W次]:"
143 | // + (System.currentTimeMillis() - time2));
144 |
145 | System.out.println("------------------------------------------------------------------------------");
146 | }
147 | }
148 | });
149 |
150 |
151 |
152 |
153 | t1.start();
154 | t2.start();
155 | t3.start();
156 |
157 |
158 |
159 |
160 |
161 | }
162 |
163 | // @org.junit.Test
164 | // public void testSerialize() throws Exception {
165 | //
166 | // TRoleEqu vo = new TRoleEqu();
167 | // vo.setOwnerid(1);
168 | // vo.setEquid(1);
169 | //
170 | //// RoleVo.Builder builder = RoleVo.newBuilder();
171 | //// builder.setRoleName("123");
172 | //// builder.setRoleID(1);
173 | //// RoleVo vo = builder.build();
174 | //
175 | // System.out.println("序列化 , 反序列化 10W 次对比测试:");
176 | //
177 | // for (int j = 0; j != 50; ++j) {
178 | // long time1 = System.currentTimeMillis();
179 | // for (int i = 0; i < 10000; i++) {
180 | // JRedisSerializationUtils.kryoDeserialize(JRedisSerializationUtils.kryoSerialize(vo));
181 | // }
182 | // System.out.println("kryo序列化方案[序列化10000次]:"
183 | // + (System.currentTimeMillis() - time1));
184 | //
185 | // long time2 = System.currentTimeMillis();
186 | // for (int i = 0; i < 10000; i++) {
187 | // JRedisSerializationUtils.fastDeserialize(JRedisSerializationUtils.fastSerialize(vo));
188 | // }
189 | // System.out.println("fast序列化方案[序列化10000次]:"
190 | // + (System.currentTimeMillis() - time2));
191 | //
192 | //// long time3 = System.currentTimeMillis();
193 | //// for (int i = 0; i < 1000000; i++) {
194 | //// JRedisSerializationUtils.jdeserialize(JRedisSerializationUtils.jserialize(vo));
195 | //// }
196 | //// System.out.println("jdk序列化方案[序列化1000000次]:"
197 | //// + (System.currentTimeMillis() - time3));
198 | //
199 | //
200 | //// long time4 = System.currentTimeMillis();
201 | //// for (int i = 0; i < 100000; i++) {
202 | //// JRedisSerializationUtils.protoDeserialize(JRedisSerializationUtils.protoSerialize(vo), RoleVo.getDefaultInstance());
203 | //// }
204 | //// System.out.println("protoBuffer序列化方案[序列化100000次]:"
205 | //// + (System.currentTimeMillis() - time4));
206 | //
207 | // System.out.println("------------------------------------------------------------------------------");
208 | // }
209 | // }
210 |
211 |
212 | public String getUsername() {
213 | return username;
214 | }
215 |
216 | public void setUsername(String username) {
217 | this.username = username;
218 | }
219 |
220 | public String getPassword() {
221 | return password;
222 | }
223 |
224 | public void setPassword(String password) {
225 | this.password = password;
226 | }
227 |
228 | public int getAge() {
229 | return age;
230 | }
231 |
232 | public void setAge(int age) {
233 | this.age = age;
234 | }
235 |
236 | }
237 |
--------------------------------------------------------------------------------
/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, and
10 | distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by the copyright
13 | owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all other entities
16 | that control, are controlled by, or are under common control with that entity.
17 | For the purposes of this definition, "control" means (i) the power, direct or
18 | indirect, to cause the direction or management of such entity, whether by
19 | contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
20 | outstanding shares, or (iii) beneficial ownership of such entity.
21 |
22 | "You" (or "Your") shall mean an individual or Legal Entity exercising
23 | permissions granted by this License.
24 |
25 | "Source" form shall mean the preferred form for making modifications, including
26 | but not limited to software source code, documentation source, and configuration
27 | files.
28 |
29 | "Object" form shall mean any form resulting from mechanical transformation or
30 | translation of a Source form, including but not limited to compiled object code,
31 | generated documentation, and conversions to other media types.
32 |
33 | "Work" shall mean the work of authorship, whether in Source or Object form, made
34 | available under the License, as indicated by a copyright notice that is included
35 | in or attached to the work (an example is provided in the Appendix below).
36 |
37 | "Derivative Works" shall mean any work, whether in Source or Object form, that
38 | is based on (or derived from) the Work and for which the editorial revisions,
39 | annotations, elaborations, or other modifications represent, as a whole, an
40 | original work of authorship. For the purposes of this License, Derivative Works
41 | shall not include works that remain separable from, or merely link (or bind by
42 | name) to the interfaces of, the Work and Derivative Works thereof.
43 |
44 | "Contribution" shall mean any work of authorship, including the original version
45 | of the Work and any modifications or additions to that Work or Derivative Works
46 | thereof, that is intentionally submitted to Licensor for inclusion in the Work
47 | by the copyright owner or by an individual or Legal Entity authorized to submit
48 | on behalf of the copyright owner. For the purposes of this definition,
49 | "submitted" means any form of electronic, verbal, or written communication sent
50 | to the Licensor or its representatives, including but not limited to
51 | communication on electronic mailing lists, source code control systems, and
52 | issue tracking systems that are managed by, or on behalf of, the Licensor for
53 | the purpose of discussing and improving the Work, but excluding communication
54 | that is conspicuously marked or otherwise designated in writing by the copyright
55 | owner as "Not a Contribution."
56 |
57 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf
58 | of whom a Contribution has been received by Licensor and subsequently
59 | incorporated within the Work.
60 |
61 | 2. Grant of Copyright License.
62 |
63 | Subject to the terms and conditions of this License, each Contributor hereby
64 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
65 | irrevocable copyright license to reproduce, prepare Derivative Works of,
66 | publicly display, publicly perform, sublicense, and distribute the Work and such
67 | Derivative Works in Source or Object form.
68 |
69 | 3. Grant of Patent License.
70 |
71 | Subject to the terms and conditions of this License, each Contributor hereby
72 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
73 | irrevocable (except as stated in this section) patent license to make, have
74 | made, use, offer to sell, sell, import, and otherwise transfer the Work, where
75 | such license applies only to those patent claims licensable by such Contributor
76 | that are necessarily infringed by their Contribution(s) alone or by combination
77 | of their Contribution(s) with the Work to which such Contribution(s) was
78 | submitted. If You institute patent litigation against any entity (including a
79 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a
80 | Contribution incorporated within the Work constitutes direct or contributory
81 | patent infringement, then any patent licenses granted to You under this License
82 | for that Work shall terminate as of the date such litigation is filed.
83 |
84 | 4. Redistribution.
85 |
86 | You may reproduce and distribute copies of the Work or Derivative Works thereof
87 | in any medium, with or without modifications, and in Source or Object form,
88 | provided that You meet the following conditions:
89 |
90 | You must give any other recipients of the Work or Derivative Works a copy of
91 | this License; and
92 | You must cause any modified files to carry prominent notices stating that You
93 | changed the files; and
94 | You must retain, in the Source form of any Derivative Works that You distribute,
95 | all copyright, patent, trademark, and attribution notices from the Source form
96 | of the Work, excluding those notices that do not pertain to any part of the
97 | Derivative Works; and
98 | If the Work includes a "NOTICE" text file as part of its distribution, then any
99 | Derivative Works that You distribute must include a readable copy of the
100 | attribution notices contained within such NOTICE file, excluding those notices
101 | that do not pertain to any part of the Derivative Works, in at least one of the
102 | following places: within a NOTICE text file distributed as part of the
103 | Derivative Works; within the Source form or documentation, if provided along
104 | with the Derivative Works; or, within a display generated by the Derivative
105 | Works, if and wherever such third-party notices normally appear. The contents of
106 | the NOTICE file are for informational purposes only and do not modify the
107 | License. You may add Your own attribution notices within Derivative Works that
108 | You distribute, alongside or as an addendum to the NOTICE text from the Work,
109 | provided that such additional attribution notices cannot be construed as
110 | modifying the License.
111 | You may add Your own copyright statement to Your modifications and may provide
112 | additional or different license terms and conditions for use, reproduction, or
113 | distribution of Your modifications, or for any such Derivative Works as a whole,
114 | provided Your use, reproduction, and distribution of the Work otherwise complies
115 | with the conditions stated in this License.
116 |
117 | 5. Submission of Contributions.
118 |
119 | Unless You explicitly state otherwise, any Contribution intentionally submitted
120 | for inclusion in the Work by You to the Licensor shall be under the terms and
121 | conditions of this License, without any additional terms or conditions.
122 | Notwithstanding the above, nothing herein shall supersede or modify the terms of
123 | any separate license agreement you may have executed with Licensor regarding
124 | such Contributions.
125 |
126 | 6. Trademarks.
127 |
128 | This License does not grant permission to use the trade names, trademarks,
129 | service marks, or product names of the Licensor, except as required for
130 | reasonable and customary use in describing the origin of the Work and
131 | reproducing the content of the NOTICE file.
132 |
133 | 7. Disclaimer of Warranty.
134 |
135 | Unless required by applicable law or agreed to in writing, Licensor provides the
136 | Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
137 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
138 | including, without limitation, any warranties or conditions of TITLE,
139 | NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
140 | solely responsible for determining the appropriateness of using or
141 | redistributing the Work and assume any risks associated with Your exercise of
142 | permissions under this License.
143 |
144 | 8. Limitation of Liability.
145 |
146 | In no event and under no legal theory, whether in tort (including negligence),
147 | contract, or otherwise, unless required by applicable law (such as deliberate
148 | and grossly negligent acts) or agreed to in writing, shall any Contributor be
149 | liable to You for damages, including any direct, indirect, special, incidental,
150 | or consequential damages of any character arising as a result of this License or
151 | out of the use or inability to use the Work (including but not limited to
152 | damages for loss of goodwill, work stoppage, computer failure or malfunction, or
153 | any and all other commercial damages or losses), even if such Contributor has
154 | been advised of the possibility of such damages.
155 |
156 | 9. Accepting Warranty or Additional Liability.
157 |
158 | While redistributing the Work or Derivative Works thereof, You may choose to
159 | offer, and charge a fee for, acceptance of support, warranty, indemnity, or
160 | other liability obligations and/or rights consistent with this License. However,
161 | in accepting such obligations, You may act only on Your own behalf and on Your
162 | sole responsibility, not on behalf of any other Contributor, and only if You
163 | agree to indemnify, defend, and hold each Contributor harmless for any liability
164 | incurred by, or claims asserted against, such Contributor by reason of your
165 | accepting any such warranty or additional liability.
166 |
167 | END OF TERMS AND CONDITIONS
168 |
169 | APPENDIX: How to apply the Apache License to your work
170 |
171 | To apply the Apache License to your work, attach the following boilerplate
172 | notice, with the fields enclosed by brackets "{}" replaced with your own
173 | identifying information. (Don't include the brackets!) The text should be
174 | enclosed in the appropriate comment syntax for the file format. We also
175 | recommend that a file or class name and description of purpose be included on
176 | the same "printed page" as the copyright notice for easier identification within
177 | third-party archives.
178 |
179 | Copyright 2014 石头哥哥
180 |
181 | Licensed under the Apache License, Version 2.0 (the "License");
182 | you may not use this file except in compliance with the License.
183 | You may obtain a copy of the License at
184 |
185 | http://www.apache.org/licenses/LICENSE-2.0
186 |
187 | Unless required by applicable law or agreed to in writing, software
188 | distributed under the License is distributed on an "AS IS" BASIS,
189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190 | See the License for the specific language governing permissions and
191 | limitations under the License.
--------------------------------------------------------------------------------
/src/main/java/proto/TRoleEqu.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. @石头哥哥
3 | * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 | */
5 |
6 | package proto;
7 |
8 |
9 | import org.msgpack.annotation.Message;
10 |
11 | import java.io.Serializable;
12 |
13 | @Message
14 | public class TRoleEqu implements Serializable {
15 |
16 | private Integer equid = 0;
17 |
18 | private Integer equtypeid = 0;
19 |
20 | private Byte itemtype = 0;
21 |
22 | private Integer ownerid = 0;
23 |
24 | private Byte equpinzhi = 0;
25 |
26 | private Byte equpinjie = 0;
27 |
28 | private Integer equpinjieexp = 0;
29 |
30 | private Integer equlevel = 0;
31 |
32 | private Byte equtype = 0;
33 |
34 | private Byte equlocation = 0;
35 |
36 | private Long equtimeout = 0l;
37 |
38 | private Integer equprice = 0;
39 |
40 | private Boolean equshowbag = false;
41 |
42 | private Integer effecttype1 = 0;
43 |
44 | private Double effectnum1 = 0d;
45 |
46 | private Double effectnumgrowup1 = 0d;
47 |
48 | private Integer effecttype2 = 0;
49 |
50 | private Double effectnum2 = 0d;
51 |
52 | private Double effectnumgrowup2 = 0d;
53 |
54 | private Integer effecttype3 = 0;
55 |
56 | private Double effectnum3 = 0d;
57 |
58 | private Double effectnumgrowup3;
59 |
60 | private static final long serialVersionUID = 1L;
61 |
62 | public Integer getEquid() {
63 | return equid;
64 | }
65 |
66 | public void setEquid(Integer equid) {
67 | this.equid = equid;
68 | }
69 |
70 | public Integer getEqutypeid() {
71 | return equtypeid;
72 | }
73 |
74 | public void setEqutypeid(Integer equtypeid) {
75 | this.equtypeid = equtypeid;
76 | }
77 |
78 | public Byte getItemtype() {
79 | return itemtype;
80 | }
81 |
82 | public void setItemtype(Byte itemtype) {
83 | this.itemtype = itemtype;
84 | }
85 |
86 | public Integer getOwnerid() {
87 | return ownerid;
88 | }
89 |
90 | public void setOwnerid(Integer ownerid) {
91 | this.ownerid = ownerid;
92 | }
93 |
94 | public Byte getEqupinzhi() {
95 | return equpinzhi;
96 | }
97 |
98 | public void setEqupinzhi(Byte equpinzhi) {
99 | this.equpinzhi = equpinzhi;
100 | }
101 |
102 | public Byte getEqupinjie() {
103 | return equpinjie;
104 | }
105 |
106 | public void setEqupinjie(Byte equpinjie) {
107 | this.equpinjie = equpinjie;
108 | }
109 |
110 | public Integer getEqupinjieexp() {
111 | return equpinjieexp;
112 | }
113 |
114 | public void setEqupinjieexp(Integer equpinjieexp) {
115 | this.equpinjieexp = equpinjieexp;
116 | }
117 |
118 | public Integer getEqulevel() {
119 | return equlevel;
120 | }
121 |
122 | public void setEqulevel(Integer equlevel) {
123 | this.equlevel = equlevel;
124 | }
125 |
126 | public Byte getEqutype() {
127 | return equtype;
128 | }
129 |
130 | public void setEqutype(Byte equtype) {
131 | this.equtype = equtype;
132 | }
133 |
134 | public Byte getEqulocation() {
135 | return equlocation;
136 | }
137 |
138 | public void setEqulocation(Byte equlocation) {
139 | this.equlocation = equlocation;
140 | }
141 |
142 | public Long getEqutimeout() {
143 | return equtimeout;
144 | }
145 |
146 | public void setEqutimeout(Long equtimeout) {
147 | this.equtimeout = equtimeout;
148 | }
149 |
150 | public Integer getEquprice() {
151 | return equprice;
152 | }
153 |
154 | public void setEquprice(Integer equprice) {
155 | this.equprice = equprice;
156 | }
157 |
158 | public Boolean getEqushowbag() {
159 | return equshowbag;
160 | }
161 |
162 | public void setEqushowbag(Boolean equshowbag) {
163 | this.equshowbag = equshowbag;
164 | }
165 |
166 | public Integer getEffecttype1() {
167 | return effecttype1;
168 | }
169 |
170 | public void setEffecttype1(Integer effecttype1) {
171 | this.effecttype1 = effecttype1;
172 | }
173 |
174 | public Double getEffectnum1() {
175 | return effectnum1;
176 | }
177 |
178 | public void setEffectnum1(Double effectnum1) {
179 | this.effectnum1 = effectnum1;
180 | }
181 |
182 | public Double getEffectnumgrowup1() {
183 | return effectnumgrowup1;
184 | }
185 |
186 | public void setEffectnumgrowup1(Double effectnumgrowup1) {
187 | this.effectnumgrowup1 = effectnumgrowup1;
188 | }
189 |
190 | public Integer getEffecttype2() {
191 | return effecttype2;
192 | }
193 |
194 | public void setEffecttype2(Integer effecttype2) {
195 | this.effecttype2 = effecttype2;
196 | }
197 |
198 | public Double getEffectnum2() {
199 | return effectnum2;
200 | }
201 |
202 | public void setEffectnum2(Double effectnum2) {
203 | this.effectnum2 = effectnum2;
204 | }
205 |
206 | public Double getEffectnumgrowup2() {
207 | return effectnumgrowup2;
208 | }
209 |
210 | public void setEffectnumgrowup2(Double effectnumgrowup2) {
211 | this.effectnumgrowup2 = effectnumgrowup2;
212 | }
213 |
214 | public Integer getEffecttype3() {
215 | return effecttype3;
216 | }
217 |
218 | public void setEffecttype3(Integer effecttype3) {
219 | this.effecttype3 = effecttype3;
220 | }
221 |
222 | public Double getEffectnum3() {
223 | return effectnum3;
224 | }
225 |
226 | public void setEffectnum3(Double effectnum3) {
227 | this.effectnum3 = effectnum3;
228 | }
229 |
230 | public Double getEffectnumgrowup3() {
231 | return effectnumgrowup3;
232 | }
233 |
234 | public void setEffectnumgrowup3(Double effectnumgrowup3) {
235 | this.effectnumgrowup3 = effectnumgrowup3;
236 | }
237 |
238 | @Override
239 | public boolean equals(Object that) {
240 | if (this == that) {
241 | return true;
242 | }
243 | if (that == null) {
244 | return false;
245 | }
246 | if (getClass() != that.getClass()) {
247 | return false;
248 | }
249 | TRoleEqu other = (TRoleEqu) that;
250 | return (this.getEquid() == null ? other.getEquid() == null : this.getEquid().equals(other.getEquid()))
251 | && (this.getEqutypeid() == null ? other.getEqutypeid() == null : this.getEqutypeid().equals(other.getEqutypeid()))
252 | && (this.getItemtype() == null ? other.getItemtype() == null : this.getItemtype().equals(other.getItemtype()))
253 | && (this.getOwnerid() == null ? other.getOwnerid() == null : this.getOwnerid().equals(other.getOwnerid()))
254 | && (this.getEqupinzhi() == null ? other.getEqupinzhi() == null : this.getEqupinzhi().equals(other.getEqupinzhi()))
255 | && (this.getEqupinjie() == null ? other.getEqupinjie() == null : this.getEqupinjie().equals(other.getEqupinjie()))
256 | && (this.getEqupinjieexp() == null ? other.getEqupinjieexp() == null : this.getEqupinjieexp().equals(other.getEqupinjieexp()))
257 | && (this.getEqulevel() == null ? other.getEqulevel() == null : this.getEqulevel().equals(other.getEqulevel()))
258 | && (this.getEqutype() == null ? other.getEqutype() == null : this.getEqutype().equals(other.getEqutype()))
259 | && (this.getEqulocation() == null ? other.getEqulocation() == null : this.getEqulocation().equals(other.getEqulocation()))
260 | && (this.getEqutimeout() == null ? other.getEqutimeout() == null : this.getEqutimeout().equals(other.getEqutimeout()))
261 | && (this.getEquprice() == null ? other.getEquprice() == null : this.getEquprice().equals(other.getEquprice()))
262 | && (this.getEqushowbag() == null ? other.getEqushowbag() == null : this.getEqushowbag().equals(other.getEqushowbag()))
263 | && (this.getEffecttype1() == null ? other.getEffecttype1() == null : this.getEffecttype1().equals(other.getEffecttype1()))
264 | && (this.getEffectnum1() == null ? other.getEffectnum1() == null : this.getEffectnum1().equals(other.getEffectnum1()))
265 | && (this.getEffectnumgrowup1() == null ? other.getEffectnumgrowup1() == null : this.getEffectnumgrowup1().equals(other.getEffectnumgrowup1()))
266 | && (this.getEffecttype2() == null ? other.getEffecttype2() == null : this.getEffecttype2().equals(other.getEffecttype2()))
267 | && (this.getEffectnum2() == null ? other.getEffectnum2() == null : this.getEffectnum2().equals(other.getEffectnum2()))
268 | && (this.getEffectnumgrowup2() == null ? other.getEffectnumgrowup2() == null : this.getEffectnumgrowup2().equals(other.getEffectnumgrowup2()))
269 | && (this.getEffecttype3() == null ? other.getEffecttype3() == null : this.getEffecttype3().equals(other.getEffecttype3()))
270 | && (this.getEffectnum3() == null ? other.getEffectnum3() == null : this.getEffectnum3().equals(other.getEffectnum3()))
271 | && (this.getEffectnumgrowup3() == null ? other.getEffectnumgrowup3() == null : this.getEffectnumgrowup3().equals(other.getEffectnumgrowup3()));
272 | }
273 |
274 | @Override
275 | public int hashCode() {
276 | final int prime = 31;
277 | int result = 1;
278 | result = prime * result + ((getEquid() == null) ? 0 : getEquid().hashCode());
279 | result = prime * result + ((getEqutypeid() == null) ? 0 : getEqutypeid().hashCode());
280 | result = prime * result + ((getItemtype() == null) ? 0 : getItemtype().hashCode());
281 | result = prime * result + ((getOwnerid() == null) ? 0 : getOwnerid().hashCode());
282 | result = prime * result + ((getEqupinzhi() == null) ? 0 : getEqupinzhi().hashCode());
283 | result = prime * result + ((getEqupinjie() == null) ? 0 : getEqupinjie().hashCode());
284 | result = prime * result + ((getEqupinjieexp() == null) ? 0 : getEqupinjieexp().hashCode());
285 | result = prime * result + ((getEqulevel() == null) ? 0 : getEqulevel().hashCode());
286 | result = prime * result + ((getEqutype() == null) ? 0 : getEqutype().hashCode());
287 | result = prime * result + ((getEqulocation() == null) ? 0 : getEqulocation().hashCode());
288 | result = prime * result + ((getEqutimeout() == null) ? 0 : getEqutimeout().hashCode());
289 | result = prime * result + ((getEquprice() == null) ? 0 : getEquprice().hashCode());
290 | result = prime * result + ((getEqushowbag() == null) ? 0 : getEqushowbag().hashCode());
291 | result = prime * result + ((getEffecttype1() == null) ? 0 : getEffecttype1().hashCode());
292 | result = prime * result + ((getEffectnum1() == null) ? 0 : getEffectnum1().hashCode());
293 | result = prime * result + ((getEffectnumgrowup1() == null) ? 0 : getEffectnumgrowup1().hashCode());
294 | result = prime * result + ((getEffecttype2() == null) ? 0 : getEffecttype2().hashCode());
295 | result = prime * result + ((getEffectnum2() == null) ? 0 : getEffectnum2().hashCode());
296 | result = prime * result + ((getEffectnumgrowup2() == null) ? 0 : getEffectnumgrowup2().hashCode());
297 | result = prime * result + ((getEffecttype3() == null) ? 0 : getEffecttype3().hashCode());
298 | result = prime * result + ((getEffectnum3() == null) ? 0 : getEffectnum3().hashCode());
299 | result = prime * result + ((getEffectnumgrowup3() == null) ? 0 : getEffectnumgrowup3().hashCode());
300 | return result;
301 | }
302 | }
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 | 4.0.0
12 |
13 | springJredisCache
14 | springJredisCache
15 | 1.0-SNAPSHOT
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | ehcache
32 | local ehcache
33 | http://oss.sonatype.org/
34 |
35 | true
36 |
37 |
38 | false
39 |
40 |
41 |
42 |
43 | sonatype-snapshots
44 | sonatype snapshots repo
45 | https://oss.sonatype.org/content/repositories/snapshots
46 |
47 |
48 |
49 |
50 |
51 | sourceforge
52 | http://oss.sonatype.org/content/groups/sourceforge/
53 |
54 | true
55 |
56 |
57 | true
58 |
59 |
60 |
61 |
62 |
63 |
64 | springsource-repo
65 | SpringSource Repository
66 | http://repo.springsource.org/release
67 |
68 |
69 |
70 | spring-milestones
71 | http://maven.springframework.org/milestone/org/springframework/
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | org.springframework
81 | spring-beans
82 | 4.0.6.RELEASE
83 |
84 |
85 |
86 | org.springframework
87 | spring-context-support
88 | 4.0.6.RELEASE
89 |
90 |
91 |
92 | org.springframework
93 | spring-context
94 | 4.0.6.RELEASE
95 |
96 |
97 | org.springframework
98 | spring-core
99 | 4.0.6.RELEASE
100 |
101 |
102 | org.springframework
103 | spring-tx
104 | 4.0.6.RELEASE
105 |
106 |
107 |
108 | org.springframework
109 | spring-jdbc
110 | 4.0.6.RELEASE
111 |
112 |
113 |
114 |
115 | redis.clients
116 | jedis
117 | 2.5.1
118 |
119 |
120 |
121 |
122 | org.javolution
123 | javolution-core-java
124 | 6.0.0
125 |
126 |
127 |
128 |
129 | log4j
130 | log4j
131 | 1.2.17
132 |
133 |
134 |
135 |
136 | org.slf4j
137 | slf4j-api
138 | 1.7.3
139 |
140 |
141 |
142 | org.slf4j
143 | slf4j-log4j12
144 | 1.7.5
145 |
146 |
147 |
148 | org.slf4j
149 | jcl-over-slf4j
150 | 1.7.5
151 |
152 |
153 |
154 |
155 | io.netty
156 | netty-buffer
157 | 4.0.23.Final
158 |
159 |
160 |
161 | de.ruedigermoeller
162 | fst
163 | 2.05
164 |
165 |
166 |
167 | org.msgpack
168 | msgpack
169 | 0.6.11
170 |
171 |
172 |
173 |
174 | com.esotericsoftware.kryo
175 | kryo
176 | 2.24.0
177 |
178 |
179 |
180 | de.javakaffee
181 | kryo-serializers
182 | 0.27
183 |
184 |
185 |
186 |
187 | org.apache.directmemory
188 | directmemory-kryo
189 | 0.2
190 |
191 |
192 |
193 |
194 | org.objenesis
195 | objenesis
196 | 2.1
197 |
198 |
199 |
200 |
201 | com.google.protobuf
202 | protobuf-java
203 | 2.5.0
204 |
205 |
206 |
207 | commons-configuration
208 | commons-configuration
209 | 1.10
210 |
211 |
212 | commons-collections
213 | commons-collections
214 | 3.2.1
215 |
216 |
217 | commons-lang
218 | commons-lang
219 | 2.3
220 |
221 |
222 | commons-logging
223 | commons-logging
224 | 1.1.1
225 |
226 |
227 | commons-beanutils
228 | commons-beanutils
229 | 1.9.0
230 |
231 |
232 |
233 | junit
234 | junit
235 | 4.11
236 |
237 |
238 |
239 |
240 | springJredisCache
241 | src/main/java
242 |
243 |
244 | org.apache.maven.plugins
245 | maven-compiler-plugin
246 | 2.3.2
247 |
248 | 1.6
249 | 1.6
250 | UTF-8
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 | org.apache.maven.plugins
293 | maven-javadoc-plugin
294 | 2.7
295 |
296 |
297 | attach-javadoc
298 | package
299 |
300 | jar
301 |
302 |
303 |
304 |
305 | UTF-8
306 |
307 |
308 |
309 |
310 |
311 |
--------------------------------------------------------------------------------
/src/main/java/springJredisCache/JRedisSerializationUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. @石头哥哥
3 | * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 | */
5 |
6 | package springJredisCache;
7 |
8 |
9 | import com.esotericsoftware.kryo.Kryo;
10 | import com.esotericsoftware.kryo.io.Input;
11 | import com.esotericsoftware.kryo.io.Output;
12 | import com.google.protobuf.CodedInputStream;
13 | import com.google.protobuf.ExtensionRegistryLite;
14 | import com.google.protobuf.InvalidProtocolBufferException;
15 | import com.google.protobuf.MessageLite;
16 | import de.javakaffee.kryoserializers.*;
17 | import de.javakaffee.kryoserializers.cglib.CGLibProxySerializer;
18 | import javolution.util.FastTable;
19 | import org.msgpack.MessagePack;
20 | import org.nustaq.serialization.FSTObjectInput;
21 | import org.nustaq.serialization.FSTObjectOutput;
22 | import springJredisCache.Serializations.KryoThreadLocalSer;
23 |
24 | import java.io.*;
25 | import java.lang.reflect.InvocationHandler;
26 | import java.util.Arrays;
27 | import java.util.Collections;
28 | import java.util.GregorianCalendar;
29 |
30 | /**
31 | * @author 石头哥哥
32 | * dcserver1.3
33 | * Date:14-1-9
34 | * Time:下午4:00
35 | * Package:{@link springJredisCache}
36 | * Comment: 对象序列化工具类 序列化方案基于 FST - Fast Serialization
37 | * https://github.com/flapdoodle-oss/de.flapdoodle.fast-serialization
38 | *
39 | *
40 | * cache utils
41 | */
42 |
43 | public class JRedisSerializationUtils {
44 |
45 |
46 | public JRedisSerializationUtils() {
47 | }
48 |
49 |
50 | protected static boolean useKryoPool = false;
51 |
52 | // Serialize
53 | //-----------------------------------------------------------------------
54 |
55 | // In order to optimize object reuse and thread safety,
56 | // FSTConfiguration provides 2 simple factory methods to
57 | // obtain input/outputstream instances (they are stored thread local):
58 | //! reuse this Object, it caches metadata. Performance degrades massively
59 | //using createDefaultConfiguration() FSTConfiguration is singleton
60 |
61 | /**
62 | * Serializes an Object to a byte array for
63 | * storage/serialization.
64 | *
65 | * @param obj the object to serialize to bytes
66 | * @return a byte[] with the converted Serializable
67 | * @throws JRedisCacheException (runtime) if the serialization fails
68 | */
69 | public static byte[] fastSerialize(Object obj) {
70 | ByteArrayOutputStream byteArrayOutputStream = null;
71 | FSTObjectOutput out = null;
72 | try {
73 | // stream closed in the finally
74 | byteArrayOutputStream = new ByteArrayOutputStream(512);
75 | out = new FSTObjectOutput(byteArrayOutputStream); //32000 buffer size
76 | out.writeObject(obj);
77 | out.flush();
78 | return byteArrayOutputStream.toByteArray();
79 | } catch (IOException ex) {
80 | throw new JRedisCacheException(ex);
81 | } finally {
82 | try {
83 | obj = null;
84 | if (out != null) {
85 | out.close(); //call flush byte buffer
86 | out = null;
87 | }
88 | if (byteArrayOutputStream != null) {
89 |
90 | byteArrayOutputStream.close();
91 | byteArrayOutputStream = null;
92 | }
93 | } catch (IOException ex) {
94 | // ignore close exception
95 | }
96 | }
97 | }
98 | // Deserialize
99 | //-----------------------------------------------------------------------
100 |
101 | /**
102 | * Deserializes a single Object from an array of bytes.
103 | *
104 | * @param objectData the serialized object, must not be null
105 | * @return the deserialized object
106 | * @throws IllegalArgumentException if objectData is null
107 | * @throws JRedisCacheException (runtime) if the serialization fails
108 | */
109 | public static Object fastDeserialize(byte[] objectData) throws Exception {
110 | ByteArrayInputStream byteArrayInputStream = null;
111 | FSTObjectInput in = null;
112 | try {
113 | // stream closed in the finally
114 | byteArrayInputStream = new ByteArrayInputStream(objectData);
115 | in = new FSTObjectInput(byteArrayInputStream);
116 | return in.readObject();
117 | } catch (ClassNotFoundException ex) {
118 | throw new JRedisCacheException(ex);
119 | } catch (IOException ex) {
120 | throw new JRedisCacheException(ex);
121 | } finally {
122 | try {
123 | objectData = null;
124 | if (in != null) {
125 | in.close();
126 | in = null;
127 | }
128 | if (byteArrayInputStream != null) {
129 | byteArrayInputStream.close();
130 | byteArrayInputStream = null;
131 | }
132 | } catch (IOException ex) {
133 | // ignore close exception
134 | }
135 | }
136 | }
137 |
138 | /**
139 | * Kryo 的包装
140 | */
141 | private static class KryoHolder {
142 | private Kryo kryo;
143 | static final int BUFFER_SIZE = 1024;
144 | private Output output = new Output(BUFFER_SIZE, -1); //reuse
145 | private Input input = new Input();
146 |
147 | KryoHolder(Kryo kryo) {
148 | this.kryo = kryo;
149 | this.kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer());
150 | this.kryo.register(Collections.EMPTY_LIST.getClass(), new CollectionsEmptyListSerializer());
151 | this.kryo.register(Collections.EMPTY_MAP.getClass(), new CollectionsEmptyMapSerializer());
152 | this.kryo.register(Collections.EMPTY_SET.getClass(), new CollectionsEmptySetSerializer());
153 | this.kryo.register(Collections.singletonList("").getClass(), new CollectionsSingletonListSerializer());
154 | this.kryo.register(Collections.singleton("").getClass(), new CollectionsSingletonSetSerializer());
155 | this.kryo.register(Collections.singletonMap("", "").getClass(), new CollectionsSingletonMapSerializer());
156 | this.kryo.register(GregorianCalendar.class, new GregorianCalendarSerializer());
157 | this.kryo.register(InvocationHandler.class, new JdkProxySerializer());
158 | // register CGLibProxySerializer, works in combination with the appropriate action in handleUnregisteredClass (see below)
159 | this.kryo.register(CGLibProxySerializer.CGLibProxyMarker.class, new CGLibProxySerializer());
160 | UnmodifiableCollectionsSerializer.registerSerializers(this.kryo);
161 | SynchronizedCollectionsSerializer.registerSerializers(this.kryo);
162 |
163 |
164 | //其他第三方
165 | // // joda datetime
166 | // kryo.register(DateTime.class, new JodaDateTimeSerializer());
167 | // // wicket
168 | // kryo.register(MiniMap.class, new MiniMapSerializer());
169 | // // guava ImmutableList
170 | // ImmutableListSerializer.registerSerializers(kryo);
171 | }
172 |
173 | }
174 |
175 |
176 | interface KryoPool {
177 |
178 | /**
179 | * get o kryo object
180 | *
181 | * @return
182 | */
183 | KryoHolder get();
184 |
185 | /**
186 | * return object
187 | *
188 | * @param kryo
189 | */
190 | void offer(KryoHolder kryo);
191 | }
192 |
193 |
194 | //基于kryo序列换方案
195 |
196 | /**
197 | * 由于kryo创建的代价相对较高 ,这里使用空间换时间
198 | * 对KryoHolder对象进行重用
199 | * KryoHolder会出现峰值,应该不会造成内存泄漏哦
200 | */
201 | public static class KryoPoolImpl implements KryoPool {
202 | /**
203 | * default is 1500
204 | * online server limit 3K
205 | */
206 | // private static int DEFAULT_MAX_KRYO_SIZE = 1500;
207 |
208 | /**
209 | * thread safe list
210 | */
211 | private final FastTable kryoFastTable = new FastTable().atomic();
212 |
213 |
214 | /**
215 | *
216 | */
217 | private KryoPoolImpl() {
218 |
219 | }
220 |
221 | /**
222 | * @return
223 | */
224 | public static KryoPool getInstance() {
225 | return Singleton.pool;
226 | }
227 |
228 | /**
229 | * get o KryoHolder object
230 | *
231 | * @return
232 | */
233 | @Override
234 | public KryoHolder get() {
235 | KryoHolder kryoHolder = kryoFastTable.pollFirst(); // Retrieves and removes the head of the queue represented by this table
236 | return kryoHolder == null ? creatInstnce() : kryoHolder;
237 | }
238 |
239 | /**
240 | * create a new kryo object to application use
241 | *
242 | * @return
243 | */
244 | public KryoHolder creatInstnce() {
245 | Kryo kryo = new Kryo();
246 | kryo.setReferences(false);//
247 | return new KryoHolder(kryo);
248 | }
249 |
250 | /**
251 | * return object
252 | * Inserts the specified element at the tail of this queue.
253 | *
254 | * @param kryoHolder
255 | */
256 | @Override
257 | public void offer(KryoHolder kryoHolder) {
258 | kryoFastTable.addLast(kryoHolder);
259 | }
260 |
261 | /**
262 | * creat a Singleton
263 | */
264 | private static class Singleton {
265 | private static final KryoPool pool = new KryoPoolImpl();
266 | }
267 | }
268 |
269 |
270 | /**
271 | * 将对象序列化为字节数组
272 | *
273 | * @param obj
274 | * @return 字节数组
275 | * @throws JRedisCacheException
276 | */
277 | public static byte[] kryoSerialize(Object obj) throws JRedisCacheException {
278 |
279 | if (useKryoPool) {
280 | KryoHolder kryoHolder = null;
281 | if (obj == null) throw new JRedisCacheException("obj can not be null");
282 | try {
283 | kryoHolder = KryoPoolImpl.getInstance().get();
284 | kryoHolder.output.clear(); //clear Output -->每次调用的时候 重置
285 | kryoHolder.kryo.writeClassAndObject(kryoHolder.output, obj);
286 | return kryoHolder.output.toBytes();// 无法避免拷贝 ~~~
287 | } catch (JRedisCacheException e) {
288 | throw new JRedisCacheException("Serialize obj exception");
289 | } finally {
290 | KryoPoolImpl.getInstance().offer(kryoHolder);
291 | obj = null; //GC
292 | }
293 | } else {
294 | return KryoThreadLocalSer.getInstance().ObjSerialize(obj);
295 | }
296 |
297 | }
298 |
299 |
300 | /**
301 | * 将字节数组反序列化为对象
302 | *
303 | * @param bytes 字节数组
304 | * @return object
305 | * @throws JRedisCacheException
306 | */
307 | public static Object kryoDeserialize(byte[] bytes) throws JRedisCacheException {
308 | if (useKryoPool) {
309 | KryoHolder kryoHolder = null;
310 | if (bytes == null) throw new JRedisCacheException("bytes can not be null");
311 | try {
312 | kryoHolder = KryoPoolImpl.getInstance().get();
313 | kryoHolder.input.setBuffer(bytes, 0, bytes.length);//call it ,and then use input object ,discard any array
314 | return kryoHolder.kryo.readClassAndObject(kryoHolder.input);
315 | } catch (JRedisCacheException e) {
316 | throw new JRedisCacheException("Deserialize bytes exception");
317 | } finally {
318 | KryoPoolImpl.getInstance().offer(kryoHolder);
319 | bytes = null; // for gc
320 | }
321 | } else {
322 | return KryoThreadLocalSer.getInstance().ObjDeserialize(bytes);
323 | }
324 |
325 | }
326 |
327 |
328 | /**
329 | * 将字节数组反序列化为对象
330 | *
331 | * @param bytes 字节数组
332 | * @return object
333 | * @throws JRedisCacheException
334 | */
335 | public static Object kryoDeserialize(byte[] bytes, int length) throws JRedisCacheException {
336 | KryoHolder kryoHolder = null;
337 | if (bytes == null) throw new JRedisCacheException("bytes can not be null");
338 | try {
339 | kryoHolder = KryoPoolImpl.getInstance().get();
340 | kryoHolder.input.setBuffer(bytes, 0, length);//call it ,and then use input object ,discard any array
341 | return kryoHolder.kryo.readClassAndObject(kryoHolder.input);
342 | } catch (JRedisCacheException e) {
343 | throw new JRedisCacheException("Deserialize bytes exception");
344 | } finally {
345 | KryoPoolImpl.getInstance().offer(kryoHolder);
346 | bytes = null; // for gc
347 | }
348 | }
349 |
350 | private static final class MessagePackHolder {
351 | private MessagePack messagePack;
352 | static final int BUFFER_SIZE = 1024;
353 | private Output output = new Output(BUFFER_SIZE, -1); //reuse
354 | private Input in = new Input();
355 |
356 | public MessagePackHolder(MessagePack messagePack) {
357 | this.messagePack = messagePack;
358 | }
359 | }
360 |
361 | //基于messagePack的序列化方案
362 | interface MessagePackPool {
363 |
364 | /**
365 | * @return
366 | */
367 | MessagePackHolder get();
368 |
369 | /**
370 | * @param messagePack
371 | */
372 | void offer(MessagePackHolder messagePack);
373 |
374 |
375 | }
376 |
377 |
378 | private static final class MessagePackPoolImpl implements MessagePackPool {
379 |
380 | /**
381 | * atomic , thread safe list
382 | */
383 | private final FastTable messagePackFastTable = new FastTable().atomic();
384 |
385 | /**
386 | * @return
387 | */
388 | public static MessagePackPool getInstance() {
389 | return Singleton.pool;
390 | }
391 |
392 | private MessagePackPoolImpl() {
393 | }
394 |
395 | /**
396 | * @return
397 | */
398 | @Override
399 | public MessagePackHolder get() {
400 | MessagePackHolder messagePackHolder = messagePackFastTable.pollFirst();
401 | return messagePackHolder == null ? creatInstnce() : messagePackHolder;
402 | }
403 |
404 | /**
405 | * create a new kryo object to application use
406 | *
407 | * @return
408 | */
409 | private MessagePackHolder creatInstnce() {
410 | return new MessagePackHolder(new MessagePack());
411 | }
412 |
413 | /**
414 | * @param messagePackHolder
415 | */
416 | @Override
417 | public void offer(MessagePackHolder messagePackHolder) {
418 | if (messagePackHolder != null) messagePackFastTable.addLast(messagePackHolder);
419 | }
420 |
421 | /**
422 | * creat a Singleton
423 | */
424 | private static class Singleton {
425 | private static final MessagePackPool pool = new MessagePackPoolImpl();
426 | }
427 | }
428 |
429 |
430 | /**
431 | * 将对象序列化为字节数组
432 | *
433 | * @param obj
434 | * @return 字节数组
435 | * @throws JRedisCacheException
436 | */
437 | public static byte[] messagePackSerialize(Object obj) throws JRedisCacheException {
438 | MessagePackHolder messagePackHolder = null;
439 | if (obj == null) throw new JRedisCacheException("obj can not be null");
440 | try {
441 | messagePackHolder = MessagePackPoolImpl.getInstance().get();
442 | messagePackHolder.output.clear();
443 | messagePackHolder.messagePack.write(messagePackHolder.output, obj);
444 | return messagePackHolder.output.toBytes();
445 | } catch (JRedisCacheException e) {
446 | MessagePackPoolImpl.getInstance().offer(messagePackHolder);
447 | throw new JRedisCacheException("Serialize obj exception");
448 | } catch (IOException e) {
449 | MessagePackPoolImpl.getInstance().offer(messagePackHolder);
450 | return null;
451 | } finally {
452 | MessagePackPoolImpl.getInstance().offer(messagePackHolder);
453 | obj = null; //GC
454 | }
455 | }
456 |
457 |
458 | /**
459 | * 将字节数组反序列化为对象
460 | *
461 | * @param bytes 字节数组
462 | * @return object
463 | * @throws JRedisCacheException
464 | */
465 | public static Object messagePackDeserialize(byte[] bytes) throws JRedisCacheException {
466 | MessagePackHolder messagePackHolder = null;
467 | if (bytes == null) throw new JRedisCacheException("bytes can not be null");
468 | try {
469 | messagePackHolder = MessagePackPoolImpl.getInstance().get();
470 | messagePackHolder.in.setBuffer(bytes);
471 | return messagePackHolder.messagePack.read(messagePackHolder.in);
472 | } catch (JRedisCacheException e) {
473 | throw new JRedisCacheException("Deserialize bytes exception");
474 | } catch (IOException e) {
475 | MessagePackPoolImpl.getInstance().offer(messagePackHolder);
476 | return null;
477 | } finally {
478 | MessagePackPoolImpl.getInstance().offer(messagePackHolder);
479 | bytes = null;
480 | }
481 | }
482 |
483 |
484 | //jdk原生序列换方案
485 |
486 | /**
487 | * @param obj
488 | * @return
489 | */
490 | @Deprecated
491 | public static byte[] jserialize(Object obj) {
492 | ObjectOutputStream oos = null;
493 | ByteArrayOutputStream baos = null;
494 | try {
495 | baos = new ByteArrayOutputStream();
496 | oos = new ObjectOutputStream(baos);
497 | oos.writeObject(obj);
498 | return baos.toByteArray();
499 | } catch (IOException e) {
500 | throw new JRedisCacheException(e);
501 | } finally {
502 | if (oos != null)
503 | try {
504 | oos.close();
505 | baos.close();
506 | } catch (IOException e) {
507 | }
508 | }
509 | }
510 |
511 | /**
512 | * @param bits
513 | * @return
514 | */
515 | @Deprecated
516 | public static Object jdeserialize(byte[] bits) {
517 | ObjectInputStream ois = null;
518 | ByteArrayInputStream bais = null;
519 | try {
520 | bais = new ByteArrayInputStream(bits);
521 | ois = new ObjectInputStream(bais);
522 | return ois.readObject();
523 | } catch (Exception e) {
524 | throw new JRedisCacheException(e);
525 | } finally {
526 | if (ois != null)
527 | try {
528 | ois.close();
529 | bais.close();
530 | } catch (IOException e) {
531 | }
532 | }
533 | }
534 |
535 |
536 | // 基于protobuffer的序列化方案
537 |
538 | /**
539 | * @param bytes 字节数据
540 | * @param messageLite 序列化对应的类型
541 | * @return
542 | * @throws JRedisCacheException
543 | */
544 | public static MessageLite protoDeserialize(byte[] bytes, MessageLite messageLite) throws JRedisCacheException {
545 | assert (bytes != null && messageLite != null);
546 | try {
547 | return messageLite.getParserForType().parsePartialFrom(CodedInputStream.newInstance(bytes), ExtensionRegistryLite.getEmptyRegistry());
548 | } catch (InvalidProtocolBufferException e) {
549 | e.printStackTrace();
550 | return null;
551 | }
552 | }
553 |
554 | /**
555 | * @param messageLite 序列化对应的类型
556 | * @return
557 | * @throws JRedisCacheException
558 | */
559 | public static byte[] protoSerialize(MessageLite messageLite) throws JRedisCacheException {
560 | assert (messageLite != null);
561 | return messageLite.toByteArray();
562 | }
563 |
564 |
565 | }
566 |
--------------------------------------------------------------------------------
/src/main/java/proto/RoleVo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014. @石头哥哥
3 | * THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 | */
5 |
6 | // Generated by the protocol buffer compiler. DO NOT EDIT!
7 | // source: protoFile.proto
8 |
9 | package proto;
10 |
11 | /**
12 | * Protobuf type {@code proto.RoleVo}
13 | *
14 | *
15 | * 角色vo change!!!
16 | *
17 | */
18 | public final class RoleVo extends
19 | com.google.protobuf.GeneratedMessage implements
20 | // @@protoc_insertion_point(message_implements:proto.RoleVo)
21 | RoleVoOrBuilder {
22 | // Use RoleVo.newBuilder() to construct.
23 | private RoleVo(com.google.protobuf.GeneratedMessage.Builder> builder) {
24 | super(builder);
25 | this.unknownFields = builder.getUnknownFields();
26 | }
27 | private RoleVo(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }
28 |
29 | private static final RoleVo defaultInstance;
30 | public static RoleVo getDefaultInstance() {
31 | return defaultInstance;
32 | }
33 |
34 | public RoleVo getDefaultInstanceForType() {
35 | return defaultInstance;
36 | }
37 |
38 | private final com.google.protobuf.UnknownFieldSet unknownFields;
39 | @java.lang.Override
40 | public final com.google.protobuf.UnknownFieldSet
41 | getUnknownFields() {
42 | return this.unknownFields;
43 | }
44 | private RoleVo(
45 | com.google.protobuf.CodedInputStream input,
46 | com.google.protobuf.ExtensionRegistryLite extensionRegistry)
47 | throws com.google.protobuf.InvalidProtocolBufferException {
48 | initFields();
49 | int mutable_bitField0_ = 0;
50 | com.google.protobuf.UnknownFieldSet.Builder unknownFields =
51 | com.google.protobuf.UnknownFieldSet.newBuilder();
52 | try {
53 | boolean done = false;
54 | while (!done) {
55 | int tag = input.readTag();
56 | switch (tag) {
57 | case 0:
58 | done = true;
59 | break;
60 | default: {
61 | if (!parseUnknownField(input, unknownFields,
62 | extensionRegistry, tag)) {
63 | done = true;
64 | }
65 | break;
66 | }
67 | case 8: {
68 | bitField0_ |= 0x00000001;
69 | roleID_ = input.readUInt32();
70 | break;
71 | }
72 | case 18: {
73 | com.google.protobuf.ByteString bs = input.readBytes();
74 | bitField0_ |= 0x00000002;
75 | roleName_ = bs;
76 | break;
77 | }
78 | case 24: {
79 | bitField0_ |= 0x00000004;
80 | roleSex_ = input.readUInt32();
81 | break;
82 | }
83 | }
84 | }
85 | } catch (com.google.protobuf.InvalidProtocolBufferException e) {
86 | throw e.setUnfinishedMessage(this);
87 | } catch (java.io.IOException e) {
88 | throw new com.google.protobuf.InvalidProtocolBufferException(
89 | e.getMessage()).setUnfinishedMessage(this);
90 | } finally {
91 | this.unknownFields = unknownFields.build();
92 | makeExtensionsImmutable();
93 | }
94 | }
95 | public static final com.google.protobuf.Descriptors.Descriptor
96 | getDescriptor() {
97 | return proto.ProtoFile.internal_static_proto_RoleVo_descriptor;
98 | }
99 |
100 | protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
101 | internalGetFieldAccessorTable() {
102 | return proto.ProtoFile.internal_static_proto_RoleVo_fieldAccessorTable
103 | .ensureFieldAccessorsInitialized(
104 | proto.RoleVo.class, proto.RoleVo.Builder.class);
105 | }
106 |
107 | public static com.google.protobuf.Parser PARSER =
108 | new com.google.protobuf.AbstractParser() {
109 | public RoleVo parsePartialFrom(
110 | com.google.protobuf.CodedInputStream input,
111 | com.google.protobuf.ExtensionRegistryLite extensionRegistry)
112 | throws com.google.protobuf.InvalidProtocolBufferException {
113 | return new RoleVo(input, extensionRegistry);
114 | }
115 | };
116 |
117 | @java.lang.Override
118 | public com.google.protobuf.Parser getParserForType() {
119 | return PARSER;
120 | }
121 |
122 | private int bitField0_;
123 | public static final int ROLEID_FIELD_NUMBER = 1;
124 | private int roleID_;
125 | /**
126 | * required uint32 roleID = 1;
127 | *
128 | *
129 | *角色ID
130 | *
131 | */
132 | public boolean hasRoleID() {
133 | return ((bitField0_ & 0x00000001) == 0x00000001);
134 | }
135 | /**
136 | * required uint32 roleID = 1;
137 | *
138 | *
139 | *角色ID
140 | *
141 | */
142 | public int getRoleID() {
143 | return roleID_;
144 | }
145 |
146 | public static final int ROLENAME_FIELD_NUMBER = 2;
147 | private java.lang.Object roleName_;
148 | /**
149 | * optional string roleName = 2;
150 | *
151 | *
152 | *角色名称
153 | *
154 | */
155 | public boolean hasRoleName() {
156 | return ((bitField0_ & 0x00000002) == 0x00000002);
157 | }
158 | /**
159 | * optional string roleName = 2;
160 | *
161 | *
162 | *角色名称
163 | *
164 | */
165 | public java.lang.String getRoleName() {
166 | java.lang.Object ref = roleName_;
167 | if (ref instanceof java.lang.String) {
168 | return (java.lang.String) ref;
169 | } else {
170 | com.google.protobuf.ByteString bs =
171 | (com.google.protobuf.ByteString) ref;
172 | java.lang.String s = bs.toStringUtf8();
173 | if (bs.isValidUtf8()) {
174 | roleName_ = s;
175 | }
176 | return s;
177 | }
178 | }
179 | /**
180 | * optional string roleName = 2;
181 | *
182 | *
183 | *角色名称
184 | *
185 | */
186 | public com.google.protobuf.ByteString
187 | getRoleNameBytes() {
188 | java.lang.Object ref = roleName_;
189 | if (ref instanceof java.lang.String) {
190 | com.google.protobuf.ByteString b =
191 | com.google.protobuf.ByteString.copyFromUtf8(
192 | (java.lang.String) ref);
193 | roleName_ = b;
194 | return b;
195 | } else {
196 | return (com.google.protobuf.ByteString) ref;
197 | }
198 | }
199 |
200 | public static final int ROLESEX_FIELD_NUMBER = 3;
201 | private int roleSex_;
202 | /**
203 | * optional uint32 roleSex = 3;
204 | *
205 | *
206 | *角色性别
207 | *
208 | */
209 | public boolean hasRoleSex() {
210 | return ((bitField0_ & 0x00000004) == 0x00000004);
211 | }
212 | /**
213 | * optional uint32 roleSex = 3;
214 | *
215 | *
216 | *角色性别
217 | *
218 | */
219 | public int getRoleSex() {
220 | return roleSex_;
221 | }
222 |
223 | private void initFields() {
224 | roleID_ = 0;
225 | roleName_ = "";
226 | roleSex_ = 0;
227 | }
228 | private byte memoizedIsInitialized = -1;
229 | public final boolean isInitialized() {
230 | byte isInitialized = memoizedIsInitialized;
231 | if (isInitialized == 1) return true;
232 | if (isInitialized == 0) return false;
233 |
234 | if (!hasRoleID()) {
235 | memoizedIsInitialized = 0;
236 | return false;
237 | }
238 | memoizedIsInitialized = 1;
239 | return true;
240 | }
241 |
242 | public void writeTo(com.google.protobuf.CodedOutputStream output)
243 | throws java.io.IOException {
244 | getSerializedSize();
245 | if (((bitField0_ & 0x00000001) == 0x00000001)) {
246 | output.writeUInt32(1, roleID_);
247 | }
248 | if (((bitField0_ & 0x00000002) == 0x00000002)) {
249 | output.writeBytes(2, getRoleNameBytes());
250 | }
251 | if (((bitField0_ & 0x00000004) == 0x00000004)) {
252 | output.writeUInt32(3, roleSex_);
253 | }
254 | getUnknownFields().writeTo(output);
255 | }
256 |
257 | private int memoizedSerializedSize = -1;
258 | public int getSerializedSize() {
259 | int size = memoizedSerializedSize;
260 | if (size != -1) return size;
261 |
262 | size = 0;
263 | if (((bitField0_ & 0x00000001) == 0x00000001)) {
264 | size += com.google.protobuf.CodedOutputStream
265 | .computeUInt32Size(1, roleID_);
266 | }
267 | if (((bitField0_ & 0x00000002) == 0x00000002)) {
268 | size += com.google.protobuf.CodedOutputStream
269 | .computeBytesSize(2, getRoleNameBytes());
270 | }
271 | if (((bitField0_ & 0x00000004) == 0x00000004)) {
272 | size += com.google.protobuf.CodedOutputStream
273 | .computeUInt32Size(3, roleSex_);
274 | }
275 | size += getUnknownFields().getSerializedSize();
276 | memoizedSerializedSize = size;
277 | return size;
278 | }
279 |
280 | private static final long serialVersionUID = 0L;
281 | @java.lang.Override
282 | protected java.lang.Object writeReplace()
283 | throws java.io.ObjectStreamException {
284 | return super.writeReplace();
285 | }
286 |
287 | public static proto.RoleVo parseFrom(
288 | com.google.protobuf.ByteString data)
289 | throws com.google.protobuf.InvalidProtocolBufferException {
290 | return PARSER.parseFrom(data);
291 | }
292 | public static proto.RoleVo parseFrom(
293 | com.google.protobuf.ByteString data,
294 | com.google.protobuf.ExtensionRegistryLite extensionRegistry)
295 | throws com.google.protobuf.InvalidProtocolBufferException {
296 | return PARSER.parseFrom(data, extensionRegistry);
297 | }
298 | public static proto.RoleVo parseFrom(byte[] data)
299 | throws com.google.protobuf.InvalidProtocolBufferException {
300 | return PARSER.parseFrom(data);
301 | }
302 | public static proto.RoleVo parseFrom(
303 | byte[] data,
304 | com.google.protobuf.ExtensionRegistryLite extensionRegistry)
305 | throws com.google.protobuf.InvalidProtocolBufferException {
306 | return PARSER.parseFrom(data, extensionRegistry);
307 | }
308 | public static proto.RoleVo parseFrom(java.io.InputStream input)
309 | throws java.io.IOException {
310 | return PARSER.parseFrom(input);
311 | }
312 | public static proto.RoleVo parseFrom(
313 | java.io.InputStream input,
314 | com.google.protobuf.ExtensionRegistryLite extensionRegistry)
315 | throws java.io.IOException {
316 | return PARSER.parseFrom(input, extensionRegistry);
317 | }
318 | public static proto.RoleVo parseDelimitedFrom(java.io.InputStream input)
319 | throws java.io.IOException {
320 | return PARSER.parseDelimitedFrom(input);
321 | }
322 | public static proto.RoleVo parseDelimitedFrom(
323 | java.io.InputStream input,
324 | com.google.protobuf.ExtensionRegistryLite extensionRegistry)
325 | throws java.io.IOException {
326 | return PARSER.parseDelimitedFrom(input, extensionRegistry);
327 | }
328 | public static proto.RoleVo parseFrom(
329 | com.google.protobuf.CodedInputStream input)
330 | throws java.io.IOException {
331 | return PARSER.parseFrom(input);
332 | }
333 | public static proto.RoleVo parseFrom(
334 | com.google.protobuf.CodedInputStream input,
335 | com.google.protobuf.ExtensionRegistryLite extensionRegistry)
336 | throws java.io.IOException {
337 | return PARSER.parseFrom(input, extensionRegistry);
338 | }
339 |
340 | public static Builder newBuilder() { return Builder.create(); }
341 | public Builder newBuilderForType() { return newBuilder(); }
342 | public static Builder newBuilder(proto.RoleVo prototype) {
343 | return newBuilder().mergeFrom(prototype);
344 | }
345 | public Builder toBuilder() { return newBuilder(this); }
346 |
347 | @java.lang.Override
348 | protected Builder newBuilderForType(
349 | com.google.protobuf.GeneratedMessage.BuilderParent parent) {
350 | Builder builder = new Builder(parent);
351 | return builder;
352 | }
353 | /**
354 | * Protobuf type {@code proto.RoleVo}
355 | *
356 | *
357 | * 角色vo change!!!
358 | *
359 | */
360 | public static final class Builder extends
361 | com.google.protobuf.GeneratedMessage.Builder implements
362 | // @@protoc_insertion_point(builder_implements:proto.RoleVo)
363 | proto.RoleVoOrBuilder {
364 | public static final com.google.protobuf.Descriptors.Descriptor
365 | getDescriptor() {
366 | return proto.ProtoFile.internal_static_proto_RoleVo_descriptor;
367 | }
368 |
369 | protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
370 | internalGetFieldAccessorTable() {
371 | return proto.ProtoFile.internal_static_proto_RoleVo_fieldAccessorTable
372 | .ensureFieldAccessorsInitialized(
373 | proto.RoleVo.class, proto.RoleVo.Builder.class);
374 | }
375 |
376 | // Construct using proto.RoleVo.newBuilder()
377 | private Builder() {
378 | maybeForceBuilderInitialization();
379 | }
380 |
381 | private Builder(
382 | com.google.protobuf.GeneratedMessage.BuilderParent parent) {
383 | super(parent);
384 | maybeForceBuilderInitialization();
385 | }
386 | private void maybeForceBuilderInitialization() {
387 | if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
388 | }
389 | }
390 | private static Builder create() {
391 | return new Builder();
392 | }
393 |
394 | public Builder clear() {
395 | super.clear();
396 | roleID_ = 0;
397 | bitField0_ = (bitField0_ & ~0x00000001);
398 | roleName_ = "";
399 | bitField0_ = (bitField0_ & ~0x00000002);
400 | roleSex_ = 0;
401 | bitField0_ = (bitField0_ & ~0x00000004);
402 | return this;
403 | }
404 |
405 | public Builder clone() {
406 | return create().mergeFrom(buildPartial());
407 | }
408 |
409 | public com.google.protobuf.Descriptors.Descriptor
410 | getDescriptorForType() {
411 | return proto.ProtoFile.internal_static_proto_RoleVo_descriptor;
412 | }
413 |
414 | public proto.RoleVo getDefaultInstanceForType() {
415 | return proto.RoleVo.getDefaultInstance();
416 | }
417 |
418 | public proto.RoleVo build() {
419 | proto.RoleVo result = buildPartial();
420 | if (!result.isInitialized()) {
421 | throw newUninitializedMessageException(result);
422 | }
423 | return result;
424 | }
425 |
426 | public proto.RoleVo buildPartial() {
427 | proto.RoleVo result = new proto.RoleVo(this);
428 | int from_bitField0_ = bitField0_;
429 | int to_bitField0_ = 0;
430 | if (((from_bitField0_ & 0x00000001) == 0x00000001)) {
431 | to_bitField0_ |= 0x00000001;
432 | }
433 | result.roleID_ = roleID_;
434 | if (((from_bitField0_ & 0x00000002) == 0x00000002)) {
435 | to_bitField0_ |= 0x00000002;
436 | }
437 | result.roleName_ = roleName_;
438 | if (((from_bitField0_ & 0x00000004) == 0x00000004)) {
439 | to_bitField0_ |= 0x00000004;
440 | }
441 | result.roleSex_ = roleSex_;
442 | result.bitField0_ = to_bitField0_;
443 | onBuilt();
444 | return result;
445 | }
446 |
447 | public Builder mergeFrom(com.google.protobuf.Message other) {
448 | if (other instanceof proto.RoleVo) {
449 | return mergeFrom((proto.RoleVo)other);
450 | } else {
451 | super.mergeFrom(other);
452 | return this;
453 | }
454 | }
455 |
456 | public Builder mergeFrom(proto.RoleVo other) {
457 | if (other == proto.RoleVo.getDefaultInstance()) return this;
458 | if (other.hasRoleID()) {
459 | setRoleID(other.getRoleID());
460 | }
461 | if (other.hasRoleName()) {
462 | bitField0_ |= 0x00000002;
463 | roleName_ = other.roleName_;
464 | onChanged();
465 | }
466 | if (other.hasRoleSex()) {
467 | setRoleSex(other.getRoleSex());
468 | }
469 | this.mergeUnknownFields(other.getUnknownFields());
470 | return this;
471 | }
472 |
473 | public final boolean isInitialized() {
474 | if (!hasRoleID()) {
475 |
476 | return false;
477 | }
478 | return true;
479 | }
480 |
481 | public Builder mergeFrom(
482 | com.google.protobuf.CodedInputStream input,
483 | com.google.protobuf.ExtensionRegistryLite extensionRegistry)
484 | throws java.io.IOException {
485 | proto.RoleVo parsedMessage = null;
486 | try {
487 | parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
488 | } catch (com.google.protobuf.InvalidProtocolBufferException e) {
489 | parsedMessage = (proto.RoleVo) e.getUnfinishedMessage();
490 | throw e;
491 | } finally {
492 | if (parsedMessage != null) {
493 | mergeFrom(parsedMessage);
494 | }
495 | }
496 | return this;
497 | }
498 | private int bitField0_;
499 |
500 | private int roleID_ ;
501 | /**
502 | * required uint32 roleID = 1;
503 | *
504 | *
505 | *角色ID
506 | *
507 | */
508 | public boolean hasRoleID() {
509 | return ((bitField0_ & 0x00000001) == 0x00000001);
510 | }
511 | /**
512 | * required uint32 roleID = 1;
513 | *
514 | *
515 | *角色ID
516 | *
517 | */
518 | public int getRoleID() {
519 | return roleID_;
520 | }
521 | /**
522 | * required uint32 roleID = 1;
523 | *
524 | *
525 | *角色ID
526 | *
527 | */
528 | public Builder setRoleID(int value) {
529 | bitField0_ |= 0x00000001;
530 | roleID_ = value;
531 | onChanged();
532 | return this;
533 | }
534 | /**
535 | * required uint32 roleID = 1;
536 | *
537 | *
538 | *角色ID
539 | *
540 | */
541 | public Builder clearRoleID() {
542 | bitField0_ = (bitField0_ & ~0x00000001);
543 | roleID_ = 0;
544 | onChanged();
545 | return this;
546 | }
547 |
548 | private java.lang.Object roleName_ = "";
549 | /**
550 | * optional string roleName = 2;
551 | *
552 | *
553 | *角色名称
554 | *
555 | */
556 | public boolean hasRoleName() {
557 | return ((bitField0_ & 0x00000002) == 0x00000002);
558 | }
559 | /**
560 | * optional string roleName = 2;
561 | *
562 | *
563 | *角色名称
564 | *
565 | */
566 | public java.lang.String getRoleName() {
567 | java.lang.Object ref = roleName_;
568 | if (!(ref instanceof java.lang.String)) {
569 | com.google.protobuf.ByteString bs =
570 | (com.google.protobuf.ByteString) ref;
571 | java.lang.String s = bs.toStringUtf8();
572 | if (bs.isValidUtf8()) {
573 | roleName_ = s;
574 | }
575 | return s;
576 | } else {
577 | return (java.lang.String) ref;
578 | }
579 | }
580 | /**
581 | * optional string roleName = 2;
582 | *
583 | *
584 | *角色名称
585 | *
586 | */
587 | public com.google.protobuf.ByteString
588 | getRoleNameBytes() {
589 | java.lang.Object ref = roleName_;
590 | if (ref instanceof String) {
591 | com.google.protobuf.ByteString b =
592 | com.google.protobuf.ByteString.copyFromUtf8(
593 | (java.lang.String) ref);
594 | roleName_ = b;
595 | return b;
596 | } else {
597 | return (com.google.protobuf.ByteString) ref;
598 | }
599 | }
600 | /**
601 | * optional string roleName = 2;
602 | *
603 | *
604 | *角色名称
605 | *
606 | */
607 | public Builder setRoleName(
608 | java.lang.String value) {
609 | if (value == null) {
610 | throw new NullPointerException();
611 | }
612 | bitField0_ |= 0x00000002;
613 | roleName_ = value;
614 | onChanged();
615 | return this;
616 | }
617 | /**
618 | * optional string roleName = 2;
619 | *
620 | *
621 | *角色名称
622 | *
623 | */
624 | public Builder clearRoleName() {
625 | bitField0_ = (bitField0_ & ~0x00000002);
626 | roleName_ = getDefaultInstance().getRoleName();
627 | onChanged();
628 | return this;
629 | }
630 | /**
631 | * optional string roleName = 2;
632 | *
633 | *
634 | *角色名称
635 | *
636 | */
637 | public Builder setRoleNameBytes(
638 | com.google.protobuf.ByteString value) {
639 | if (value == null) {
640 | throw new NullPointerException();
641 | }
642 | bitField0_ |= 0x00000002;
643 | roleName_ = value;
644 | onChanged();
645 | return this;
646 | }
647 |
648 | private int roleSex_ ;
649 | /**
650 | * optional uint32 roleSex = 3;
651 | *
652 | *
653 | *角色性别
654 | *
655 | */
656 | public boolean hasRoleSex() {
657 | return ((bitField0_ & 0x00000004) == 0x00000004);
658 | }
659 | /**
660 | * optional uint32 roleSex = 3;
661 | *
662 | *
663 | *角色性别
664 | *
665 | */
666 | public int getRoleSex() {
667 | return roleSex_;
668 | }
669 | /**
670 | * optional uint32 roleSex = 3;
671 | *
672 | *
673 | *角色性别
674 | *
675 | */
676 | public Builder setRoleSex(int value) {
677 | bitField0_ |= 0x00000004;
678 | roleSex_ = value;
679 | onChanged();
680 | return this;
681 | }
682 | /**
683 | * optional uint32 roleSex = 3;
684 | *
685 | *
686 | *角色性别
687 | *
688 | */
689 | public Builder clearRoleSex() {
690 | bitField0_ = (bitField0_ & ~0x00000004);
691 | roleSex_ = 0;
692 | onChanged();
693 | return this;
694 | }
695 |
696 | // @@protoc_insertion_point(builder_scope:proto.RoleVo)
697 | }
698 |
699 | static {
700 | defaultInstance = new RoleVo(true);
701 | defaultInstance.initFields();
702 | }
703 |
704 | // @@protoc_insertion_point(class_scope:proto.RoleVo)
705 | }
706 |
707 |
--------------------------------------------------------------------------------
/redis1/readme.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright (c) 2014. @\u77F3\u5934\u54E5\u54E5
3 | # THIS SOFTWARE IS PROVIDED BY THE FREEBSD PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4 | #
5 |
6 | #\u8F93\u5165\u547D\u4EE4\uFF1Aredis-server.exe redis.conf
7 | #\u8BBE\u7F6E\u5BA2\u6237\u7AEF\uFF1A
8 | #\u8F93\u5165\u547D\u4EE4\uFF1Aredis-cli.exe -h IP -p \u7AEF\u53E3
9 | #\u6027\u80FD\u6D4B\u8BD5\uFF1A
10 | #\u8F93\u5165\u547D\u4EE4\uFF1Aredis-benchmark.exe -h IP-p \u7AEF\u53E3 -n \u8BF7\u6C42\u6570 -c \u5BA2\u6237\u8FDE\u63A5\u6570
11 |
12 | #redis-server\uFF1ARedis\u670D\u52A1\u5668\u7684daemon\u542F\u52A8\u7A0B\u5E8F
13 | #redis-cli\uFF1ARedis\u547D\u4EE4\u884C\u64CD\u4F5C\u5DE5\u5177\u3002\u5F53\u7136\uFF0C\u4F60\u4E5F\u53EF\u4EE5\u7528telnet\u6839\u636E\u5176\u7EAF\u6587\u672C\u534F\u8BAE\u6765\u64CD\u4F5C
14 | #redis-benchmark\uFF1ARedis\u6027\u80FD\u6D4B\u8BD5\u5DE5\u5177\uFF0C\u6D4B\u8BD5Redis\u5728\u4F60\u7684\u7CFB\u7EDF\u53CA\u4F60\u7684\u914D\u7F6E\u4E0B\u7684\u8BFB\u5199\u6027\u80FD
15 | #redis-stat\uFF1ARedis\u72B6\u6001\u68C0\u6D4B\u5DE5\u5177\uFF0C\u53EF\u4EE5\u68C0\u6D4BRedis\u5F53\u524D\u72B6\u6001\u53C2\u6570\u53CA\u5EF6\u8FDF\u72B6\u51B5
16 |
17 |
18 | #redis.conf\u914D\u7F6E\u6587\u4EF6\u6CE8\u89E3\uFF08\u539F\u6587\u5730\u5740\uFF09\uFF1A
19 | #daemonize\u662F\u5426\u4EE5\u540E\u53F0\u8FDB\u7A0B\u8FD0\u884C\uFF0C\u9ED8\u8BA4\u4E3Ano
20 | #pidfile\u5982\u4EE5\u540E\u53F0\u8FDB\u7A0B\u8FD0\u884C\uFF0C\u5219\u9700\u6307\u5B9A\u4E00\u4E2Apid\uFF0C\u9ED8\u8BA4\u4E3A/var/run/redis.pid
21 | #bind\u7ED1\u5B9A\u4E3B\u673AIP\uFF0C\u9ED8\u8BA4\u503C\u4E3A127.0.0.1\uFF08\u6CE8\u91CA\uFF09
22 | #port \u76D1\u542C\u7AEF\u53E3\uFF0C\u9ED8\u8BA4\u4E3A6379
23 | #timeout\u8D85\u65F6\u65F6\u95F4\uFF0C\u9ED8\u8BA4\u4E3A300\uFF08\u79D2\uFF09
24 | #loglevel\u65E5\u5FD7\u8BB0\u5F55\u7B49\u7EA7\uFF0C\u67094\u4E2A\u53EF\u9009\u503C\uFF0Cdebug\uFF0Cverbose\uFF08\u9ED8\u8BA4\u503C\uFF09\uFF0Cnotice\uFF0Cwarning
25 | #logfile\u65E5\u5FD7\u8BB0\u5F55\u65B9\u5F0F\uFF0C\u9ED8\u8BA4\u503C\u4E3Astdout
26 | #databases\u53EF\u7528\u6570\u636E\u5E93\u6570\uFF0C\u9ED8\u8BA4\u503C\u4E3A16\uFF0C\u9ED8\u8BA4\u6570\u636E\u5E93\u4E3A0
27 | #save\u6307\u51FA\u5728\u591A\u957F\u65F6\u95F4\u5185\uFF0C\u6709\u591A\u5C11\u6B21\u66F4\u65B0\u64CD\u4F5C\uFF0C\u5C31\u5C06\u6570\u636E\u540C\u6B65\u5230\u6570\u636E\u6587\u4EF6\u3002\u8FD9\u4E2A\u53EF\u4EE5\u591A\u4E2A\u6761\u4EF6\u914D\u5408\uFF0C\u6BD4\u5982\u9ED8\u8BA4\u914D\u7F6E\u6587\u4EF6\u4E2D\u7684\u8BBE\u7F6E\uFF0C\u5C31\u8BBE\u7F6E\u4E86\u4E09\u4E2A\u6761\u4EF6\u3002
28 | #save 900 1 900\u79D2\uFF0815\u5206\u949F\uFF09\u5185\u81F3\u5C11\u67091\u4E2Akey\u88AB\u6539\u53D8
29 | #save 300 10 300\u79D2\uFF085\u5206\u949F\uFF09\u5185\u81F3\u5C11\u6709300\u4E2Akey\u88AB\u6539\u53D8
30 | #save 60 10000 60\u79D2\u5185\u81F3\u5C11\u670910000\u4E2Akey\u88AB\u6539\u53D8
31 | #rdbcompression\u5B58\u50A8\u81F3\u672C\u5730\u6570\u636E\u5E93\u65F6\u662F\u5426\u538B\u7F29\u6570\u636E\uFF0C\u9ED8\u8BA4\u4E3Ayes
32 | #dbfilename\u672C\u5730\u6570\u636E\u5E93\u6587\u4EF6\u540D\uFF0C\u9ED8\u8BA4\u503C\u4E3Adump.rdb
33 | #dir \u672C\u5730\u6570\u636E\u5E93\u5B58\u653E\u8DEF\u5F84\uFF0C\u9ED8\u8BA4\u503C\u4E3A./
34 | #slaveof\u5F53\u672C\u673A\u4E3A\u4ECE\u670D\u52A1\u65F6\uFF0C\u8BBE\u7F6E\u4E3B\u670D\u52A1\u7684IP\u53CA\u7AEF\u53E3\uFF08\u6CE8\u91CA\uFF09
35 | #masterauth\u5F53\u672C\u673A\u4E3A\u4ECE\u670D\u52A1\u65F6\uFF0C\u8BBE\u7F6E\u4E3B\u670D\u52A1\u7684\u8FDE\u63A5\u5BC6\u7801\uFF08\u6CE8\u91CA\uFF09
36 | #requirepass\u8FDE\u63A5\u5BC6\u7801\uFF08\u6CE8\u91CA\uFF09
37 | #maxclients\u6700\u5927\u5BA2\u6237\u7AEF\u8FDE\u63A5\u6570\uFF0C\u9ED8\u8BA4\u4E0D\u9650\u5236\uFF08\u6CE8\u91CA\uFF09
38 | #maxmemory\u8BBE\u7F6E\u6700\u5927\u5185\u5B58\uFF0C\u8FBE\u5230\u6700\u5927\u5185\u5B58\u8BBE\u7F6E\u540E\uFF0CRedis\u4F1A\u5148\u5C1D\u8BD5\u6E05\u9664\u5DF2\u5230\u671F\u6216\u5373\u5C06\u5230\u671F\u7684Key\uFF0C\u5F53\u6B64\u65B9\u6CD5\u5904\u7406\u540E\uFF0C\u4EFB\u5230\u8FBE\u6700\u5927\u5185\u5B58\u8BBE\u7F6E\uFF0C\u5C06\u65E0\u6CD5\u518D\u8FDB\u884C\u5199\u5165\u64CD\u4F5C\u3002\uFF08\u6CE8\u91CA\uFF09
39 | #appendonly\u662F\u5426\u5728\u6BCF\u6B21\u66F4\u65B0\u64CD\u4F5C\u540E\u8FDB\u884C\u65E5\u5FD7\u8BB0\u5F55\uFF0C\u5982\u679C\u4E0D\u5F00\u542F\uFF0C\u53EF\u80FD\u4F1A\u5728\u65AD\u7535\u65F6\u5BFC\u81F4\u4E00\u6BB5\u65F6\u95F4\u5185\u7684\u6570\u636E\u4E22\u5931\u3002\u56E0\u4E3Aredis\u672C\u8EAB\u540C\u6B65\u6570\u636E\u6587\u4EF6\u662F\u6309\u4E0A\u9762save\u6761\u4EF6\u6765\u540C\u6B65\u7684\uFF0C\u6240\u4EE5\u6709\u7684\u6570\u636E\u4F1A\u5728\u4E00\u6BB5\u65F6\u95F4\u5185\u53EA\u5B58\u5728\u4E8E\u5185\u5B58\u4E2D\u3002\u9ED8\u8BA4\u503C\u4E3Ano
40 | #appendfilename\u66F4\u65B0\u65E5\u5FD7\u6587\u4EF6\u540D\uFF0C\u9ED8\u8BA4\u503C\u4E3Aappendonly.aof\uFF08\u6CE8\u91CA\uFF09
41 | #appendfsync\u66F4\u65B0\u65E5\u5FD7\u6761\u4EF6\uFF0C\u5171\u67093\u4E2A\u53EF\u9009\u503C\u3002no\u8868\u793A\u7B49\u64CD\u4F5C\u7CFB\u7EDF\u8FDB\u884C\u6570\u636E\u7F13\u5B58\u540C\u6B65\u5230\u78C1\u76D8\uFF0Calways\u8868\u793A\u6BCF\u6B21\u66F4\u65B0\u64CD\u4F5C\u540E\u624B\u52A8\u8C03\u7528fsync()\u5C06\u6570\u636E\u5199\u5230\u78C1\u76D8\uFF0Ceverysec\u8868\u793A\u6BCF\u79D2\u540C\u6B65\u4E00\u6B21\uFF08\u9ED8\u8BA4\u503C\uFF09\u3002
42 | #vm-enabled\u662F\u5426\u4F7F\u7528\u865A\u62DF\u5185\u5B58\uFF0C\u9ED8\u8BA4\u503C\u4E3Ano
43 | #vm-swap-file\u865A\u62DF\u5185\u5B58\u6587\u4EF6\u8DEF\u5F84\uFF0C\u9ED8\u8BA4\u503C\u4E3A/tmp/redis.swap\uFF0C\u4E0D\u53EF\u591A\u4E2ARedis\u5B9E\u4F8B\u5171\u4EAB
44 | #vm-max-memory\u5C06\u6240\u6709\u5927\u4E8Evm-max-memory\u7684\u6570\u636E\u5B58\u5165\u865A\u62DF\u5185\u5B58,\u65E0\u8BBAvm-max-memory\u8BBE\u7F6E\u591A\u5C0F,\u6240\u6709\u7D22\u5F15\u6570\u636E\u90FD\u662F\u5185\u5B58\u5B58\u50A8\u7684(Redis\u7684\u7D22\u5F15\u6570\u636E\u5C31\u662Fkeys),\u4E5F\u5C31\u662F\u8BF4,\u5F53vm-max-memory\u8BBE\u7F6E\u4E3A0\u7684\u65F6\u5019,\u5176\u5B9E\u662F\u6240\u6709value\u90FD\u5B58\u5728\u4E8E\u78C1\u76D8\u3002\u9ED8\u8BA4\u503C\u4E3A0\u3002
45 |
46 |
47 |
48 | #\u662F\u5426\u4EE5\u540E\u53F0\u8FDB\u7A0B\u8FD0\u884C\uFF0C\u9ED8\u8BA4\u4E3Ano\uFF0C\u5982\u679C\u9700\u8981\u4EE5\u540E\u53F0\u8FDB\u7A0B\u8FD0\u884C\u5219\u6539\u4E3Ayes
49 | daemonize no
50 |
51 |
52 | #\u5982\u679C\u4EE5\u540E\u53F0\u8FDB\u7A0B\u8FD0\u884C\u7684\u8BDD\uFF0C\u5C31\u9700\u8981\u6307\u5B9Apid\uFF0C\u4F60\u53EF\u4EE5\u5728\u6B64\u81EA\u5B9A\u4E49redis.pid\u6587\u4EF6\u7684\u4F4D\u7F6E\u3002
53 | pidfile /var/run/redis.pid
54 |
55 |
56 | #\u63A5\u53D7\u8FDE\u63A5\u7684\u7AEF\u53E3\u53F7\uFF0C\u5982\u679C\u7AEF\u53E3\u662F0\u5219redis\u5C06\u4E0D\u4F1A\u76D1\u542CTCP socket\u8FDE\u63A5
57 | port 6379
58 |
59 | # If you want you can bind a single interface, if the bind option is not
60 | # specified all the interfaces will listen for incoming connections.
61 | #
62 | # bind 127.0.0.1
63 |
64 | # Specify the path for the unix socket that will be used to listen for
65 | # incoming connections. There is no default, so Redis will not listen
66 | # on a unix socket when not specified.
67 | #
68 | # unixsocket /tmp/redis.sock
69 | # unixsocketperm 755
70 |
71 |
72 | #\u8FDE\u63A5\u8D85\u65F6\u65F6\u95F4\uFF0C\u5355\u4F4D\u79D2\u3002(0 to disable)\uFF1F
73 | timeout 300000000
74 | 16:34
75 |
76 | #\u65E5\u5FD7\u7EA7\u522B\uFF0C\u9ED8\u8BA4\u662Fverbose\uFF08\u8BE6\u7EC6\uFF09\uFF0C\u5404\u79CD\u65E5\u5FD7\u7EA7\u522B\uFF1A
77 | #debug:\u5F88\u8BE6\u7EC6\u7684\u4FE1\u606F\uFF0C\u9002\u5408\u5F00\u53D1\u548C\u6D4B\u8BD5
78 | #verbose:\u5305\u542B\u8BB8\u591A\u4E0D\u592A\u6709\u7528\u7684\u4FE1\u606F\uFF0C\u4F46\u6BD4debug\u8981\u6E05\u723D\u4E00\u4E9B\uFF08many rarely useful info, but not a mess like #the debug level\uFF09
79 | #notice:\u6BD4\u8F83\u9002\u5408\u751F\u4EA7\u73AF\u5883
80 | #warning:\u8B66\u544A\u4FE1\u606F
81 | loglevel verbose
82 |
83 |
84 | #\u6307\u5B9Alog\u6587\u4EF6\u7684\u540D\u5B57\uFF0C\u9ED8\u8BA4\u662Fstdout\u3002stdout\u4F1A\u8BA9redis\u628A\u65E5\u5FD7\u8F93\u51FA\u5230\u6807\u51C6\u8F93\u51FA\u3002\u4F46\u662F\u5982\u679C\u4F7F\u7528stdout\u800C\u53C8\u4EE5\u540E\u53F0\u8FDB#\u7A0B\u7684\u65B9\u5F0F\u8FD0\u884Credis\uFF0C\u5219\u65E5\u5FD7\u4F1A\u8F93\u51FA\u5230/dev/null
85 | logfile stdout
86 |
87 |
88 | #'syslog-enabled'\u8BBE\u7F6E\u4E3Ayes\u4F1A\u628A\u65E5\u5FD7\u8F93\u51FA\u5230\u7CFB\u7EDF\u65E5\u5FD7\uFF0C\u9ED8\u8BA4\u662Fno
89 | # syslog-enabled no
90 |
91 |
92 | #\u6307\u5B9Asyslog\u7684\u6807\u793A\u7B26\uFF0C\u5982\u679C'syslog-enabled'\u662Fno\uFF0C\u5219\u8FD9\u4E2A\u9009\u9879\u65E0\u6548\u3002
93 | # syslog-ident redis
94 |
95 |
96 | #\u6307\u5B9Asyslog \u8BBE\u5907\uFF08facility), \u5FC5\u987B\u662FUSER\u6216\u8005LOCAL0\u5230LOCAL7.
97 | # syslog-facility local0
98 |
99 |
100 | #\u8BBE\u7F6E\u6570\u636E\u5E93\u6570\u76EE\u3002\u9ED8\u8BA4\u7684\u6570\u636E\u5E93\u662FDB 0\u3002\u53EF\u4EE5\u901A\u8FC7SELECT \u6765\u9009\u62E9\u4E00\u4E2A\u6570\u636E\u5E93\uFF0Cdbid\u662F[0,'databases'-1]\u7684\u6570\u5B57
101 | databases 16
102 |
103 | ################## \u5FEB\u7167#################################
104 | #
105 | # \u786C\u76D8\u4E0A\u4FDD\u5B58\u6570\u636E:
106 | #
107 | # save
108 | #
109 | # \u548C\u90FD\u6EE1\u8DB3\u65F6\u5C31\u4F1A\u89E6\u53D1\u6570\u636E\u4FDD\u5B58\u52A8\u4F5C\u3002
110 | #
111 | #
112 | # \u4EE5\u4E0B\u9762\u7684\u4F8B\u5B50\u6765\u8BF4\u660E\uFF1A
113 | # \u8FC7\u4E86900\u79D2\u5E76\u4E14\u67091\u4E2Akey\u53D1\u751F\u4E86\u6539\u53D8 \u5C31\u4F1A\u89E6\u53D1save\u52A8\u4F5C
114 | # \u8FC7\u4E86300\u79D2\u5E76\u4E14\u670910\u4E2Akey\u53D1\u751F\u4E86\u6539\u53D8 \u5C31\u4F1A\u89E6\u53D1save\u52A8\u4F5C
115 | # \u8FC7\u4E8660\u79D2\u5E76\u4E14\u81F3\u5C11\u670910000\u4E2Akey\u53D1\u751F\u4E86\u6539\u53D8 \u4E5F\u4F1A\u89E6\u53D1save\u52A8\u4F5C
116 | #
117 | # \u6CE8\u610F\uFF1A\u5982\u679C\u4F60\u4E0D\u60F3\u8BA9redis\u81EA\u52A8\u4FDD\u5B58\u6570\u636E\uFF0C\u90A3\u5C31\u628A\u4E0B\u9762\u7684\u914D\u7F6E\u6CE8\u91CA\u6389\uFF01
118 |
119 | save 900 1
120 | save 300 10
121 | save 60 10000
122 |
123 |
124 | #\u5B58\u50A8\u6570\u636E\u65F6\u662F\u5426\u538B\u7F29\u6570\u636E\u3002\u9ED8\u8BA4\u662Fyes\u3002
125 | rdbcompression yes
126 |
127 | # \u4FDD\u5B58dump\u6570\u636E\u7684\u6587\u4EF6\u540D
128 | dbfilename dump.rdb
129 |
130 | # \u5DE5\u4F5C\u76EE\u5F55.
131 | #
132 | # \u6570\u636E\u4F1A\u88AB\u6301\u4E45\u5316\u5230\u8FD9\u4E2A\u76EE\u5F55\u4E0B\u7684\u2018dbfilename\u2019\u6307\u5B9A\u7684\u6587\u4EF6\u4E2D\u3002
133 | #
134 | #
135 | # \u6CE8\u610F\uFF0C\u8FD9\u91CC\u6307\u5B9A\u7684\u5FC5\u987B\u662F\u76EE\u5F55\u800C\u4E0D\u80FD\u662F\u6587\u4EF6\u3002
136 | dir ./
137 |
138 | ######## REPLICATION\uFF08\u590D\u5236\uFF0C\u5197\u4F59\uFF09#################################
139 |
140 | # Master-Slave replication. \u4F7F\u7528slaveof\u628A\u4E00\u4E2A Redis \u5B9E\u4F8B\u8BBE\u7F6E\u6210\u4E3A\u53E6\u4E00\u4E2ARedis server\u7684\u4ECE\u5E93\uFF08\u70ED\u5907\uFF09. \u6CE8\u610F\uFF1A #\u914D\u7F6E\u53EA\u5BF9\u5F53\u524Dslave\u6709\u6548\u3002
141 | # \u56E0\u6B64\u53EF\u4EE5\u628A\u67D0\u4E2Aslave\u914D\u7F6E\u6210\u4F7F\u7528\u4E0D\u540C\u7684\u65F6\u95F4\u95F4\u9694\u6765\u4FDD\u5B58\u6570\u636E\u6216\u8005\u76D1\u542C\u5176\u4ED6\u7AEF\u53E3\u7B49\u7B49\u3002
142 | #\u547D\u4EE4\u683C\u5F0F\uFF1A
143 | # slaveof
144 |
145 |
146 | #\u5982\u679Cmaster\u6709\u5BC6\u7801\u4FDD\u62A4\uFF0C\u5219\u5728slave\u4E0Emaster\u8FDB\u884C\u6570\u636E\u540C\u6B65\u4E4B\u524D\u9700\u8981\u8FDB\u884C\u5BC6\u7801\u6821\u9A8C\uFF0C\u5426\u5219master\u4F1A\u62D2\u7EDDslave\u7684\u8BF7#\u6C42\u3002
147 | #
148 | # masterauth
149 |
150 | #\u5F53slave\u4E22\u5931\u4E0Emaster\u7684\u8FDE\u63A5\u65F6\uFF0C\u6216\u8005slave\u4ECD\u7136\u5728\u4E8Emaster\u8FDB\u884C\u6570\u636E\u540C\u6B65\u65F6\uFF08\u8FD8\u6CA1\u6709\u4E0Emaster\u4FDD\u6301\u4E00\u81F4\uFF09\uFF0C#slave\u53EF\u4EE5\u6709\u4E24\u79CD\u65B9\u5F0F\u6765\u54CD\u5E94\u5BA2\u6237\u7AEF\u8BF7\u6C42\uFF1A
151 | #
152 | # 1) \u5982\u679C slave-serve-stale-data \u8BBE\u7F6E\u6210 'yes' (the default) slave\u4F1A\u4ECD\u7136\u54CD\u5E94\u5BA2\u6237\u7AEF\u8BF7\u6C42,\u6B64\u65F6\u53EF\u80FD\u4F1A\u6709\u95EE\u9898\u3002
153 | #
154 | # 2) \u5982\u679C slave-serve-stale data\u8BBE\u7F6E\u6210 'no' slave\u4F1A\u8FD4\u56DE"SYNC with master in progress"\u8FD9\u6837\u7684\u9519\u8BEF\u4FE1\u606F\u3002 \u4F46 INFO \u548CSLAVEOF\u547D\u4EE4\u9664\u5916\u3002
155 | #
156 | slave-serve-stale-data yes
157 |
158 | ############### \u5B89\u5168 ###################################
159 |
160 | # \u9700\u8981\u5BA2\u6237\u7AEF\u5728\u6267\u884C\u4EFB\u4F55\u547D\u4EE4\u4E4B\u524D\u6307\u5B9A AUTH
161 | #
162 | # requirepass foobared
163 |
164 | # \u547D\u4EE4\u91CD\u547D\u540D.
165 | #
166 | #
167 | # \u4F8B\u5982:
168 | #
169 | # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
170 | #
171 | # \u540C\u6837\u53EF\u4EE5\u901A\u8FC7\u628A\u4E00\u4E2A\u547D\u4EE4\u91CD\u547D\u540D\u4E3A\u7A7A\u4E32\u6765\u5F7B\u5E95kill\u6389\u8FD9\u4E2A\u547D\u4EE4\uFF0C\u6BD4\u5982\uFF1A
172 | #
173 | # rename-command CONFIG ""
174 |
175 | #################### \u9650\u5236 ####################################
176 |
177 | # \u8BBE\u7F6E\u6700\u5927\u8FDE\u63A5\u6570. \u9ED8\u8BA4\u6CA1\u6709\u9650\u5236, '0' \u610F\u5473\u7740\u4E0D\u9650\u5236.
178 | #
179 | # maxclients 128
180 |
181 |
182 | #\u6700\u5927\u53EF\u4F7F\u7528\u5185\u5B58\u3002\u5982\u679C\u8D85\u8FC7\uFF0CRedis\u4F1A\u8BD5\u56FE\u5220\u9664EXPIRE\u96C6\u5408\u4E2D\u7684keys\uFF0C\u5177\u4F53\u505A\u6CD5\u662F\uFF1ARedis\u4F1A\u8BD5\u56FE\u91CA\u653E\u5373\u5C06\u8FC7\u671F\u7684#keys\uFF0C\u800C\u4FDD\u62A4\u8FD8\u6709\u5F88\u957F\u751F\u547D\u5468\u671F\u7684keys\u3002
183 | #
184 | #\u5982\u679C\u8FD9\u6837\u8FD8\u4E0D\u884C\uFF0CRedis\u5C31\u4F1A\u62A5\u9519\uFF0C\u4F46\u50CFGET\u4E4B\u7C7B\u7684\u67E5\u8BE2\u8BF7\u6C42\u8FD8\u662F\u4F1A\u5F97\u5230\u54CD\u5E94\u3002
185 | #
186 | #\u8B66\u544A\uFF1A\u5982\u679C\u4F60\u60F3\u628ARedis\u89C6\u4E3A\u4E00\u4E2A\u771F\u6B63\u7684DB\u7684\u8BDD\uFF0C\u90A3\u4E0D\u8981\u8BBE\u7F6E,\u53EA\u6709\u4F60\u53EA\u60F3\u628ARedis\u4F5C\u4E3Acache\u6216\u8005
187 | #\u6709\u72B6\u6001\u7684server\uFF08'state' server)\u65F6\u624D\u9700\u8981\u8BBE\u7F6E\u3002
188 | #
189 | # maxmemory
190 |
191 | #\u5185\u5B58\u6E05\u7406\u7B56\u7565\uFF1A\u5982\u679C\u8FBE\u5230\u4E86maxmemory\uFF0C\u4F60\u53EF\u4EE5\u91C7\u53D6\u5982\u4E0B\u52A8\u4F5C\uFF1A
192 | #
193 | # volatile-lru -> \u4F7F\u7528LRU\u7B97\u6CD5\u6765\u5220\u9664\u8FC7\u671F\u7684set
194 | # allkeys-lru -> \u5220\u9664\u4EFB\u4F55\u9075\u5FAALRU\u7B97\u6CD5\u7684key
195 | # volatile-random ->\u968F\u673A\u5730\u5220\u9664\u8FC7\u671Fset\u4E2D\u7684key
196 | # allkeys->random -> \u968F\u673A\u5730\u5220\u9664\u4E00\u4E2Akey
197 | # volatile-ttl -> \u5220\u9664\u6700\u8FD1\u5373\u5C06\u8FC7\u671F\u7684key\uFF08the nearest expire time (minor TTL)\uFF09
198 | # noeviction -> \u6839\u672C\u4E0D\u8FC7\u671F\uFF0C\u5199\u64CD\u4F5C\u76F4\u63A5\u62A5\u9519
199 | #
200 | #
201 | # \u9ED8\u8BA4\u7B56\u7565:
202 | #
203 | # maxmemory-policy volatile-lru
204 |
205 | # \u5BF9\u4E8E\u5904\u7406redis\u5185\u5B58\u6765\u8BF4\uFF0CLRU\u548Cminor TTL\u7B97\u6CD5\u4E0D\u662F\u7CBE\u786E\u7684\uFF0C\u800C\u662F\u8FD1\u4F3C\u7684\uFF08\u4F30\u8BA1\u7684\uFF09\u7B97\u6CD5\u3002\u6240\u4EE5\u6211\u4EEC\u4F1A\u68C0\u67E5\u67D0\u4E9B\u6837\u672C#\u6765\u8FBE\u5230\u5185\u5B58\u68C0\u67E5\u7684\u76EE\u7684\u3002\u9ED8\u8BA4\u7684\u6837\u672C\u6570\u662F3\uFF0C\u4F60\u53EF\u4EE5\u4FEE\u6539\u5B83\u3002
206 | #
207 | # maxmemory-samples 3
208 |
209 | ################# APPEND ONLY MODE ###############################
210 |
211 | #\u9ED8\u8BA4\u60C5\u51B5\u4E0B\uFF0CRedis\u4F1A\u5F02\u6B65\u7684\u628A\u6570\u636E\u4FDD\u5B58\u5230\u786C\u76D8\u3002\u5982\u679C\u4F60\u7684\u5E94\u7528\u573A\u666F\u5141\u8BB8\u56E0\u4E3A\u7CFB\u7EDF\u5D29\u6E83\u7B49\u6781\u7AEF\u60C5\u51B5\u800C\u5BFC\u81F4\u6700\u65B0\u6570\u636E\u4E22\u5931#\u7684\u8BDD\uFF0C\u90A3\u8FD9\u79CD\u505A\u6CD5\u5DF2\u7ECF\u5F88ok\u4E86\u3002\u5426\u5219\u4F60\u5E94\u8BE5\u6253\u5F00\u2018append only\u2019\u6A21\u5F0F\uFF0C\u5F00\u542F\u8FD9\u79CD\u6A21\u5F0F\u540E\uFF0CRedis\u4F1A\u5728#appendonly.aof\u6587\u4EF6\u4E2D\u6DFB\u52A0\u6BCF\u4E00\u4E2A\u5199\u64CD\u4F5C\uFF0C\u8FD9\u4E2A\u6587\u4EF6\u4F1A\u5728Redis\u542F\u52A8\u65F6\u88AB\u8BFB\u53D6\u6765\u5728\u5185\u5B58\u4E2D\u91CD\u65B0\u6784\u5EFA\u6570\u636E\u96C6\u3002
212 | #
213 | #\u6CE8\u610F\uFF1A\u5982\u679C\u4F60\u9700\u8981\uFF0C\u4F60\u53EF\u4EE5\u540C\u65F6\u5F00\u542F\u2018append only\u2019\u6A21\u5F0F\u548C\u5F02\u6B65dumps\u6A21\u5F0F\uFF08\u4F60\u9700\u8981\u6CE8\u91CA\u6389\u4E0A\u9762\u7684\u2018save\u2019\u8868\u8FBE\u5F0F\u6765\u7981#\u6B62dumps\uFF09\uFF0C\u8FD9\u79CD\u60C5\u51B5\u4E0B\uFF0CRedis\u91CD\u5EFA\u6570\u636E\u96C6\u65F6\u4F1A\u4F18\u5148\u4F7F\u7528appendonly.aof\u800C\u5FFD\u7565dump.rdb
214 | #
215 | appendonly no
216 |
217 | # append only \u6587\u4EF6\u540D (\u9ED8\u8BA4: "appendonly.aof")
218 | # appendfilename appendonly.aof
219 |
220 | # \u8C03\u7528fsync()\u51FD\u6570\u901A\u77E5\u64CD\u4F5C\u7CFB\u7EDF\u7ACB\u523B\u5411\u786C\u76D8\u5199\u6570\u636E
221 | #
222 | # Redis\u652F\u63013\u4E2D\u6A21\u5F0F:
223 | #
224 | # no:\u4E0Dfsync, \u53EA\u662F\u901A\u77E5OS\u53EF\u4EE5flush\u6570\u636E\u4E86\uFF0C\u5177\u4F53\u662F\u5426flush\u53D6\u51B3\u4E8EOS.\u6027\u80FD\u66F4\u597D.
225 | # always: \u6BCF\u6B21\u5199\u5165append only \u65E5\u5FD7\u6587\u4EF6\u540E\u90FD\u4F1Afsync . \u6027\u80FD\u5DEE\uFF0C\u4F46\u5F88\u5B89\u5168.
226 | # everysec: \u6CA1\u95F4\u96941\u79D2\u8FDB\u884C\u4E00\u6B21fsync. \u6298\u4E2D.
227 | #
228 | # \u9ED8\u8BA4\u662F "everysec"
229 | # appendfsync always
230 | appendfsync everysec
231 | # appendfsync no
232 |
233 | # \u5F53AOF fsync\u7B56\u7565\u88AB\u8BBE\u7F6E\u4E3Aalways\u6216\u8005everysec\u5E76\u4E14\u540E\u53F0\u4FDD\u5B58\u8FDB\u7A0B\uFF08saving process)\u6B63\u5728\u6267\u884C\u5927\u91CFI/O\u64CD\u4F5C\u65F6
234 | # Redis\u53EF\u80FD\u4F1A\u5728fsync()\u8C03\u7528\u4E0A\u963B\u585E\u8FC7\u957F\u65F6\u95F4
235 | #
236 | no-appendfsync-on-rewrite no
237 |
238 | # append only \u6587\u4EF6\u7684\u81EA\u52A8\u91CD\u5199
239 | # \u5F53AOF \u65E5\u5FD7\u6587\u4EF6\u5373\u5C06\u589E\u957F\u5230\u6307\u5B9A\u767E\u5206\u6BD4\u65F6\uFF0CRedis\u53EF\u4EE5\u901A\u8FC7\u8C03\u7528BGREWRITEAOF \u6765\u81EA\u52A8\u91CD\u5199append only\u6587\u4EF6\u3002
240 | #
241 | # \u5B83\u662F\u8FD9\u4E48\u5E72\u7684\uFF1ARedis\u4F1A\u8BB0\u4F4F\u6700\u8FD1\u4E00\u6B21\u91CD\u5199\u540E\u7684AOF \u6587\u4EF6size\u3002\u7136\u540E\u5B83\u4F1A\u628A\u8FD9\u4E2Asize\u4E0E\u5F53\u524Dsize\u8FDB\u884C\u6BD4\u8F83\uFF0C\u5982\u679C\u5F53\u524D# size\u6BD4\u6307\u5B9A\u7684\u767E\u5206\u6BD4\u5927\uFF0C\u5C31\u4F1A\u89E6\u53D1\u91CD\u5199\u3002\u540C\u6837\uFF0C\u4F60\u9700\u8981\u6307\u5B9AAOF\u6587\u4EF6\u88AB\u91CD\u5199\u7684\u6700\u5C0Fsize\uFF0C\u8FD9\u5BF9\u907F\u514D\u867D\u7136\u767E\u5206\u6BD4\u8FBE\u5230\u4E86# \u4F46\u662F\u5B9E\u9645\u4E0A\u6587\u4EF6size\u8FD8\u662F\u5F88\u5C0F\uFF08\u8FD9\u79CD\u60C5\u51B5\u6CA1\u6709\u5FC5\u8981\u91CD\u5199\uFF09\u5374\u5BFC\u81F4AOF\u6587\u4EF6\u91CD\u5199\u7684\u60C5\u51B5\u5F88\u6709\u7528\u3002
242 | #
243 | #
244 | # auto-aof-rewrite-percentage \u8BBE\u7F6E\u4E3A 0 \u53EF\u4EE5\u5173\u95EDAOF\u91CD\u5199\u529F\u80FD
245 |
246 | auto-aof-rewrite-percentage 100
247 | auto-aof-rewrite-min-size 64mb
248 |
249 | ################## SLOW LOG ###################################
250 |
251 | # Redis slow log\u7528\u6765\u8BB0\u5F55\u8D85\u8FC7\u6307\u5B9A\u6267\u884C\u65F6\u95F4\u7684\u67E5\u8BE2\u3002
252 | #
253 | # \u4F60\u53EF\u4EE5\u6307\u5B9A\u4E24\u4E2A\u53C2\u6570\uFF1A\u4E00\u4E2A\u662F\u6162\u67E5\u8BE2\u7684\u9600\u503C\uFF0C\u5355\u4F4D\u662F\u6BEB\u79D2\uFF1B\u53E6\u5916\u4E00\u4E2A\u662Fslow log\u7684\u957F\u5EA6\uFF0C\u76F8\u5F53\u4E8E\u4E00\u4E2A\u961F\u5217\u3002
254 |
255 | # \u8D1F\u6570\u5219\u5173\u95EDslow log\uFF0C0\u5219\u4F1A\u5BFC\u81F4\u6BCF\u4E2A\u547D\u4EE4\u90FD\u88AB\u8BB0\u5F55
256 | slowlog-log-slower-than 10000
257 |
258 | # \u4E0D\u8BBE\u7F6E\u4F1A\u6D88\u8017\u8FC7\u591A\u5185\u5B58\uFF0C\u6240\u4EE5\u8FD8\u662F\u8981\u8BBE\u7F6E\u4E00\u4E0B\u3002\u53EF\u4EE5\u4F7F\u7528SLOWLOG RESET\u547D\u4EE4\u6765\u56DE\u6536slow log\u4F7F\u7528\u7684\u5185\u5B58
259 | slowlog-max-len 1024
260 |
261 | ################ \u865A\u62DF\u5185\u5B58 ###############################
262 | #\u4F7F\u7528redis \u5C31\u522B\u7528\u865A\u62DF\u5185\u5B58\u4E86\uFF0C\u7EDD\u5BF9\u4E0D\u662F\u4E00\u4E2A\u597D\u4E3B\u610F\uFF0C\u52A0\u4E2A\u673A\u5668\u5427\uFF0C\u6240\u4EE5\u8FD9\u91CC\u4E0D\u7FFB\u8BD1\u5566\uFF01\uFF01
263 |
264 | ### WARNING! Virtual Memory is deprecated in Redis 2.4
265 | ### The use of Virtual Memory is strongly discouraged.
266 |
267 | # Virtual Memory allows Redis to work with datasets bigger than the actual
268 | # amount of RAM needed to hold the whole dataset in memory.
269 | # In order to do so very used keys are taken in memory while the other keys
270 | # are swapped into a swap file, similarly to what operating systems do
271 | # with memory pages.
272 | #
273 | # To enable VM just set 'vm-enabled' to yes, and set the following three
274 | # VM parameters accordingly to your needs.
275 |
276 | vm-enabled no
277 | # vm-enabled yes
278 |
279 | # This is the path of the Redis swap file. As you can guess, swap files
280 | # can't be shared by different Redis instances, so make sure to use a swap
281 | # file for every redis process you are running. Redis will complain if the
282 | # swap file is already in use.
283 | #
284 | # The best kind of storage for the Redis swap file (that's accessed at random)
285 | # is a Solid State Disk (SSD).
286 | #
287 | # *** WARNING *** if you are using a shared hosting the default of putting
288 | # the swap file under /tmp is not secure. Create a dir with access granted
289 | # only to Redis user and configure Redis to create the swap file there.
290 | vm-swap-file /tmp/redis.swap
291 |
292 | # vm-max-memory configures the VM to use at max the specified amount of
293 | # RAM. Everything that deos not fit will be swapped on disk *if* possible, that
294 | # is, if there is still enough contiguous space in the swap file.
295 | #
296 | # With vm-max-memory 0 the system will swap everything it can. Not a good
297 | # default, just specify the max amount of RAM you can in bytes, but it's
298 | # better to leave some margin. For instance specify an amount of RAM
299 | # that's more or less between 60 and 80% of your free RAM.
300 | vm-max-memory 0
301 |
302 | # Redis swap files is split into pages. An object can be saved using multiple
303 | # contiguous pages, but pages can't be shared between different objects.
304 | # So if your page is too big, small objects swapped out on disk will waste
305 | # a lot of space. If you page is too small, there is less space in the swap
306 | # file (assuming you configured the same number of total swap file pages).
307 | #
308 | # If you use a lot of small objects, use a page size of 64 or 32 bytes.
309 | # If you use a lot of big objects, use a bigger page size.
310 | # If unsure, use the default :)
311 | vm-page-size 32
312 |
313 | # Number of total memory pages in the swap file.
314 | # Given that the page table (a bitmap of free/used pages) is taken in memory,
315 | # every 8 pages on disk will consume 1 byte of RAM.
316 | #
317 | # The total swap size is vm-page-size * vm-pages
318 | #
319 | # With the default of 32-bytes memory pages and 134217728 pages Redis will
320 | # use a 4 GB swap file, that will use 16 MB of RAM for the page table.
321 | #
322 | # It's better to use the smallest acceptable value for your application,
323 | # but the default is large in order to work in most conditions.
324 | vm-pages 134217728
325 |
326 | # Max number of VM I/O threads running at the same time.
327 | # This threads are used to read/write data from/to swap file, since they
328 | # also encode and decode objects from disk to memory or the reverse, a bigger
329 | # number of threads can help with big objects even if they can't help with
330 | # I/O itself as the physical device may not be able to couple with many
331 | # reads/writes operations at the same time.
332 | #
333 | # The special value of 0 turn off threaded I/O and enables the blocking
334 | # Virtual Memory implementation.
335 | vm-max-threads 4
336 |
337 | ################\u9AD8\u7EA7\u914D\u7F6E###############################
338 |
339 | # Hashes are encoded in a special way (much more memory efficient) when they
340 | # have at max a given numer of elements, and the biggest element does not
341 | # exceed a given threshold. You can configure this limits with the following
342 | # configuration directives.
343 | hash-max-zipmap-entries 512
344 | hash-max-zipmap-value 64
345 |
346 | # Similarly to hashes, small lists are also encoded in a special way in order
347 | # to save a lot of space. The special representation is only used when
348 | # you are under the following limits:
349 | list-max-ziplist-entries 512
350 | list-max-ziplist-value 64
351 |
352 | # Sets have a special encoding in just one case: when a set is composed
353 | # of just strings that happens to be integers in radix 10 in the range
354 | # of 64 bit signed integers.
355 | # The following configuration setting sets the limit in the size of the
356 | # set in order to use this special memory saving encoding.
357 | set-max-intset-entries 512
358 |
359 | # Similarly to hashes and lists, sorted sets are also specially encoded in
360 | # order to save a lot of space. This encoding is only used when the length and
361 | # elements of a sorted set are below the following limits:
362 | zset-max-ziplist-entries 128
363 | zset-max-ziplist-value 64
364 |
365 | # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
366 | # order to help rehashing the main Redis hash table (the one mapping top-level
367 | # keys to values). The hash table implementation redis uses (see dict.c)
368 | # performs a lazy rehashing: the more operation you run into an hash table
369 | # that is rhashing, the more rehashing "steps" are performed, so if the
370 | # server is idle the rehashing is never complete and some more memory is used
371 | # by the hash table.
372 | #
373 | # The default is to use this millisecond 10 times every second in order to
374 | # active rehashing the main dictionaries, freeing memory when possible.
375 | #
376 | # If unsure:
377 | # use "activerehashing no" if you have hard latency requirements and it is
378 | # not a good thing in your environment that Redis can reply form time to time
379 | # to queries with 2 milliseconds delay.
380 | #
381 | # use "activerehashing yes" if you don't have such hard requirements but
382 | # want to free memory asap when possible.
383 | activerehashing yes
384 |
385 | ################## INCLUDES ###################################
386 |
387 | # Include one or more other config files here. This is useful if you
388 | # have a standard template that goes to all redis server but also need
389 | # to customize a few per-server settings. Include files can include
390 | # other files, so use this wisely.
391 | #
392 | # include /path/to/local.conf
393 | # include /path/to/other.conf
394 |
--------------------------------------------------------------------------------