搜索词>>redis 耗时0.0140
  • redis 命令查看使用情况redis info命令详解_redis查看内存使用情况

    redis 命令查看使用情况redis info命令详解,redis查看内存使用情况。redis info命令的详细解释<p>通过redis-cli连接到redis服务</p> <pre> <code class="language-html">redis-cli -h 192.168.1.3 -p 6300 192.168.1.3:6300> 192.168.1.3:6300> auth pass 192.168.1.3:6300> info all</code></pre> <pre> <code class="language-bash"># Server(服务器信息) redis_version:3.0.0                              #redis服务器版本 redis_git_sha1:00000000                  #Git SHA1 redis_git_dirty:0                                    #Git dirty flag redis_build_id:6c2c390b97607ff0    #redis build id redis_mode:cluster                              #运行模式,单机或者集群 os:Linux 2.6.32-358.2.1.el6.x86_64 x86_64 #redis服务器的宿主操作系统 arch_bits:64                                         #架构(32或64位) multiplexing_api:epoll                        #redis所使用的事件处理机制 gcc_version:4.4.7                                #编译redis时所使用的gcc版本 process_id:12099                               #redis服务器进程的pid run_id:63bcd0e57adb695ff0bf873cf42d403ddbac1565  #redis服务器的随机标识符(用于sentinel和集群) tcp_port:9021                                #redis服务器监听端口 uptime_in_seconds:26157730   #redis服务器启动总时间,单位是秒 uptime_in_days:302                    #redis服务器启动总时间,单位是天 hz:10                                #redis内部调度(进行关闭timeout的客户端,删除过期key等等)频率,程序规定serverCron每秒运行10次。 lru_clock:14359959      #自增的时钟,用于LRU管理,该时钟100ms(hz=10,因此每1000ms/10=100ms执行一次定时任务)更新一次。 config_file:/redis_cluster/etc/9021.conf  #配置文件路径 # Clients(已连接客户端信息) connected_clients:1081       #已连接客户端的数量(不包括通过slave连接的客户端) client_longest_output_list:0 #当前连接的客户端当中,最长的输出列表,用client list命令观察omem字段最大值 client_biggest_input_buf:0   #当前连接的客户端当中,最大输入缓存,用client list命令观察qbuf和qbuf-free两个字段最大值 blocked_clients:0                   #正在等待阻塞命令(BLPOP、BRPOP、BRPOPLPUSH)的客户端的数量 # Memory(内存信息) used_memory:327494024                 #由redis分配器分配的内存总量,以字节为单位 used_memory_human:312.32M       #以人类可读的格式返回redis分配的内存总量 used_memory_rss:587247616         #从操作系统的角度,返回redis已分配的内存总量(俗称常驻集大小)。这个值和top命令的输出一致 used_memory_peak:1866541112    #redis的内存消耗峰值(以字节为单位)  used_memory_peak_human:1.74G #以人类可读的格式返回redis的内存消耗峰值 used_memory_lua:35840                   #lua引擎所使用的内存大小(以字节为单位) mem_fragmentation_ratio:1.79          #used_memory_rss和used_memory之间的比率,小于1表示使用了swap,大于1表示碎片比较多 mem_allocator:jemalloc-3.6.0            #在编译时指定的redis所使用的内存分配器。可以是libc、jemalloc或者tcmalloc # Persistence(rdb和aof的持久化相关信息) loading:0                                                    #服务器是否正在载入持久化文件 rdb_changes_since_last_save:28900855 #离最近一次成功生成rdb文件,写入命令的个数,即有多少个写入命令没有持久化 rdb_bgsave_in_progress:0                  #服务器是否正在创建rdb文件 rdb_last_save_time:1482358115        #离最近一次成功创建rdb文件的时间戳。当前时间戳 - rdb_last_save_time=多少秒未成功生成rdb文件 rdb_last_bgsave_status:ok                   #最近一次rdb持久化是否成功 rdb_last_bgsave_time_sec:2                #最近一次成功生成rdb文件耗时秒数 rdb_current_bgsave_time_sec:-1        #如果服务器正在创建rdb文件,那么这个域记录的就是当前的创建操作已经耗费的秒数 aof_enabled:1                                          #是否开启了aof aof_rewrite_in_progress:0                     #标识aof的rewrite操作是否在进行中 aof_rewrite_scheduled:0               #rewrite任务计划,当客户端发送bgrewriteaof指令,如果当前rewrite子进程正在执行,那么将客户端请求的bgrewriteaof变为计划任务,待aof子进程结束后执行rewrite  aof_last_rewrite_time_sec:-1            #最近一次aof rewrite耗费的时长 aof_current_rewrite_time_sec:-1      #如果rewrite操作正在进行,则记录所使用的时间,单位秒 aof_last_bgrewrite_status:ok             #上次bgrewriteaof操作的状态 aof_last_write_status:ok                     #上次aof写入状态 aof_current_size:4201740                 #aof当前尺寸 aof_base_size:4201687                    #服务器启动时或者aof重写最近一次执行之后aof文件的大小 aof_pending_rewrite:0                       #是否有aof重写操作在等待rdb文件创建完毕之后执行? aof_buffer_length:0                             #aof buffer的大小 aof_rewrite_buffer_length:0              #aof rewrite buffer的大小 aof_pending_bio_fsync:0                  #后台I/O队列里面,等待执行的fsync调用数量 aof_delayed_fsync:0                          #被延迟的fsync调用数量 # Stats(一般统计信息) total_connections_received:209561105 #新创建连接个数,如果新创建连接过多,过度地创建和销毁连接对性能有影响,说明短连接严重或连接池使用有问题,需调研代码的连接设置 total_commands_processed:2220123478  #redis处理的命令数 instantaneous_ops_per_sec:279                  #redis当前的qps,redis内部较实时的每秒执行的命令数 total_net_input_bytes:118515678789          #redis网络入口流量字节数 total_net_output_bytes:236361651271       #redis网络出口流量字节数 instantaneous_input_kbps:13.56                  #redis网络入口kps instantaneous_output_kbps:31.33               #redis网络出口kps rejected_connections:0                                   #拒绝的连接个数,redis连接个数达到maxclients限制,拒绝新连接的个数 sync_full:1                                                          #主从完全同步成功次数 sync_partial_ok:0                                             #主从部分同步成功次数 sync_partial_err:0                                            #主从部分同步失败次数 expired_keys:15598177                                #运行以来过期的key的数量 evicted_keys:0                                                 #运行以来剔除(超过了maxmemory后)的key的数量 keyspace_hits:1122202228                          #命中次数 keyspace_misses:577781396                     #没命中次数 pubsub_channels:0                                       #当前使用中的频道数量 pubsub_patterns:0                                         #当前使用的模式的数量 latest_fork_usec:15679                                 #最近一次fork操作阻塞redis进程的耗时数,单位微秒 migrate_cached_sockets:0                          # # Replication(主从信息,master上显示的信息) role:master                               #实例的角色,是master or slave connected_slaves:1              #连接的slave实例个数 slave0:ip=192.168.64.104,port=9021,state=online,offset=6713173004,lag=0 #lag从库多少秒未向主库发送REPLCONF命令 master_repl_offset:6713173145  #主从同步偏移量,此值如果和上面的offset相同说明主从一致没延迟 repl_backlog_active:1                   #复制积压缓冲区是否开启 repl_backlog_size:134217728    #复制积压缓冲大小 repl_backlog_first_byte_offset:6578955418  #复制缓冲区里偏移量的大小 repl_backlog_histlen:134217728   #此值等于 master_repl_offset - repl_backlog_first_byte_offset,该值不会超过repl_backlog_size的大小 # Replication(主从信息,slave上显示的信息) role:slave                                        #实例的角色,是master or slave master_host:192.168.64.102       #此节点对应的master的ip master_port:9021                          #此节点对应的master的port master_link_status:up                   #slave端可查看它与master之间同步状态,当复制断开后表示down master_last_io_seconds_ago:0  #主库多少秒未发送数据到从库? master_sync_in_progress:0        #从服务器是否在与主服务器进行同步 slave_repl_offset:6713173818   #slave复制偏移量 slave_priority:100                          #slave优先级 slave_read_only:1                         #从库是否设置只读 connected_slaves:0                      #连接的slave实例个数 master_repl_offset:0          repl_backlog_active:0                  #复制积压缓冲区是否开启 repl_backlog_size:134217728   #复制积压缓冲大小 repl_backlog_first_byte_offset:0 #复制缓冲区里偏移量的大小 repl_backlog_histlen:0           #此值等于 master_repl_offset - repl_backlog_first_byte_offset,该值不会超过repl_backlog_size的大小 # CPU(CPU计算量统计信息) used_cpu_sys:96894.66             #将所有redis主进程在核心态所占用的CPU时求和累计起来 used_cpu_user:87397.39           #将所有redis主进程在用户态所占用的CPU时求和累计起来 used_cpu_sys_children:6.37     #将后台进程在核心态所占用的CPU时求和累计起来 used_cpu_user_children:52.83 #将后台进程在用户态所占用的CPU时求和累计起来 # Commandstats(各种不同类型的命令的执行统计信息) cmdstat_get:calls=1664657469,usec=8266063320,usec_per_call=4.97   #call每个命令执行次数,usec总共消耗的CPU时长(单位微秒),平均每次消耗的CPU时长(单位微秒) # Cluster(集群相关信息) cluster_enabled:1   #实例是否启用集群模式 # Keyspace(数据库相关的统计信息) db0:keys=194690,expires=191702,avg_ttl=3607772262 #db0的key的数量,以及带有生存期的key的数,平均存活时间</code></pre>
  • Redis 删除/清除数据

    Redis 删除/清除数据​​​​​​​1.访问redis根目录    cd  /usr/local/redis-2.8.192.登录redis:redis-cli -h 127.0.0.1 -p 63793.查看所有key值:keys *Redis 删除/清除数据​​​​​​​1.访问redis根目录    cd  /usr/local/redis-2.8.192.登录redis:redis-cli -h 127.0.0.1 -p 63793.查看所有key值:keys *4.删除指定索引的值:del key5.清空整个 Redis 服务器的数据:flushall 6.清空当前库中的所有 key:flushdb 
  • Redis 禁用持久化配置

    Redis 禁用持久化配置Redis 禁用持久化配置
  • redis在window系统上的下载安装使用说明

    redis在window系统上的下载安装使用说明redis在window系统上的下载安装使用说明<br /> 去redis的官方网站你会发现下载下来的都是源码,支持Linux的make编译方式,并没有window版本的redis下载,其实官方有说明 <h3>Windows</h3> The Redis project does not officially support Windows. However, the Microsoft Open Tech group develops and maintains this Windows port targeting Win64. <a href="https://github.com/MSOpenTech/redis" rel="external nofollow" target="_blank" >Learn more</a><br /> 大概就是说:<br /> Redis项目没有正式支持Windows。 但是,Microsoft Open Tech组织开发并维护了面向Win64的Windows 64位<br /> 也就是说window版本是不是由redis官方维护的,是Microsoft Open Tech组织。其项目的GitHub地址为<br /> <a href="http://github.com/MSOpenTech/redis" rel="external nofollow" target="_blank" >http://github.com/MSOpenTech/redis</a><br /> <br /> 下载步骤,打开上面的url,你将看到以下界面(可能会有一点版本变化): <div style="text-align:center"> <figure class="image" style="display:inline-block"><img srcset="" width="" size="" class="img-thumbnail" alt="下载页面" src="/resources/assist/images/blog/0838f0d2-178b-4181-94a0-8517074e979a.png" /> <figcaption>下载页面</figcaption> </figure> </div> <br /> <br /> 点击release<br /> <img srcset="" width="" size="" class="img-thumbnail" alt="re" src="/resources/assist/images/blog/2a4956c9-d247-48c4-b896-8a9405a14507.png" /><br /> 这时候你就可以看到下载的页面: <div style="text-align:center"> <figure class="image" style="display:inline-block"><img srcset="" width="" size="" class="img-thumbnail" alt="download redis" src="/resources/assist/images/blog/244c4b23-eb9d-44fa-8100-ab017c20a658.png" /> <figcaption>download redis</figcaption> </figure> </div> <br /> <br /> 选择zip版或者msi版本,我这里下载的zip版本下载.<br /> <br /> <br /> 加压下载后的zip: <figure class="image"><img srcset="" width="" size="" class="img-thumbnail" alt="解压文件" src="/resources/assist/images/blog/8d7d6242-404d-4f9e-98b2-3ac65284ffd0.png" /> <figcaption>解压文件</figcaption> </figure> <br /> <br /> 使用cmd执行命令 <pre> <code>F:\迅雷下载\Redis-x64-3.2.100>redis-server.exe redis.windows.conf</code></pre> <strong><span style="color:#ff0000">注意前面的路径改成你自己的路径</span></strong> <div style="text-align:center"> <figure class="image" style="display:inline-block"><img srcset="" width="" size="" class="img-thumbnail" alt="启动redis成功" src="/resources/assist/images/blog/6cdd0fda-90f4-45b1-8a7b-5f52880d2d16.png" /> <figcaption>启动redis成功</figcaption> </figure> </div> <br /> <br /> 到这里window系统上如何下载安装和启动redis已经完成。<br /> <br /> 将redis安装成系统服务: <pre> <code>redis-server.exe --service-install redis.windows.conf --loglevel verbose </code></pre> <br /> 卸载服务: <pre> <code>redis-server --service-uninstall </code></pre>  <br /> <br /> ------------------------------------------<br /> 由网友Clay提供最新的window版本 redis 下载地址:<a rel="external nofollow" target="_blank" href="https://github.com/tporadowski/redis/releases">https://github.com/tporadowski/redis/releases</a>【感谢支持】
  • MISCONF Redis is configured to save RDB snapshots...问题解决

    今天遇到Redis “MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk”的问题。这个错误信息是Redis客户端工具在保存数据时候抛出的异常信息。情况说明今天遇到Redis “MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk”的问题。这个错误信息是Redis客户端工具在保存数据时候抛出的异常信息。常规操作网上查了一下,很多人都是建议“config set stop-writes-on-bgsave-error no”。这样做其实是不好的,这仅仅是让程序忽略了这个异常,使得程序能够继续往下运行,但实际上数据还是会存储到硬盘失败!上一次遇到这个问题是因为一个程序的Bug造成系统内存被耗尽了,后来修复了那个Bug问题就解决了。今天出现问题时查看系统内存还有2GB左右,“感觉好像不是内存的缘故”(后面发现还是因为内存的缘故)。日志监控由于Redis是daemon模式运行的,没法看到详细的日志。修改配置文件设置logfile参数为文件(默认是stdout,建议以后安装完毕就修改这个参数为文件,不然会丢掉很多重要信息),重启Redis,查看日志,看到程序启动时就有一行警告提示:“WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.”(警告:过量使用内存设置为0!在低内存环境下,后台保存可能失败。为了修正这个问题,请在/etc/sysctl.conf 添加一项 'vm.overcommit_memory = 1' ,然后重启(或者运行命令'sysctl vm.overcommit_memory=1' )使其生效。)当时没明白意思,就忽略了。再启动Redis客户端,程序保存数据时继续报“MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk”异常,再查看Redis日志,看到有这样的错误提示“Can’t save in background: fork: Cannot allocate memory”,这个提示很明显"Fork进程时内存不够用了!"(还是内存的问题)。了解Redis数据回写机制Redis的数据回写机制分同步和异步两种同步回写即SAVE命令,主进程直接向磁盘回写数据。在数据大的情况下会导致系统假死很长时间,所以一般不是推荐的。异步回写即BGSAVE命令,主进程fork后,复制自身并通过这个新的进程回写磁盘,回写结束后新进程自行关闭。由于这样做不需要主进程阻塞,系统不会假死,一般默认会采用这个方法。个人感觉方法2采用fork主进程的方式很拙劣,但似乎是唯一的方法。内存中的热数据随时可能修改,要在磁盘上保存某个时间的内存镜像必须要冻结。冻结就会导致假死。fork一个新的进程之后等于复制了当时的一个内存镜像,这样主进程上就不需要冻结,只要子进程上操作就可以了。在小内存的进程上做一个fork,不需要太多资源,但当这个进程的内存空间以G为单位时,fork就成为一件很恐怖的操作。何况在16G内存的主机上fork 14G内存的进程呢?肯定会报内存无法分配的。更可气的是,越是改动频繁的主机上fork也越频繁,fork操作本身的代价恐怕也不会比假死好多少。找到原因之后,直接修改内核参数vm.overcommit_memory = 1Linux内核会根据参数vm.overcommit_memory参数的设置决定是否放行。 如果 vm.overcommit_memory = 1,直接放行vm.overcommit_memory = 0:则比较 此次请求分配的虚拟内存大小和系统当前空闲的物理内存加上swap,决定是否放行。vm.overcommit_memory = 2:则会比较 进程所有已分配的虚拟内存加上此次请求分配的虚拟内存和系统当前的空闲物理内存加上swap,决定是否放行。为什么系统明明还剩2GB的内存,Redis会说内存不够呢?简单地说:Redis在保存数据到硬盘时为了避免主进程假死,需要Fork一份主进程,然后在Fork进程内完成数据保存到硬盘的操作,如果主进程使用了4GB的内存,Fork子进程的时候需要额外的4GB,此时内存就不够了,Fork失败,进而数据保存硬盘也失败了。另外磁盘满了也会报这个错误“MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk”
  • Java连接redis启动报错Error redis clients jedis HostAndPort cant resolve localhost address

    Java连接redis启动报错Error redis clients jedis HostAndPort cant resolve localhost address<h2>问题描述</h2> 错误环境:<br /> 本地window开发环境没有问题。上到Linux环境,启动出现问题。<br /> 错误信息:<br /> Error redis clients jedis HostAndPort cant resolve localhost address <pre> <code>15:44:52.039 [localhost-startStop-1] DEBUG o.m.spring.SqlSessionFactoryBean - Parsed mapper file: 'file [/data/website/test/filetest/WEB-INF/classes/com/cqax/business/dao/WebConfigMapper.xml]' 07-Aug-2017 15:44:52.529 SEVERE [localhost-startStop-1] redis.clients.jedis.HostAndPort.getLocalHostQuietly cant resolve localhost address java.net.UnknownHostException: template: template: Name or service not known at java.net.InetAddress.getLocalHost(InetAddress.java:1473) at redis.clients.jedis.HostAndPort.getLocalHostQuietly(HostAndPort.java:105) at redis.clients.jedis.HostAndPort.<clinit>(HostAndPort.java:12) at redis.clients.jedis.JedisFactory.<init>(JedisFactory.java:37) at redis.clients.jedis.JedisPool.<init>(JedisPool.java:185) at redis.clients.jedis.JedisPool.<init>(JedisPool.java:162) at redis.clients.jedis.JedisPool.<init>(JedisPool.java:92) at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.createRedisPool(JedisConnectionFactory.java:227) at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.createPool(JedisConnectionFactory.java:204) at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.afterPropertiesSet(JedisConnectionFactory.java:195) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1531) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:522) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:496) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:627) at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:169) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:318) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:372) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:634) at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:145) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1193) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1095) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrievalHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:92) at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:102) at org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.findCandidateAdvisors(AnnotationAwareAspectJAutoProxyCreator.java:88) at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:103) at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:248) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1037) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1011) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:473) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1531) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.aop.framework.autoproxy.BeanFactoryAdvisorRetrievalHelper.findAdvisorBeans(BeanFactoryAdvisorRetrievalHelper.java:92) at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findCandidateAdvisors(AbstractAdvisorAutoProxyCreator.java:102) at org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator.findCandidateAdvisors(AnnotationAwareAspectJAutoProxyCreator.java:88) at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.shouldSkip(AspectJAwareAdvisorAutoProxyCreator.java:103) at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessBeforeInstantiation(AbstractAutoProxyCreator.java:248) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1037) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveBeforeInstantiation(AbstractAutowireCapableBeanFactory.java:1011) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:473) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744) Caused by: java.net.UnknownHostException: template: Name or service not known at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901) at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293) at java.net.InetAddress.getLocalHost(InetAddress.java:1469) ... 149 more </code></pre> <h2>问题解决</h2> 解决办法:<br /> 1.查看Linux系统的主机名 <pre> <code>[root@template conf]# hostname template [root@template conf]# </code></pre> 2.查看/etc/hosts文件中是否有127.0.0.1对应主机名,如果没有则添加<br /> <br /> <img alt="查看hosts" class="img-thumbnail" src="/resources/assist/images/blog/c635cbc26ec7400faf5c052c25a159c2.png" />
  • spring boot 整合redis实现spring的缓存框架

    spring boot 1.5整合redis实现spring的缓存框架,spring boot,redisspring boot 整合redis实现spring的缓存框架<br /> <br /> 1.创建一个spring boot项目<br /> <img alt="项目" class="img-thumbnail" src="/resources/assist/images/blog/87917c2a16564cc08bf8e7670ec943ea.jpg" /><br /> 2.配置pom.xml文件 <pre> <code class="language-xml"><?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.leftso</groupId> <artifactId>demo-springboot-redis</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>demo-springboot-redis</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> </code></pre> <br /> 3.在spring boot的application配置文件中配置redis的相关信息 <pre> <code>####################Redis 配置信息 ########################## # Redis数据库分片索引(默认为0) spring.redis.database=0 # Redis服务器地址 spring.redis.host=10.1.1.134 # Redis服务器连接端口 spring.redis.port=6379 # Redis服务器连接密码(默认为空) spring.redis.password= # 连接池最大连接数(使用负值表示没有限制) spring.redis.pool.max-active=8 # 连接池最大阻塞等待时间(使用负值表示没有限制) spring.redis.pool.max-wait=-1 # 连接池中的最大空闲连接 spring.redis.pool.max-idle=8 # 连接池中的最小空闲连接 spring.redis.pool.min-idle=0 # 连接超时时间(毫秒) spring.redis.timeout=0</code></pre> <br /> 4.配置redis整合入spring的缓存框架 <pre> <code class="language-java">package com.leftso.config; import java.lang.reflect.Method; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.interceptor.KeyGenerator; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.cache.RedisCacheManager; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; @Configuration @EnableCaching // 继承CachingConfigurerSupport并重写方法,配合该注解实现spring缓存框架的启用 public class RedisConfig extends CachingConfigurerSupport { /** 载入通过配置文件配置的连接工场 **/ @Autowired RedisConnectionFactory redisConnectionFactory; @SuppressWarnings("rawtypes") @Autowired RedisTemplate redisTemplate; @Bean RedisTemplate<String, Object> objRedisTemplate() { RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>(); redisTemplate.setConnectionFactory(redisConnectionFactory); return redisTemplate; } /* * (non-Javadoc) * * @see org.springframework.cache.annotation.CachingConfigurerSupport# * cacheManager() */ @Bean // 必须添加此注解 @Override public CacheManager cacheManager() { RedisCacheManager redisCacheManager = new RedisCacheManager(redisTemplate); // 设置缓存过期时间 // redisCacheManager.setDefaultExpiration(60);//秒 return redisCacheManager; } /** * 重写缓存的key生成策略,可根据自身业务需要进行自己的配置生成条件 * * @see org.springframework.cache.annotation.CachingConfigurerSupport# * keyGenerator() */ @Bean // 必须项 @Override public KeyGenerator keyGenerator() { return new KeyGenerator() { @Override public Object generate(Object target, Method method, Object... params) { StringBuilder sb = new StringBuilder(); sb.append(target.getClass().getName()); sb.append(method.getName()); for (Object obj : params) { sb.append(obj.toString()); } return sb.toString(); } }; } } </code></pre> <br /> 5.创建一个测试的pojo和一个测试的controller <pre> <code class="language-java">package com.leftso.pojo; import java.io.Serializable; /** * * <pre> * [Summary] * 测试用简单类型 * [Detail] * TODO * [Author] * XQLEE * [Version] * v1.0 * 2017年5月8日上午9:58:42 * </pre> */ public class Address implements Serializable{ /** * */ private static final long serialVersionUID = 1L; private String id; private String city; private String detail; public Address() { } public Address(String id, String city, String detail) { super(); this.id = id; this.city = city; this.detail = detail; } /** * @return the id */ public String getId() { return id; } /** * @param id * the id to set */ public void setId(String id) { this.id = id; } /** * @return the city */ public String getCity() { return city; } /** * @param city * the city to set */ public void setCity(String city) { this.city = city; } /** * @return the detail */ public String getDetail() { return detail; } /** * @param detail * the detail to set */ public void setDetail(String detail) { this.detail = detail; } } </code></pre>   <pre> <code class="language-java">package com.leftso.controller; import org.springframework.cache.annotation.Cacheable; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import com.leftso.pojo.Address; @RestController public class CacheTestCtrl { @GetMapping("/getAddr") @Cacheable(value = "address-cache") // 设置缓存的名称,也可以通过key属性指定缓存的key,keyGenerator指定key生成策略器(keyGenerator一般推荐在重写CachingConfigurerSupport类里面的方法适合全局指定) public Address getAddress() { Address addr = new Address("001", "重庆市", "渝北区"); System.out.println("==========你看见这句话表示没有缓存时候打印出来的========"); return addr; } } </code></pre> <br /> 6.启动spring boot项目,访问地址localhost:8080/getAddr<br /> 第一次访问将会在控制台中看到以下输出:<br /> <img alt="1" class="img-thumbnail" src="/resources/assist/images/blog/8273e3645def48cfb209a482857ff0ab.jpg" /><br /> <br /> 后面多次刷新都不会进入到该方法中去读取信息,而是通过缓存直接读取了缓存信息。<br /> <br /> <br /> 至此spring boot整合redis 实现基本的缓存已经完成。
  • Redis 队列 Java调用简单实现

    简述在本博客中,我们将会创建一个reids的消息队列,Redis可以被当成消息队列使用简述在本博客中,我们将会创建一个reids的消息队列,Redis可以被当成消息队列使用。消息会被存放在一个key-value集合中。redis消息生产者使用RPUSH命令将消息添加到队列的尾部,而消息消费者可以使用BLPOP命令获取列表开头的消息,使用FIFO(先进先出)规则。注意:本博客前置条件,熟悉redis并且知道如何启动redis服务器Redis 队列实现需要的maven依赖<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.leftso.redis</groupId> <artifactId>message-queue</artifactId> <version>1.0.0-SNAPSHOT</version> <name>REDDIS - ${project.artifactId}</name> <url>http://leftso.com</url> <dependencies> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.7.2</version> </dependency> </dependencies> </project>Redis消息队列生产者 我们先使用rpush()方法将消息发布到mq-key队列中。这条消息将会添加到列表的最末端。import redis.clients.jedis.Jedis; public class MessageProducer { public static void main(String... args) { Jedis jedis = new Jedis("localhost"); jedis.rpush("mq-key", "first message"); jedis.rpush("mq-key", "second message"); jedis.rpush("mq-key", "third message"); } }Redis消息队列消费者 我们可以使用lpop()或者blpop()方法来消费消息。下面我们将会使用阻塞的lpop 方法,就如方法名称一样,使用该方法线程会进入阻塞状态直到下一个消息过来。我们可以设置一个等待消息的超时时间。下面设置的超时时间为0,表示永久等待没有超时时间。import redis.clients.jedis.Jedis; import java.util.List; public class MessageConsumer { private static final int TIMEOUT = 0; public static void main(String... args ) { Jedis jedis = new Jedis("localhost"); while(true){ System.out.println("Waiting for a message in the queue"); List<String> messages = jedis.blpop(TIMEOUT, "mq-key"); System.out.println("received message with key:" + messages.get(0) + " with value:" + messages.get(1)); } } }启动消息队列消费者$title(console) Waiting for a message in the queue启动消息队列生产者$title(console) Waiting for a message in the queue received message with key:mq-key with value:first message Waiting for a message in the queue received message with key:mq-key with value:second message Waiting for a message in the queue received message with key:mq-key with value:third message Waiting for a message in the queue参考文档:Redis RPUSH DocRedis BLPOP Doc代码段 小部件
  • spring boot 2.0 Redis整合_spring boot 2.0 集成Redis实现缓存框架(一)

    Spring Boot 2.0 Redis整合,通过spring boot 2.0整合Redis作为spring缓存框架的实现。spring boot 2.0 Redis整合_spring boot 2.0 集成Redis实现缓存框架(一)
  • centos7 redis安装配置以及集群

    centos7 redis安装配置以及集群//可直接 yum install redis-server<br /> =====以下为源码安装方式=====<br /> yum install gcc<br /> <br /> wget http://download.redis.io/releases/redis-3.2.1.tar.gz<br /> <br /> <br /> tar -zxvf redis-3.2.1.tar.gz<br /> <br /> 到redis3.2.1文件夹下执行 <br />  make<br /> <br /> make MALLOC=libc<br /> <br /> =====以上为源码安装方式=====<br /> <br /> 后台启动服务 <br /> src/redis-server &<br /> 指定配置文件启动<br /> src/redis-server redis6379.conf<br /> src/redis-server redis6380.conf<br /> src/redis-server redis6381.conf<br /> src/redis-server redis6382.conf<br /> src/redis-server redis6383.conf<br /> src/redis-server redis6384.conf<br /> src/redis-server redis6385.conf<br /> src/redis-server redis6386.conf<br /> <br /> src/redis-server redis.conf<br /> <br /> 客户端进入<br /> src/redis-cli -h 192.168.1.141 -p 6381<br /> <br /> src/redis-cli -c -h 192.168.1.143 -p 6383<br /> 关闭 <br /> shutdown<br /> <br /> 查看进程<br /> ps -ef| grep redis<br /> <br /> redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005<br /> src/redis-trib.rb create --replicas 1  192.168.1.141:6379 192.168.1.142:6381 192.168.1.143:6383 192.168.1.141:6380 192.168.1.142:6382 192.168.1.143:6384 192.168.1.144:6385 192.168.1.144:6386 192.168.1.145:6387 192.168.1.145:6388 192.168.1.146:6389 192.168.1.146:6390<br /> <br /> <br /> 192.168.1.142:6380 192.168.1.143:6380 192.168.1.144:6385 192.168.1.144:6386 <br /> <br /> 安装ruby<br /> tar xzvf ruby-2.2.3.tar.gz -C /home<br /> <br /> cd ruby-2.3.0<br /> <br /> ./configure<br /> <br /> 关联ruby到redis<br /> gem install redis<br /> <br /> src/redis-trib.rb check 192.168.1.141:6379<br /> <br />  src/redis-trib.rb fix 192.168.1.143:6383<br /> <br /> flushall ——> 清空整个 Redis 服务器的数据(删除所有数据库的所有 key )<br /> <br /> flushdb ——> 清空当前数据库中的所有 key<br /> <br /> 组成集群的时候要打开6379和他的16379端口才行<br /> <br /> <br /> 检查节点状态<br /> src/redis-trib.rb check 192.168.1.141:6380<br /> <br /> 添加master节点  新节点  到  老节点<br /> src/redis-trib.rb add-node 192.168.1.145:6387 192.168.1.143:6384<br /> <br /> src/redis-trib.rb add-node 192.168.1.146:6389 192.168.1.142:6382<br /> <br /> src/redis-trib.rb add-node 192.168.1.141:6380 192.168.1.144:6386<br /> <br /> src/redis-trib.rb add-node 192.168.1.111:6391 192.168.1.145:6387<br /> <br /> <br /> 添加slave节点<br /> src/redis-trib.rb add-node 192.168.1.145:6387 192.168.1.145:6388<br /> <br /> 进入集群配置从节点 <br /> src/redis-cli -c -h 192.168.1.144 -p 6386<br /> <br /> src/redis-cli -c -h 192.168.1.145 -p 6388<br /> <br /> src/redis-cli -c -h 192.168.1.146 -p 6390<br /> <br /> src/redis-cli -c -h 192.168.1.111 -p 6392<br /> <br /> cluster replicate 4f5744474ad515f0aa6ca3ed5f3c9a666ded40e1<br /> <br /> 从新分片数据<br /> <br /> src/redis-trib.rb reshard 192.168.1.143:6385<br /> <br /> src/redis-trib.rb reshard 192.168.1.142:6381<br /> <br /> src/redis-trib.rb reshard 192.168.1.111:6391<br /> <br /> 填写主节点id  ,之后选择从所有节点上进行平均分配<br /> <br /> 16384总数量<br /> <br /> 删除从节点  <br /> src/redis-trib.rb del-node 192.168.1.141:6380 383fff8053e27d5a194c8c2ee16dd38b126c0b10<br /> <br /> 删除主节点<br /> src/redis-trib.rb reshard 192.168.1.142:6381<br /> src/redis-trib.rb del-node 192.168.1.142:6381 77f99b006027c44b9b8b59b93d785da3ca16e59a <br /> <br /> chmod +x -R redis-3.2.1<br /> 查看端口<br /> netstat -ntlp<br /> 拷贝文件<br /> cp -r redis-3.2.1 redis-3.2.1-80<br /> <br /> <br /> # redis-trib.rb add-node 192.168.3.61:6379 192.168.3.88:6379<br /> <br /> # redis-trib.rb add-node 192.168.3.61:7379 192.168.3.88:6379<br /> <br /> <br /> cluster forget 383fff8053e27d5a194c8c2ee16dd38b126c0b10<br /> <br /> cluster saveconfig<br /> <br /> <br /> <br /> <br /> CLUSTER FAILOVER 切换主从<br /> <br /> <br /> <br />         CLUSTER INFO 打印集群的信息<br />         CLUSTER NODES 列出集群当前已知的所有节点(node),以及这些节点的相关信息。<br />         //节点<br />         CLUSTER MEET <ip> <port> 将 ip 和 port 所指定的节点添加到集群当中,让它成为集群的一份子。<br />         CLUSTER FORGET <node_id> 从集群中移除 node_id 指定的节点。<br />         CLUSTER REPLICATE <node_id> 将当前节点设置为 node_id 指定的节点的从节点。<br />         CLUSTER SAVECONFIG 将节点的配置文件保存到硬盘里面。<br />         CLUSTER ADDSLOTS <slot> [slot ...] 将一个或多个槽(slot)指派(assign)给当前节点。<br />         CLUSTER DELSLOTS <slot> [slot ...] 移除一个或多个槽对当前节点的指派。<br />         CLUSTER FLUSHSLOTS 移除指派给当前节点的所有槽,让当前节点变成一个没有指派任何槽的节点。<br />         CLUSTER SETSLOT <slot> NODE <node_id> 将槽 slot 指派给 node_id 指定的节点。<br />         CLUSTER SETSLOT <slot> MIGRATING <node_id> 将本节点的槽 slot 迁移到 node_id 指定的节点中。<br />         CLUSTER SETSLOT <slot> IMPORTING <node_id> 从 node_id 指定的节点中导入槽 slot 到本节点。<br />         CLUSTER SETSLOT <slot> STABLE 取消对槽 slot 的导入(import)或者迁移(migrate)。<br />         //键<br />         CLUSTER KEYSLOT <key> 计算键 key 应该被放置在哪个槽上。<br />         CLUSTER COUNTKEYSINSLOT <slot> 返回槽 slot 目前包含的键值对数量。<br />         CLUSTER GETKEYSINSLOT <slot> <count> 返回 count 个 slot 槽中的键。<br />         //新增<br />         CLUSTER SLAVES node-id 返回一个master节点的slaves 列表<br /> <br /> <br />