redis-4.0.10クラスタインストール(3台のマシン、6つのnode)、Springプロジェクトでの統合、redis操作ツールクラス

135457 ワード

1 Redisインストール
redis高可用性の3つの一般的なクラスタ方式:redis sentinel、redis cluster(マルチホスト+分散)、redis sharding.次に、redis sentinelの導入手順について説明します.
1.1 Redisクラスタ実装(マシン3台、node 6個)
1.1.1インストール前の準備
yum install -y gcc
make MALLOC=libc

1.1.2 redisソフトウェアのダウンロード、解凍
redisを/home/bigdata/softwareにアップロードし、redisを解凍します.
cd /home/bigdata/software 
tar -zxvf redis-4.0.10.tar.gz -C /home/bigdata/installed
cd /home/bigdata/installed/redis-4.0.10

1.1.3.インストールするディレクトリを作成するには、次の手順に従います.
mkdir -p /usr/local/redis/redis-4.0.10 

1.1.3.コンパイル:
make PREFIX=/usr/local/redis/redis-4.0.10 install(root   sudo)

1.1.4.ソースディレクトリコピーredis.confプロファイル
cp redis.conf /usr/local/redis/ redis-4.0.10/redis.conf(       tar.gz       redis.conf

1.1.5.環境変数を/etc/profileに追加
#redis
export REDIS_HOME=/usr/local/redis/redis-4.0.10
export PATH=$PATH:$REDIS_HOME/bin

構成が完了したら、終了、実行:
source /etc/profile

1.1.6.redisプロファイルの変更
a、daemonize:  yes,           ,  。 
b、bind:         ,              (        ) c、requirepass     (test_redis,         )
d、port:  6379  。         ,   。 
e、dir:  /usr/local/redis/redis-4.0.10/standalone   rdb、aof       ,dir       。         。                    。   ./data,         ,     ./data   ,          。          。 
f、logfile:      。      "/usr/local/redis/redis-4.0.10/standalone/6379.log"(           ) 
g、dbfilename:rdb    ,  dump-6379.rdb (      dir   ) 
h、appendonly  yes i、appendfilename  appendonly-6379.aof (      dir

redisの起動:
[root@bigdata1 redis-4.0.10]# bin/redis-server /usr/local/redis/redis-4.0.10/redis.conf

redisプロセスを表示するには、次の手順に従います.
[root@bigdata1 redis-4.0.10]# ps -ef | grep redis
root     13079     1  0 14:07 ?        00:00:00 bin/redis-server *:
root     13096 11631  0 14:07 pts/2    00:00:00 grep --color=auto r
[root@bigdata1 redis-4.0.10]#

接続:
[root@bigdata1 redis-4.0.10] cd /usr/local/redis/redis-4.0.10
[root@bigdata1 redis-4.0.10]# bin/redis-cli -h bigdata1 -p 6379 -a test_redis
Warning: Using a password with '-a' option on the command line interface may not be safe.
bigdata1:6379>

これにより,単一redisクラスタのインストールが完了したことが分かる.
Redisを閉じる:
kill  
   :redis-cli shutdown(   )  redis-cli a test_redis shutdown(    )

su - root -c 'redis-server /usr/local/redis/redis-4.0.10/redis.conf'

1.2クラスタのインストール:
修正/usr/local/redis/redis-4.0.10/redis.confの内容は、次の内容を変更します.
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
protected-mode no

3台のマシンでそれぞれ/usr/local/redis/redis-4.0.10を/usr/local/redis/redis-4.0.10-2にコピーし、中のportを6378に変更し、すべての/usr/local/redis/redis-4.0.10-2/redis.confのredis-4.0.10をredis-4.0.10-2に変更
インストールruby
[root@bigdata1 software]# cd /home/bigdata/software
[root@bigdata1 software]# tar -zxvf ruby-2.3.3.tar.gz -C /home/bigdata/installed/
[root@bigdata1 software]# cd /home/bigdata/installed/ruby-2.3.3
[root@bigdata1 ruby-2.3.3]# ./configure --prefix=/usr/local/ruby/ruby-2.3.3
[root@bigdata1 ruby-2.3.3]# make #    
[root@bigdata1 ruby-2.3.3]#y make install

rubyの環境変数を設定するには、次の手順に従います.
[root@bigdata1 ruby-2.3.3]# vim /etc/profile


# ruby
export RUBY_HOME=/usr/local/ruby/ruby-2.3.3
export PATH=$PATH:$RUBY_HOME/bin

source /etc/profile

rubygemsのインストール:rubygemsの公式サイトにアクセスし、最新のrubygemsパッケージをダウンロードします.
https://rubygems.org/pages/download#formats

に入る
cd /home/bigdata/installed
unzip rubygems-2.7.7.zip
[root@bigdata2 installed]# cd rubygems-2.7.7/ 

次にインストールします.コマンドは次のとおりです.
ruby setup.rb

2)ruby vがバージョンになるかどうかを確認し、バージョン説明が得られるとともに、rubyが環境変数に加わったことを示す3)rubyをインストールした後にopensslをインストールしなければならない.そうしないと、gem install redisを試みると次のようなエラーが発生するUnable to require openssl、install OpenSSL and rebuild ruby(preferred)or use non‐HTTPS sources、Unable to require openssl、 install OpenSSL and rebuild ruby (preferred) or use non‐HTTPS sources
4)Opensslをインストールする前に、次のコマンドを実行し、y同意を入力します.
yum install --enablerepo=centosplus openssl-devel

5)ruby 2に入る.3.1ディレクトリのext/opensslディレクトリ、ruby extconfを実行する.rb
[root@bigdata1 ruby-2.3.3]# cd /home/bigdata/installed/ruby-2.3.3/ext/openssl
[root@bigdata1 openssl]# ruby extconf.rb
[root@bigdata1 openssl]# make
[root@bigdata1 openssl]# make install
[root@bigdata1 openssl]# openssl version  openssl   ,      

6)gemでredisをインストールする
[root@bigdata2 bin]# pwd
/home/bigdata/installed/rubygems-2.7.7/bin
[root@bigdata2 bin]# ./gem install redis --version 4.0.10 

redisの作成クラスタコマンドを実行して、redisのソースディレクトリにクラスタを作成します.
[root@bigdata1 src]# cd /usr/local/redis/redis/src

redis-trib.rbはredisのインストールディレクトリにコピーします(3台のマシンでそれぞれ次の操作を行います):
[root@bigdata1 src]# cp redis-trib.rb /usr/local/redis/redis-4.0.10
[root@bigdata1 src]# cp redis-trib.rb /usr/local/redis/redis-4.0.10-2

redis-tribを表示するrbの使い方
[root@bigdata2 src]# ./redis-trib.rb
Usage: redis-trib   

  create          host1:port1 ... hostN:portN
                  --replicas 
  check           host:port
  info            host:port
  fix             host:port
                  --timeout 
  reshard         host:port
                  --from 
                  --to 
                  --slots 
                  --yes
                  --timeout 
                  --pipeline 
  rebalance       host:port
                  --weight 
                  --auto-weights
                  --use-empty-masters
                  --timeout 
                  --simulate
                  --pipeline 
                  --threshold 
  add-node        new_host:new_port existing_host:existing_port
                  --slave
                  --master-id 
  del-node        host:port node_id
  set-timeout     host:port milliseconds
  call            host:port command arg arg .. arg
  import          host:port
                  --from 
                  --copy
                  --replace
  help            (show this help)

For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.
[root@bigdata2 src]#

各redisノードを起動する、クラスタの下のxxxを起動する.xxx.xxx.IPの接頭辞
[root@bigdata1 src]#./redis-trib.rb create --replicas 1 xxx.xxx.xxx.140:6379 xxx.xxx.xxx.140:6378 xxx.xxx.xxx.141:6379 xxx.xxx.xxx.141:6378 xxx.xxx.xxx.142:6379 xxx.xxx.xxx.142:6378
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
bigdata1:6379
bigdata2:6379
bigdata3:6379
Adding replica bigdata2:6378 to bigdata1:6379
Adding replica bigdata3:6378 to bigdata2:6379
Adding replica bigdata1:6378 to bigdata3:6379
M: ffff2d324488baa6612d80d326cc15ce560c5375 bigdata1:6379
   slots:0-5460 (5461 slots) master
S: a4c2b4a75824a58e3b8c4c378da9abbc1bce37db bigdata1:6378
   replicates 9b2cddbe060c292fb53b0925c46e7d4385a2203d
M: 30bc072f6efc950932f63e22a12b2ed3f3da167a bigdata2:6379
   slots:5461-10922 (5462 slots) master
S: 0b90a52a4931dfdd0f50ffb507ba779e32d3446a bigdata2:6378
   replicates ffff2d324488baa6612d80d326cc15ce560c5375
M: 9b2cddbe060c292fb53b0925c46e7d4385a2203d bigdata3:6379
   slots:10923-16383 (5461 slots) master
S: dd05a7c04115d28b9fc0ebbfbfca59ccdfe556c4 bigdata3:6378
   replicates 30bc072f6efc950932f63e22a12b2ed3f3da167a
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
/usr/local/ruby/ruby-2.3.3/lib/ruby/gems/2.3.0/gems/redis-4.0.1/lib/redis/client.rb:119:in `call': ERR Invalid node address specified: bigdata1:6379 (Redis::CommandError)
    from /usr/local/ruby/ruby-2.3.3/lib/ruby/gems/2.3.0/gems/redis-4.0.1/lib/redis.rb:2764:in `block in method_missing'
    from /usr/local/ruby/ruby-2.3.3/lib/ruby/gems/2.3.0/gems/redis-4.0.1/lib/redis.rb:45:in `block in synchronize'
    from /usr/local/ruby/ruby-2.3.3/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
    from /usr/local/ruby/ruby-2.3.3/lib/ruby/gems/2.3.0/gems/redis-4.0.1/lib/redis.rb:45:in `synchronize'
    from /usr/local/ruby/ruby-2.3.3/lib/ruby/gems/2.3.0/gems/redis-4.0.1/lib/redis.rb:2763:in `method_missing'
    from ./redis-trib.rb:941:in `block in join_cluster'
    from ./redis-trib.rb:939:in `each'
    from ./redis-trib.rb:939:in `join_cluster'
    from ./redis-trib.rb:1431:in `create_cluster_cmd'
    from ./redis-trib.rb:1830:in `
' [root@bigdata1 src]#

構成が完了したら、次のコマンドを実行して表示します.
 [root@bigdata1 redis-4.0.10]# bin/redis-cli -h bigdata1 -p 6379 -a test_redis
Warning: Using a password with '-a' option on the command line interface may not be safe.
bigdata1:6379> cluster info    #      
cluster_state:fail
cluster_slots_assigned:5461
cluster_slots_ok:5461
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:1
cluster_size:1
cluster_current_epoch:1
cluster_my_epoch:1
cluster_stats_messages_sent:0
cluster_stats_messages_received:0
bigdata1:6379> cluster nodes   #      
5f1f88c2a4869c51ae57d3f4537bf8da19d070f3 xxx.xxx.xxx.142:6378@16378 slave 64a3926e25023c1d391afb88c2850dfdad72657c 0 1530777080000 6 connected
64a3926e25023c1d391afb88c2850dfdad72657c xxx.xxx.xxx.141:6379@16379 master - 0 1530777080000 3 connected 5461-10922
9f0840b083f5223c0c2278b1e75351bc1172d960 xxx.xxx.xxx.142:6379@16379 master - 0 1530777080673 5 connected 10923-16383
5539fdec71b6be6ebc48a36ba4c642a92b27a215 xxx.xxx.xxx.141:6378@16378 slave 7f51d465030d468bcfae748fdf7760f33a469c0c 0 1530777082677 4 connected
7f51d465030d468bcfae748fdf7760f33a469c0c xxx.xxx.xxx.140:6379@16379 myself,master - 0 1530777081000 1 connected 0-5460
34b0cf0efcaefd3f6de8cdbcdb5d0b9b417c836a xxx.xxx.xxx.140:6378@16378 slave 9f0840b083f5223c0c2278b1e75351bc1172d960 0 1530777081675 5 connected
bigdata1:6379> 

コマンドも使用できます.
[root@bigdata2 src]# ./redis-trib.rb info bigdata1:6379
bigdata1:6379 (ffff2d32...) -> 0 keys | 5461 slots | 0 slaves.
[OK] 0 keys in 1 masters.
0.00 keys per slot on average.
[root@bigdata2 src]# ./redis-trib.rb info bigdata1:6378
bigdata1:6378 (a4c2b4a7...) -> 0 keys | 0 slots | 0 slaves.
[OK] 0 keys in 1 masters.
0.00 keys per slot on average.
[root@bigdata2 src]# ./redis-trib.rb info bigdata2:6378
bigdata2:6378 (0b90a52a...) -> 0 keys | 0 slots | 0 slaves.
[OK] 0 keys in 1 masters.
0.0 keys per slot on average.

次のようになります.
[root@bigdata2 redis-4.0.10]# bin/redis-cli -h bigdata2
bigdata2:6379> info
# Server
redis_version:4.0.10
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:8302a44837507475
redis_mode:cluster
os:Linux 3.10.0-693.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:4.8.5
process_id:19732
run_id:81a5378421b525b1c97351322949b030c93cc567
tcp_port:6379
uptime_in_seconds:2941
uptime_in_days:0
hz:10
lru_clock:3973023
executable:/usr/local/redis/redis-4.0.10/bin/redis-server
config_file:/usr/local/redis/redis-4.0.10/redis.conf

# Clients
connected_clients:2
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

# Memory
used_memory:1529224
used_memory_human:1.46M
used_memory_rss:9994240
used_memory_rss_human:9.53M
used_memory_peak:1559408
used_memory_peak_human:1.49M
used_memory_peak_perc:98.06%
used_memory_overhead:1511488
used_memory_startup:1445000
used_memory_dataset:17736
used_memory_dataset_perc:21.06%
total_system_memory:16547332096
total_system_memory_human:15.41G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:6.53
mem_allocator:jemalloc-4.0.3
active_defrag_running:0
lazyfree_pending_objects:0

# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1530696738
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1
rdb_last_cow_size:0
aof_enabled:1
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok
aof_last_cow_size:0
aof_current_size:0
aof_base_size:0
aof_pending_rewrite:0
aof_buffer_length:0
aof_rewrite_buffer_length:0
aof_pending_bio_fsync:0
aof_delayed_fsync:0

# Stats
total_connections_received:4
total_commands_processed:17
instantaneous_ops_per_sec:0
total_net_input_bytes:55966
total_net_output_bytes:30041
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.00
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:0
expired_stale_perc:0.00
expired_time_cap_reached_count:0
evicted_keys:0
keyspace_hits:0
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
migrate_cached_sockets:0
slave_expires_tracked_keys:0
active_defrag_hits:0
active_defrag_misses:0
active_defrag_key_hits:0
active_defrag_key_misses:0

# Replication
role:master
connected_slaves:0
master_replid:330bc27779b0a28f762a8725d37adff9cde477af
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

# CPU
used_cpu_sys:1.13
used_cpu_user:0.78
used_cpu_sys_children:0.00
used_cpu_user_children:0.00

# Cluster
cluster_enabled:1

# Keyspace
bigdata2:6379>

Jedisを直接使用してプログラム接続を使用する場合は、次のような質問をします.
redis.clients.jedis.exceptions.JedisClusterException:CLUSTERDOWN The cluster is down

解決策は、./redis-trib.rb check xxx.xxx.xxx.142:6379がこのコマンドによって各ノードをチェックすることである.発見は以下の問題を報告します.
[ERR] Not all 16384 slots are covered by nodes
./redis-trib.rb fix xxx.xxx.xxx.142:6379このコマンドで上記の問題を解決します.
現在のredisの接続数を表示します.使用:info clients。
[root@bigdata1 redis-4.0.10-2]# bin/redis-cli -h bigdata1
bigdata1:6379> info clients
# Clients
connected_clients:3
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

サポートされている最大接続数を表示するには、config get maxclientsを使用します.
bigdata1:6379> config get maxclients
1) "maxclients"
2) "10000"
bigdata1:6379>

redisの保護モードをオフにします.
[root@bigdata1 redis-4.0.10-2]# bin/redis-cli -h bigdata3 -p 6379 -a test_redis
[root@bigdata1 redis-4.0.10-2]# bin/redis-cli -h bigdata3 -p 6378 -a test_redis
Warning: Using a password with '-a' option on the command line interface may not be safe.
bigdata3:6378> config get protected-mode
1) "protected-mode"
2) "yes"
bigdata3:6378> config set protected-mode "no"
OK

1.3とSpring継承
1.3.1 maven pom依存の追加
<aspectjweaver.version>1.8.3aspectjweaver.version>
<redis.clients.version>2.9.0redis.clients.version>


<dependency>
    <groupId>org.aspectjgroupId>
    <artifactId>aspectjweaverartifactId>
    <version>${aspectjweaver.version}version>
dependency>
<dependency>
    <groupId>org.springframework.datagroupId>
    <artifactId>spring-data-redisartifactId>
dependency>
<dependency>
    <groupId>redis.clientsgroupId>
    <artifactId>jedisartifactId>
    <version>${redis.clients.version}version>
dependency>

1.3.2 Springのプロパティファイルの作成
#JedisPoolConfig   
#     ,        300   ,  18            ,     。
redis.pool.maxTotal=4000
#      
redis.pool.maxIdle=300
#     
redis.pool.minIdle=5
#       
redis.pool.numTestsPerEvictionRun=1024
#         
redis.pool.timeBetweenEvictionRunsMillis=30000
#         
redis.pool.minEvictableIdleTimeMillis=1800000
#            ,     >       >            
redis.pool.softMinEvictableIdleTimeMillis=10000
#             ,  0:       ,  -1
redis.pool.maxWaitMillis=3000
#             ,  false
redis.pool.testOnBorrow=true
#         ,  false
redis.pool.testWhileIdle=true
#         ,false   ,true    ,  true
redis.pool.blockWhenExhausted=false
#RedisClusterConfiguration  
redis.maxRedirects=5

#      
redis.host1=xxx.xxx.xxx.140
redis.port1=6379

redis.host2=xxx.xxx.xxx.140
redis.port2=6378

redis.host3=xxx.xxx.xxx.141
redis.port3=6379

redis.host4=xxx.xxx.xxx.141
redis.port4=6378

redis.host5=xxx.xxx.xxx.142
redis.port5=6379

redis.host6=xxx.xxx.xxx.142
redis.port6=6378

redis.password=test_redis
redis.dataBase=0

# redis  
redis.host=xxx.xxx.xxx.141
redis.port=6377

1.3.2 Springのプロファイルの追加

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd">

    
    
    <bean id="baseRedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
        
        <property name="maxTotal" value="${redis.pool.maxTotal}" />
        
        <property name="maxIdle" value="${redis.pool.maxIdle}" />
        
        <property name="minIdle" value="${redis.pool.minIdle}" />
        
        <property name="numTestsPerEvictionRun" value="${redis.pool.numTestsPerEvictionRun}" />
        
        <property name="timeBetweenEvictionRunsMillis" value="${redis.pool.timeBetweenEvictionRunsMillis}" />
        
        <property name="minEvictableIdleTimeMillis" value="${redis.pool.minEvictableIdleTimeMillis}" />
        
        <property name="softMinEvictableIdleTimeMillis" value="${redis.pool.softMinEvictableIdleTimeMillis}" />
        
        <property name="maxWaitMillis" value="${redis.pool.maxWaitMillis}" />
        
        <property name="testOnBorrow" value="${redis.pool.testOnBorrow}" />
        
        <property name="testWhileIdle" value="${redis.pool.testWhileIdle}" />
        
        <property name="blockWhenExhausted" value="${redis.pool.blockWhenExhausted}" />
    bean>

    
    <bean id="baseRedisClusterConfiguration" class="org.springframework.data.redis.connection.RedisClusterConfiguration">
        <property name="maxRedirects" value="${redis.maxRedirects}" />
        <property name="clusterNodes">
            <set>
                <bean class="org.springframework.data.redis.connection.RedisClusterNode">
                    <constructor-arg name="host" value="${redis.host1}" />
                    <constructor-arg name="port" value="${redis.port1}"/>
                bean>
                <bean class="org.springframework.data.redis.connection.RedisClusterNode">
                    <constructor-arg name="host" value="${redis.host2}" />
                    <constructor-arg name="port" value="${redis.port2}" />
                bean>
                <bean class="org.springframework.data.redis.connection.RedisClusterNode">
                    <constructor-arg name="host" value="${redis.host3}" />
                    <constructor-arg name="port" value="${redis.port3}" />
                bean>
                <bean class="org.springframework.data.redis.connection.RedisClusterNode">
                    <constructor-arg name="host" value="${redis.host4}" />
                    <constructor-arg name="port" value="${redis.port4}" />
                bean>
                <bean class="org.springframework.data.redis.connection.RedisClusterNode">
                    <constructor-arg name="host" value="${redis.host5}" />
                    <constructor-arg name="port" value="${redis.port5}" />
                bean>
                <bean class="org.springframework.data.redis.connection.RedisClusterNode">
                    <constructor-arg name="host" value="${redis.host6}" />
                    <constructor-arg name="port" value="${redis.port6}" />
                bean>
            set>
        property>
    bean>

    
    <bean id="baseJedisConnFactory"
          class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" destroy-method="destroy">
        <property name="hostName" value="${redis.host}" />
        <property name="port" value="${redis.port}" />
        <property name="password" value ="${redis.password}" />
        <property name="usePool" value="true" />
        <property name="poolConfig" ref="baseRedisPoolConfig" />
    bean>

    
    

    
    <bean id="baseRedisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
        <property name="connectionFactory" ref="baseJedisConnFactory" />
        <property name="keySerializer">
            <bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
        property>
        <property name="valueSerializer">
            <bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
        property>
        <property name="hashKeySerializer">
            <bean class="org.springframework.data.redis.serializer.StringRedisSerializer" />
        property>
        <property name="hashValueSerializer">
            <bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />
        property>
    bean>

    <bean id="stringRedisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
        <property name="connectionFactory" ref="baseJedisConnFactory" />
    bean>

    <bean id="redisUtil" class="com.xxx.redis.util.RedisUtil">
        <property name="stringRedisTemplate" ref="stringRedisTemplate" />
        <property name="redisTemplate" ref="baseRedisTemplate"/>
    bean>
beans>

1.4例redis操作のコード
package com.xxx.redis.util;

import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.core.*;
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;

import java.io.Serializable;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;

/**
 * Redis   
 *
 *     :http://hbxflihua.iteye.com/blog/2328156
 *           (GitHub  : https://github.com/whvcse/RedisUtil )
 *
 * @author WangFan
 * @date 2018-02-24   03:09:50
 * @version 1.1 (GitHub  : https://github.com/whvcse/RedisUtil )
 */
public class RedisUtil {
    private StringRedisTemplate stringRedisTemplate;
    private RedisTemplate redisTemplate;

    public StringRedisTemplate getStringRedisTemplate() {
        return stringRedisTemplate;
    }

    public void setStringRedisTemplate(StringRedisTemplate stringRedisTemplate) {
        this.stringRedisTemplate = stringRedisTemplate;
    }

    public RedisTemplate getRedisTemplate() {
        return redisTemplate;
    }

    public void setRedisTemplate(RedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    /** -------------------key    --------------------- */

    /**
     *   key
     *
     * @param key
     */
    public void delete(String key) {
        stringRedisTemplate.delete(key);
    }

    /**
     *     key
     *
     * @param keys
     */
    public void delete(Collection keys) {
        stringRedisTemplate.delete(keys);
    }

    /**
     *    key
     *
     * @param key
     * @return
     */
    public byte[] dump(String key) {
        return stringRedisTemplate.dump(key);
    }

    /**
     *     key
     *
     * @param key
     * @return
     */
    public Boolean hasKey(String key) {
        return stringRedisTemplate.hasKey(key);
    }

    /**
     *       
     *
     * @param key
     * @param timeout
     * @param unit
     * @return
     */
    public Boolean expire(String key, long timeout, TimeUnit unit) {
        return stringRedisTemplate.expire(key, timeout, unit);
    }

    /**
     *       
     *
     * @param key
     * @param date
     * @return
     */
    public Boolean expireAt(String key, Date date) {
        return stringRedisTemplate.expireAt(key, date);
    }

    /**
     *      key
     *
     * @param pattern
     * @return
     */
    public Set keys(String pattern) {
        return stringRedisTemplate.keys(pattern);
    }

    /**
     *         key           db   
     *
     * @param key
     * @param dbIndex
     * @return
     */
    public Boolean move(String key, int dbIndex) {
        return stringRedisTemplate.move(key, dbIndex);
    }

    /**
     *    key      ,key      
     *
     * @param key
     * @return
     */
    public Boolean persist(String key) {
        return stringRedisTemplate.persist(key);
    }

    /**
     *    key         
     *
     * @param key
     * @param unit
     * @return
     */
    public Long getExpire(String key, TimeUnit unit) {
        return stringRedisTemplate.getExpire(key, unit);
    }

    /**
     *    key         
     *
     * @param key
     * @return
     */
    public Long getExpire(String key) {
        return stringRedisTemplate.getExpire(key);
    }

    /**
     *               key
     *
     * @return
     */
    public String randomKey() {
        return stringRedisTemplate.randomKey();
    }

    /**
     *    key    
     *
     * @param oldKey
     * @param newKey
     */
    public void rename(String oldKey, String newKey) {
        stringRedisTemplate.rename(oldKey, newKey);
    }

    /**
     *    newkey     ,  oldKey     newkey
     *
     * @param oldKey
     * @param newKey
     * @return
     */
    public Boolean renameIfAbsent(String oldKey, String newKey) {
        return stringRedisTemplate.renameIfAbsent(oldKey, newKey);
    }

    /**
     *    key         
     *
     * @param key
     * @return
     */
    public DataType type(String key) {
        return stringRedisTemplate.type(key);
    }

    /** -------------------string    --------------------- */

    /**
     *      key   
     * @param key
     * @param value
     */
    public void setString(String key, String value) {
        stringRedisTemplate.opsForValue().set(key, value);
    }

    /**
     *      key   
     * @param key
     * @return
     */
    public String getString(String key) {
        return stringRedisTemplate.opsForValue().get(key);
    }

    /**
     *    key          
     * @param key
     * @param start
     * @param end
     * @return
     */
    public String getRange(String key, long start, long end) {
        return stringRedisTemplate.opsForValue().get(key, start, end);
    }

    /**
     *     key      value ,    key    (old value)
     *
     * @param key
     * @param value
     * @return
     */
    public String getAndSet(String key, String value) {
        return stringRedisTemplate.opsForValue().getAndSet(key, value);
    }

    /**
     *   key         ,          (bit)
     *
     * @param key
     * @param offset
     * @return
     */
    public Boolean getBit(String key, long offset) {
        return stringRedisTemplate.opsForValue().getBit(key, offset);
    }

    /**
     *     
     *
     * @param keys
     * @return
     */
    public List multiGet(Collection keys) {
        return stringRedisTemplate.opsForValue().multiGet(keys);
    }

    /**
     *   ASCII ,    'a' ASCII  97,       '01100001',          offset    value
     *
     * @param key
     * @param offset
     *              
     * @param value
     *             ,true 1, false 0
     * @return
     */
    public boolean setBit(String key, long offset, boolean value) {
        return stringRedisTemplate.opsForValue().setBit(key, offset, value);
    }

    /**
     *    value     key ,   key         timeout
     *
     * @param key
     * @param value
     * @param timeout
     *                
     * @param unit
     *                ,  :TimeUnit.DAYS   :TimeUnit.HOURS   :TimeUnit.MINUTES
     *             :TimeUnit.SECONDS   :TimeUnit.MILLISECONDS
     */
    public void setEx(String key, String value, long timeout, TimeUnit unit) {
        stringRedisTemplate.opsForValue().set(key, value, timeout, unit);
    }

    /**
     *     key        key   
     *
     * @param key
     * @param value
     * @return         false,     true
     */
    public boolean setIfAbsent(String key, String value) {
        return stringRedisTemplate.opsForValue().setIfAbsent(key, value);
    }

    /**
     *   value        key         ,     offset   
     *
     * @param key
     * @param value
     * @param offset
     *                     
     */
    public void setRange(String key, String value, long offset) {
        stringRedisTemplate.opsForValue().set(key, value, offset);
    }

    /**
     *         
     *
     * @param key
     * @return
     */
    public Long size(String key) {
        return stringRedisTemplate.opsForValue().size(key);
    }

    /**
     *     
     *
     * @param maps
     */
    public void multiSet(Map maps) {
        stringRedisTemplate.opsForValue().multiSet(maps);
    }

    /**
     *           key-value  ,         key     
     *
     * @param maps
     * @return         false,     true
     */
    public boolean multiSetIfAbsent(Map maps) {
        return stringRedisTemplate.opsForValue().multiSetIfAbsent(maps);
    }

    /**
     *   (   ),       
     *
     * @param key
     * @param increment
     * @return
     */
    public Long incrBy(String key, long increment) {
        return stringRedisTemplate.opsForValue().increment(key, increment);
    }

    /**
     *
     * @param key
     * @param increment
     * @return
     */
    public Double incrByFloat(String key, double increment) {
        return stringRedisTemplate.opsForValue().increment(key, increment);
    }

    /**
     *      
     *
     * @param key
     * @param value
     * @return
     */
    public Integer append(String key, String value) {
        return stringRedisTemplate.opsForValue().append(key, value);
    }

    /** -------------------hash    ------------------------- */

    /**
     *                
     *
     * @param key
     * @param field
     * @return
     */
    public Object hGet(String key, String field) {
        return stringRedisTemplate.opsForHash().get(key, field);
    }

    /**
     *           
     *
     * @param key
     * @return
     */
    public Map hGetAll(String key) {
        return stringRedisTemplate.opsForHash().entries(key);
    }

    /**
     *           
     *
     * @param key
     * @param fields
     * @return
     */
    public List hMultiGet(String key, Collection fields) {
        return stringRedisTemplate.opsForHash().multiGet(key, fields);
    }

    public void hPut(String key, String hashKey, String value) {
        stringRedisTemplate.opsForHash().put(key, hashKey, value);
    }

    public void hPutAll(String key, Map maps) {
        stringRedisTemplate.opsForHash().putAll(key, maps);
    }

    /**
     *   hashKey       
     *
     * @param key
     * @param hashKey
     * @param value
     * @return
     */
    public Boolean hPutIfAbsent(String key, String hashKey, String value) {
        return stringRedisTemplate.opsForHash().putIfAbsent(key, hashKey, value);
    }

    /**
     *             
     *
     * @param key
     * @param fields
     * @return
     */
    public Long hDelete(String key, Object... fields) {
        return stringRedisTemplate.opsForHash().delete(key, fields);
    }

    /**
     *       key  ,         
     *
     * @param key
     * @param field
     * @return
     */
    public boolean hExists(String key, String field) {
        return stringRedisTemplate.opsForHash().hasKey(key, field);
    }

    /**
     *      key                increment
     *
     * @param key
     * @param field
     * @param increment
     * @return
     */
    public Long hIncrBy(String key, Object field, long increment) {
        return stringRedisTemplate.opsForHash().increment(key, field, increment);
    }

    /**
     *      key                increment
     *
     * @param key
     * @param field
     * @param delta
     * @return
     */
    public Double hIncrByFloat(String key, Object field, double delta) {
        return stringRedisTemplate.opsForHash().increment(key, field, delta);
    }

    /**
     *            
     *
     * @param key
     * @return
     */
    public Set hKeys(String key) {
        return stringRedisTemplate.opsForHash().keys(key);
    }

    /**
     *            
     *
     * @param key
     * @return
     */
    public Long hSize(String key) {
        return stringRedisTemplate.opsForHash().size(key);
    }

    /**
     *          
     *
     * @param key
     * @return
     */
    public List hValues(String key) {
        return stringRedisTemplate.opsForHash().values(key);
    }

    /**
     *           
     *
     * @param key
     * @param options
     * @return
     */
    public Cursor> hScan(String key, ScanOptions options) {
        return stringRedisTemplate.opsForHash().scan(key, options);
    }

    /** ------------------------list    ---------------------------- */

    /**
     *             
     *
     * @param key
     * @param index
     * @return
     */
    public String lIndex(String key, long index) {
        return stringRedisTemplate.opsForList().index(key, index);
    }

    /**
     *             
     *
     * @param key
     * @param start
     *                , 0     
     * @param end
     *                , -1    
     * @return
     */
    public List lRange(String key, long start, long end) {
        return stringRedisTemplate.opsForList().range(key, start, end);
    }

    /**
     *    list  
     *
     * @param key
     * @param value
     * @return
     */
    public Long lLeftPush(String key, String value) {
        return stringRedisTemplate.opsForList().leftPush(key, value);
    }

    /**
     *
     * @param key
     * @param value
     * @return
     */
    public Long lLeftPushAll(String key, String... value) {
        return stringRedisTemplate.opsForList().leftPushAll(key, value);
    }

    /**
     *
     * @param key
     * @param value
     * @return
     */
    public Long lLeftPushAll(String key, Collection value) {
        return stringRedisTemplate.opsForList().leftPushAll(key, value);
    }

    /**
     *  list        
     *
     * @param key
     * @param value
     * @return
     */
    public Long lLeftPushIfPresent(String key, String value) {
        return stringRedisTemplate.opsForList().leftPushIfPresent(key, value);
    }

    /**
     *   pivot  , pivot    
     *
     * @param key
     * @param pivot
     * @param value
     * @return
     */
    public Long lLeftPush(String key, String pivot, String value) {
        return stringRedisTemplate.opsForList().leftPush(key, pivot, value);
    }

    /**
     *
     * @param key
     * @param value
     * @return
     */
    public Long lRightPush(String key, String value) {
        return stringRedisTemplate.opsForList().rightPush(key, value);
    }

    /**
     *
     * @param key
     * @param value
     * @return
     */
    public Long lRightPushAll(String key, String... value) {
        return stringRedisTemplate.opsForList().rightPushAll(key, value);
    }

    /**
     *
     * @param key
     * @param value
     * @return
     */
    public Long lRightPushAll(String key, Collection value) {
        return stringRedisTemplate.opsForList().rightPushAll(key, value);
    }

    /**
     *           
     *
     * @param key
     * @param value
     * @return
     */
    public Long lRightPushIfPresent(String key, String value) {
        return stringRedisTemplate.opsForList().rightPushIfPresent(key, value);
    }

    /**
     *  pivot        
     *
     * @param key
     * @param pivot
     * @param value
     * @return
     */
    public Long lRightPush(String key, String pivot, String value) {
        return stringRedisTemplate.opsForList().rightPush(key, pivot, value);
    }

    /**
     *             
     *
     * @param key
     * @param index
     *              
     * @param value
     */
    public void lSet(String key, long index, String value) {
        stringRedisTemplate.opsForList().set(key, index, value);
    }

    /**
     *              
     *
     * @param key
     * @return      
     */
    public String lLeftPop(String key) {
        return stringRedisTemplate.opsForList().leftPop(key);
    }

    /**
     *              ,                              
     *
     * @param key
     * @param timeout
     *                
     * @param unit
     *                
     * @return
     */
    public String lBLeftPop(String key, long timeout, TimeUnit unit) {
        return stringRedisTemplate.opsForList().leftPop(key, timeout, unit);
    }

    /**
     *              
     *
     * @param key
     * @return      
     */
    public String lRightPop(String key) {
        return stringRedisTemplate.opsForList().rightPop(key);
    }

    /**
     *               ,                              
     *
     * @param key
     * @param timeout
     *                
     * @param unit
     *                
     * @return
     */
    public String lBRightPop(String key, long timeout, TimeUnit unit) {
        return stringRedisTemplate.opsForList().rightPop(key, timeout, unit);
    }

    /**
     *            ,                
     *
     * @param sourceKey
     * @param destinationKey
     * @return
     */
    public String lRightPopAndLeftPush(String sourceKey, String destinationKey) {
        return stringRedisTemplate.opsForList().rightPopAndLeftPush(sourceKey,
                destinationKey);
    }

    /**
     *          ,                    ;                              
     *
     * @param sourceKey
     * @param destinationKey
     * @param timeout
     * @param unit
     * @return
     */
    public String lBRightPopAndLeftPush(String sourceKey, String destinationKey,
            long timeout, TimeUnit unit) {
        return stringRedisTemplate.opsForList().rightPopAndLeftPush(sourceKey,
                destinationKey, timeout, unit);
    }

    /**
     *         value   
     *
     * @param key
     * @param index
     *            index=0,        value   ; index>0,              value   ;
     *            index<0,              value   ;
     * @param value
     * @return
     */
    public Long lRemove(String key, long index, String value) {
        return stringRedisTemplate.opsForList().remove(key, index, value);
    }

    /**
     *   list
     *
     * @param key
     * @param start
     * @param end
     */
    public void lTrim(String key, long start, long end) {
        stringRedisTemplate.opsForList().trim(key, start, end);
    }

    /**
     *       
     *
     * @param key
     * @return
     */
    public Long lLen(String key) {
        return stringRedisTemplate.opsForList().size(key);
    }

    /** --------------------set    -------------------------- */

    /**
     * set    
     *
     * @param key
     * @param values
     * @return
     */
    public Long sAdd(String key, String... values) {
        return stringRedisTemplate.opsForSet().add(key, values);
    }

    /**
     * set    
     *
     * @param key
     * @param values
     * @return
     */
    public Long sRemove(String key, Object... values) {
        return stringRedisTemplate.opsForSet().remove(key, values);
    }

    /**
     *               
     *
     * @param key
     * @return
     */
    public String sPop(String key) {
        return stringRedisTemplate.opsForSet().pop(key);
    }

    /**
     *    value            
     *
     * @param key
     * @param value
     * @param destKey
     * @return
     */
    public Boolean sMove(String key, String value, String destKey) {
        return stringRedisTemplate.opsForSet().move(key, value, destKey);
    }

    /**
     *        
     *
     * @param key
     * @return
     */
    public Long sSize(String key) {
        return stringRedisTemplate.opsForSet().size(key);
    }

    /**
     *         value
     *
     * @param key
     * @param value
     * @return
     */
    public Boolean sIsMember(String key, Object value) {
        return stringRedisTemplate.opsForSet().isMember(key, value);
    }

    /**
     *          
     *
     * @param key
     * @param otherKey
     * @return
     */
    public Set sIntersect(String key, String otherKey) {
        return stringRedisTemplate.opsForSet().intersect(key, otherKey);
    }

    /**
     *   key          
     *
     * @param key
     * @param otherKeys
     * @return
     */
    public Set sIntersect(String key, Collection otherKeys) {
        return stringRedisTemplate.opsForSet().intersect(key, otherKeys);
    }

    /**
     * key   otherKey        destKey   
     *
     * @param key
     * @param otherKey
     * @param destKey
     * @return
     */
    public Long sIntersectAndStore(String key, String otherKey, String destKey) {
        return stringRedisTemplate.opsForSet().intersectAndStore(key, otherKey,
                destKey);
    }

    /**
     * key             destKey   
     *
     * @param key
     * @param otherKeys
     * @param destKey
     * @return
     */
    public Long sIntersectAndStore(String key, Collection otherKeys,
            String destKey) {
        return stringRedisTemplate.opsForSet().intersectAndStore(key, otherKeys,
                destKey);
    }

    /**
     *          
     *
     * @param key
     * @param otherKeys
     * @return
     */
    public Set sUnion(String key, String otherKeys) {
        return stringRedisTemplate.opsForSet().union(key, otherKeys);
    }

    /**
     *   key          
     *
     * @param key
     * @param otherKeys
     * @return
     */
    public Set sUnion(String key, Collection otherKeys) {
        return stringRedisTemplate.opsForSet().union(key, otherKeys);
    }

    /**
     * key   otherKey        destKey 
     *
     * @param key
     * @param otherKey
     * @param destKey
     * @return
     */
    public Long sUnionAndStore(String key, String otherKey, String destKey) {
        return stringRedisTemplate.opsForSet().unionAndStore(key, otherKey, destKey);
    }

    /**
     * key             destKey 
     *
     * @param key
     * @param otherKeys
     * @param destKey
     * @return
     */
    public Long sUnionAndStore(String key, Collection otherKeys,
            String destKey) {
        return stringRedisTemplate.opsForSet().unionAndStore(key, otherKeys, destKey);
    }

    /**
     *          
     *
     * @param key
     * @param otherKey
     * @return
     */
    public Set sDifference(String key, String otherKey) {
        return stringRedisTemplate.opsForSet().difference(key, otherKey);
    }

    /**
     *   key          
     *
     * @param key
     * @param otherKeys
     * @return
     */
    public Set sDifference(String key, Collection otherKeys) {
        return stringRedisTemplate.opsForSet().difference(key, otherKeys);
    }

    /**
     * key   otherKey        destKey 
     *
     * @param key
     * @param otherKey
     * @param destKey
     * @return
     */
    public Long sDifference(String key, String otherKey, String destKey) {
        return stringRedisTemplate.opsForSet().differenceAndStore(key, otherKey,
                destKey);
    }

    /**
     * key             destKey 
     *
     * @param key
     * @param otherKeys
     * @param destKey
     * @return
     */
    public Long sDifference(String key, Collection otherKeys,
            String destKey) {
        return stringRedisTemplate.opsForSet().differenceAndStore(key, otherKeys,
                destKey);
    }

    /**
     *         
     *
     * @param key
     * @return
     */
    public Set setMembers(String key) {
        return stringRedisTemplate.opsForSet().members(key);
    }

    /**
     *             
     *
     * @param key
     * @return
     */
    public String sRandomMember(String key) {
        return stringRedisTemplate.opsForSet().randomMember(key);
    }

    /**
     *        count   
     *
     * @param key
     * @param count
     * @return
     */
    public List sRandomMembers(String key, long count) {
        return stringRedisTemplate.opsForSet().randomMembers(key, count);
    }

    /**
     *        count          
     *
     * @param key
     * @param count
     * @return
     */
    public Set sDistinctRandomMembers(String key, long count) {
        return stringRedisTemplate.opsForSet().distinctRandomMembers(key, count);
    }

    /**
     *
     * @param key
     * @param options
     * @return
     */
    public Cursor sScan(String key, ScanOptions options) {
        return stringRedisTemplate.opsForSet().scan(key, options);
    }

    /**------------------zSet    --------------------------------*/

    /**
     *     ,          score       
     *
     * @param key
     * @param value
     * @param score
     * @return
     */
    public Boolean zAdd(String key, String value, double score) {
        return stringRedisTemplate.opsForZSet().add(key, value, score);
    }

    /**
     *
     * @param key
     * @param values
     * @return
     */
    public Long zAdd(String key, Set> values) {
        return stringRedisTemplate.opsForZSet().add(key, values);
    }

    /**
     *
     * @param key
     * @param values
     * @return
     */
    public Long zRemove(String key, Object... values) {
        return stringRedisTemplate.opsForZSet().remove(key, values);
    }

    /**
     *      score ,        
     *
     * @param key
     * @param value
     * @param delta
     * @return
     */
    public Double zIncrementScore(String key, String value, double delta) {
        return stringRedisTemplate.opsForZSet().incrementScore(key, value, delta);
    }

    /**
     *           ,          score       
     *
     * @param key
     * @param value
     * @return 0     
     */
    public Long zRank(String key, Object value) {
        return stringRedisTemplate.opsForZSet().rank(key, value);
    }

    /**
     *           ,    score       
     *
     * @param key
     * @param value
     * @return
     */
    public Long zReverseRank(String key, Object value) {
        return stringRedisTemplate.opsForZSet().reverseRank(key, value);
    }

    /**
     *        ,       
     *
     * @param key
     * @param start
     *                
     * @param end
     *                , -1    
     * @return
     */
    public Set zRange(String key, long start, long end) {
        return stringRedisTemplate.opsForZSet().range(key, start, end);
    }

    /**
     *       ,    score    
     *
     * @param key
     * @param start
     * @param end
     * @return
     */
    public Set> zRangeWithScores(String key, long start,
            long end) {
        return stringRedisTemplate.opsForZSet().rangeWithScores(key, start, end);
    }

    /**
     *   Score       
     *
     * @param key
     * @param min
     *               
     * @param max
     *               
     * @return
     */
    public Set zRangeByScore(String key, double min, double max) {
        return stringRedisTemplate.opsForZSet().rangeByScore(key, min, max);
    }

    /**
     *   Score       ,       
     *
     * @param key
     * @param min
     *               
     * @param max
     *               
     * @return
     */
    public Set> zRangeByScoreWithScores(String key,
            double min, double max) {
        return stringRedisTemplate.opsForZSet().rangeByScoreWithScores(key, min, max);
    }

    /**
     *
     * @param key
     * @param min
     * @param max
     * @param start
     * @param end
     * @return
     */
    public Set> zRangeByScoreWithScores(String key,
            double min, double max, long start, long end) {
        return stringRedisTemplate.opsForZSet().rangeByScoreWithScores(key, min, max,
                start, end);
    }

    /**
     *        ,       
     *
     * @param key
     * @param start
     * @param end
     * @return
     */
    public Set zReverseRange(String key, long start, long end) {
        return stringRedisTemplate.opsForZSet().reverseRange(key, start, end);
    }

    /**
     *        ,       ,    score 
     *
     * @param key
     * @param start
     * @param end
     * @return
     */
    public Set> zReverseRangeWithScores(String key,
            long start, long end) {
        return stringRedisTemplate.opsForZSet().reverseRangeWithScores(key, start,
                end);
    }

    /**
     *   Score       ,       
     *
     * @param key
     * @param min
     * @param max
     * @return
     */
    public Set zReverseRangeByScore(String key, double min,
            double max) {
        return stringRedisTemplate.opsForZSet().reverseRangeByScore(key, min, max);
    }

    /**
     *   Score       ,       
     *
     * @param key
     * @param min
     * @param max
     * @return
     */
    public Set> zReverseRangeByScoreWithScores(
            String key, double min, double max) {
        return stringRedisTemplate.opsForZSet().reverseRangeByScoreWithScores(key,
                min, max);
    }

    /**
     *
     * @param key
     * @param min
     * @param max
     * @param start
     * @param end
     * @return
     */
    public Set zReverseRangeByScore(String key, double min,
            double max, long start, long end) {
        return stringRedisTemplate.opsForZSet().reverseRangeByScore(key, min, max,
                start, end);
    }

    /**
     *   score         
     *
     * @param key
     * @param min
     * @param max
     * @return
     */
    public Long zCount(String key, double min, double max) {
        return stringRedisTemplate.opsForZSet().count(key, min, max);
    }

    /**
     *       
     *
     * @param key
     * @return
     */
    public Long zSize(String key) {
        return stringRedisTemplate.opsForZSet().size(key);
    }

    /**
     *       
     *
     * @param key
     * @return
     */
    public Long zZCard(String key) {
        return stringRedisTemplate.opsForZSet().zCard(key);
    }

    /**
     *      value   score 
     *
     * @param key
     * @param value
     * @return
     */
    public Double zScore(String key, Object value) {
        return stringRedisTemplate.opsForZSet().score(key, value);
    }

    /**
     *            
     *
     * @param key
     * @param start
     * @param end
     * @return
     */
    public Long zRemoveRange(String key, long start, long end) {
        return stringRedisTemplate.opsForZSet().removeRange(key, start, end);
    }

    /**
     *      score         
     *
     * @param key
     * @param min
     * @param max
     * @return
     */
    public Long zRemoveRangeByScore(String key, double min, double max) {
        return stringRedisTemplate.opsForZSet().removeRangeByScore(key, min, max);
    }

    /**
     *   key otherKey       destKey 
     *
     * @param key
     * @param otherKey
     * @param destKey
     * @return
     */
    public Long zUnionAndStore(String key, String otherKey, String destKey) {
        return stringRedisTemplate.opsForZSet().unionAndStore(key, otherKey, destKey);
    }

    /**
     *
     * @param key
     * @param otherKeys
     * @param destKey
     * @return
     */
    public Long zUnionAndStore(String key, Collection otherKeys,
            String destKey) {
        return stringRedisTemplate.opsForZSet()
                .unionAndStore(key, otherKeys, destKey);
    }

    /**
     *   
     *
     * @param key
     * @param otherKey
     * @param destKey
     * @return
     */
    public Long zIntersectAndStore(String key, String otherKey,
            String destKey) {
        return stringRedisTemplate.opsForZSet().intersectAndStore(key, otherKey,
                destKey);
    }

    /**
     *   
     *
     * @param key
     * @param otherKeys
     * @param destKey
     * @return
     */
    public Long zIntersectAndStore(String key, Collection otherKeys,
            String destKey) {
        return stringRedisTemplate.opsForZSet().intersectAndStore(key, otherKeys,
                destKey);
    }

    /**
     *
     * @param key
     * @param options
     * @return
     */
    public Cursor> zScan(String key, ScanOptions options) {
        return stringRedisTemplate.opsForZSet().scan(key, options);
    }

    /**
     *   map  :     :https://www.jianshu.com/p/7bf5dc61ca06
     * @param key           :    map key
     * @param mapData       :   map 
     * @param timeout       :    ,-1:      
     * @param unit          :    
     */
    public void setMap(String key, Map mapData, Long timeout, TimeUnit unit) {
        //      
        //for (Map.Entry entry : mapData.entrySet()) {
        //  redisTemplate.opsForHash().put(key,entry.getKey(),entry.getValue());
        //}

        redisTemplate.opsForHash().putAll(key,mapData);

        if (timeout.longValue() >= 0L) {
            redisTemplate.expire(key, timeout.longValue(), unit);
        }
    }

    /**
     *  redis  key map    (mapKey,mapValue)
     *     :https://www.jianshu.com/p/7bf5dc61ca06
     *
     * @param key           :redis   map key 
     * @param mapKey        :map key mapKey
     * @param mapValue      :map  value  mapValue
     */
    public void putMapOneKV(String key,String mapKey,Object mapValue) {
        redisTemplate.opsForHash().put(key,mapKey,mapValue);
    }

    /**
     *   redis  key map  hashKeys   
     * @param key
     * @param mapKyes
     * @return
     */
    public void deleteMapOneK(String key,String... mapKyes) {
        for (String hashKey : mapKyes) {
            redisTemplate.opsForHash().delete(key,hashKey);
        }
    }

    /**
     *   map 
     * @param key
     */
    public void deleteMap(String key) {
        //  key  
        redisTemplate.expire(key, 0, TimeUnit.MILLISECONDS);
    }

    /**
     *    redis  key map  
     * @param key     :reids  key 
     * @return
     */
    public Map getMap(String key) {
        return redisTemplate.opsForHash().entries(key);
    }

    /**
     *    redis    map     
     * @param key
     * @return
     */
    public Long getMapSize(String key) {
        return redisTemplate.opsForHash().size(key);
    }

    /**
     *     ,             setObject
     *
     * @param key
     * @return
     */
    public Object getObject(final String key) {
        Object result = null;
        ValueOperations operations = redisTemplate.opsForValue();
        result = operations.get(key);
        return result;
    }

    /**
     *     ,        setObject  ,       getObject  
     * @param key
     * @param value
     * @return
     */
    public Object setObject(final String key, Object value) {
        boolean result = false;
        try {
            ValueOperations operations = redisTemplate.opsForValue();
            operations.set(key, value);
            result = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

}