`
sillycat
  • 浏览: 2542726 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Redis(5)Upgrade and HA Solution

 
阅读更多

Redis(5)Upgrade and HA Solution

1. Install it on my MAC
Download the software from here http://redis.googlecode.com/files/redis-2.6.14.tar.gz
>tar zxvf redis-2.6.14.tar.gz
>cd redis-2.6.14
>make
>mkdir /Users/carl/tool/redis-2.6.14
>cd src
>cp redis-server /Users/carl/tool/redis-2.6.14/
>cp redis-benchmark /Users/carl/tool/redis-2.6.14/
>cp redis-cli /Users/carl/tool/redis-2.6.14/
>cd ..
>cp redis.conf /Users/carl/tool/redis-2.6.14/

>sudo ln -s /Users/carl/tool/redis-2.6.14 /opt/redis-2.6.14
>sudo ln -s /opt/redis-2.6.14 /opt/redis

And we can use the same way to upgrade it to 2.6.16.

Start the redid server like this. 
>./redis-server redis.conf
>./redis-cli
>info
It will give out a lot of information to prove that our installation is right.

2. Understanding of Redis
Change the database as we like
redis 127.0.0.1:6379[1]> select 1
OK
redis 127.0.0.1:6379[1]> select 0
OK

Strings
set users:leto "{…}"
strlen users:leto

incr stats:page:about
incrby ratings:video:12333 5

http://sillycat.iteye.com/blog/1553507

Hashes
http://sillycat.iteye.com/blog/1553508

redis 127.0.0.1:6379> hmset users:goku race saiyan age 737
OK
redis 127.0.0.1:6379> hmget users:goku race powerlevel
1) "saiyan"
2) (nil)
redis 127.0.0.1:6379> hgetall users:goku
1) "race"
2) "saiyan"
3) "age"
4) "737"
redis 127.0.0.1:6379> hkeys users:goku
1) "race"
2) "age"
redis 127.0.0.1:6379> hmget users:goku race age
1) "saiyan"
2) "737"

String let you store a user1 in a single serialized value, json string or some other string.
Hash make you can store more fields there, more accurate.

Lists
http://sillycat.iteye.com/blog/1553507
LPUSH, LLEN, LRANGE, LPOP, LREM

Set
http://sillycat.iteye.com/blog/1553507
sadd, smembers, srem, sinter, sunion, sdiff

Sorted Set
http://sillycat.iteye.com/blog/1553508
zadd, zcard, zrange, zscore, zrangebyscore

Hash 
http://sillycat.iteye.com/blog/1553508

Publish/Subscribe
>subscribe crave
>publish ccav news1


>psubscribe cc*
>publish ccav news2
>publish cctv news3

Data Expiration
>set name "sillycat"
>ttl name
>exists name
>expire name 5

Check Suffix Command
>set name "karl"
>setnx name "bcd"
>get name
"Karl"

Java Mapping Spring Example
org.springframework.data.redis.connection.jedis.JedisConnectionFactory

3. Use Cases
Cache, Messaging, Counting

4. HA Solutions
Replication
http://redis.io/topics/replication

Persistence
http://redis.io/topics/persistence

HA
http://redis.io/topics/sentinel

Here is the Codes Repo.
https://github.com/antirez/redis


Build my own latest Redis
>git clone https://github.com/antirez/redis.git
>cd redis
>make
>make test
Sometimes, it has error and fail test cases, try more times.

>mkdir /Users/carl/tool/redis-latest
>cd src
>cp redis-server /Users/carl/tool/redis-latest/
>cp redis-benchmark /Users/carl/tool/redis-latest/
>cp redis-cli /Users/carl/tool/redis-latest/
>cd ..
>cp redis.conf /Users/carl/tool/redis-latest/

>sudo ln -s /Users/carl/tool/redis-latest/ /opt/redis-latest
>sudo ln -s /opt/redis-latest /opt/redis

>./redis-server redis.conf
>./redis-cli

4.1 Replication
Slave Redis servers to be exact copies of master servers.

Configration
slaveof 192.168.10.115 6379

4.2 Persistence
…snip…

4.3 Sentinel 
Get the latest unstable branch and compile that, from the same src directory
>cp redis-sentinel /Users/carl/tool/redis-latest/
>cd ..
>cp sentinel.conf /Users/carl/tool/redis-latest/

Command to start
>./redis-sentinel sentinel.conf

Or alternatively
>./redis-server sentinel.conf --sentinel

>./redis-cli -p 26379 sentinel masters

SDOWN and ODOWN
SDOWN - subjectively down, sentinel think one Redis instance not working.
ODOWN - objectively down, a lot of sentinel instance think Redis master instance down.

How to Set up Master-Slave

Configuration
>vi redis-0/redis.conf
port 6379 

>vi redis-1/redis.conf
port 6479
slaveof 127.0.0.1 6379

>vi sentinel-0/sentinel.conf
port 26379

>vi sentinel-1/sentinel.conf 
port 26479

Start Commands
>./redis-server redis-0/redis.conf
>./redis-server redis-1/redis.conf

>./redis-sentinel sentinel-0/sentinel.conf
>./redis-sentinel sentinel-1/sentinel.conf  

Then I have 1 master of Redis instance on 6379, 1 slave of Redis instance on 6479.

1 Sentinel on 26379, 1 sentinel on 26479.

Once the master is down on 6379, the slave will take the place to be master.

Information
>./redis-cli -h 127.0.0.1 -p 26379 info Sentinel 
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
master0:name=mymaster,status=ok,address=127.0.0.1:6479,slaves=1,sentinels=2

>./redis-cli -h 127.0.0.1 -p 6479
redis>info

Useful Book
http://www.redisbook.com/en/latest/
http://www.wzxue.com/redis%E6%A0%B8%E5%BF%83%E8%A7%A3%E8%AF%BB-%E9%9B%86%E7%BE%A4%E7%AE%A1%E7%90%86%E5%B7%A5%E5%85%B7redis-sentinel/


5. Scala Client
https://github.com/debasishg/scala-redis
https://github.com/top10/scala-redis-client
https://github.com/alphazero/jredis


References:
Redis 1~4
http://sillycat.iteye.com/blog/1549504
http://sillycat.iteye.com/blog/1553507
http://sillycat.iteye.com/blog/1553508
http://sillycat.iteye.com/blog/1553509
spring side
https://github.com/springside/springside4/wiki/Redis
scala client
http://redis.io/clients
https://github.com/debasishg/scala-redis
https://github.com/top10/scala-redis-client

Installation
https://github.com/JasonLai256/the-little-redis-book/blob/master/cn/redis.md

Tips
http://stackoverflow.com/questions/10137857/is-redis-just-a-cache
http://kenny7.com/2012/09/redis-usage-scenario.html
http://blog.nosqlfan.com/html/2235.html
http://blog.163.com/a12333a_li/blog/static/87594285201304103257837/
http://blog.mkfree.com/posts/5257683d479e1dd72e7c1b4e

Useful API Documents
http://redis.io/commands

分享到:
评论

相关推荐

    redis 主从切换 实现HA 的方法和工具

    5. 阅读资料:`redis_HA.pdf`可能包含了更详细的步骤和配置示例,建议深入研究以获取更全面的理解。 总结来说,通过Redis的主从复制和Keepalived的配合,我们可以构建出一个高可用的Redis集群,即使主节点出现故障...

    Redis服务端实现 & HA1

    Redis作为一个高性能的键值存储系统,其服务端的实现涉及多个关键环节,包括服务器启动流程、命令执行流程、事件循环机制以及高可用性(HA)策略。接下来,我们将深入探讨这些核心内容。 **1. Redis服务端启动流程*...

    redis5 windows ZIP免安装版本

    redis5 windows ZIP免安装版本。国外下载太慢,放到这里来。最新版可以在Windows上安装的exe版本的Redis。First release of Redis 5.x for Windows, updated to be in sync with antirez/5.0.9. Redis 5.0.9

    redis5离线安装文件包,包含redis-5.0.14.tar.gz和redis-4.6.0.gem

    # 下载 redis-3.2.1.gem然后本地安装 sudo gem install -l ./redis-3.2.1.gem port 6379 daemonize yes #bind自己的ip bind 192.168.129.101 protected-mode no #启用集群 cluster-enabled yes cluster-config-file ...

    【作者面对面问答】包邮送《Redis 5设计与源码分析》5本

    墨墨导读:本文节选自《Redis 5设计与源码分析》,主要为读者分析Redis高性能内幕,重点从源码层次讲解了Redis事件模型,网络IO事件重在使用IO复用模型,时间事件重在限制最大执行CPU时间。最后简单介绍了Redis的...

    Redis Essentials

    Scale Redis to multiple servers with Twemproxy, Redis Sentinel, and Redis Cluster A fast-paced guide, full of real-world examples to help you get the best out of the features offered by Redis Who This...

    redis5 windows msi 安装版本

    redis5 windows msi 安装版本。国外下载太慢,放到这里来。最新版可以在Windows上安装的exe版本的Redis。First release of Redis 5.x for Windows, updated to be in sync with antirez/5.0.9. Redis 5.0.9

    redis5.rpm rpm包

    redis5 rpm包,直接yum 安装使用

    Redis-Essentials.pdf

    type, and then the solution is improved and optimized by using the Hash data type. Uniqueness support is added to the String and Hash implementations by using the Sorted Set and HyperLogLog data types...

    redis-5.0.5.zip windows版本

    Redis是一款开源、高性能的键值对存储系统,常被用作数据库、缓存和消息中间件。在Windows操作系统上,由于官方默认不提供预编译的Windows版本,因此用户经常需要自行编译或者寻找第三方编译好的二进制包。本压缩包...

    windows版redis

    **Redis在Windows平台上的安装与使用** Redis,全名Remote Dictionary Server,是一种开源的、基于键值对的数据存储系统,广泛应用于缓存、消息队列、数据库等多个场景。虽然Redis官方主要支持Linux操作系统,但...

    Window版Redis 5.0.14.1 64 bit

    Window版Redis:Redis 5.0.14.1 (ec77f72d/0) 64 bit 启动server cmd->redis-server.exe redis.windows.conf 启动client cmd->redis-cli.exe 启动client, 指定主机端口 cmd->redis-cli.exe -h localhost -p 6379

    redis5安装包加依赖

    Redis 是一个高性能的键值对存储系统,常用于数据库、缓存和消息中间件。它支持多种数据结构,如字符串、哈希、列表、集合、有序集合等,这些特性使得 Redis 在很多场景下非常实用。在本文中,我们将详细介绍如何在...

    Redis-5.0.5 Windows版本

    5. **客户端连接**:Redis提供了一个命令行接口(CLI)工具`redis-cli.exe`,你可以用它连接到本地运行的Redis服务器,进行数据的读写操作。此外,Redis还支持许多编程语言的客户端库,如Python的redis-py、Java的...

    windows版本redis5 附带快速启动脚本

    5. 监控与管理:Redis提供了`INFO`命令来查看服务器状态,同时可以通过`redis-cli`的`MONITOR`命令实时监控服务器活动。 在Windows环境中,使用Redis需要注意以下几点: - 文件权限:确保Redis可执行文件和数据...

    redis-5.0.3 redis-5.0.4 redis-5.0.5

    redis-5.0.3 redis-5.0.4 redis-5.0.5

    Linux 系统 安装redis redis-5.0.1.tar.gz 安装包

    5. **配置Redis**: Redis的配置文件是`redis.conf`,可以根据实际需求进行定制。默认情况下,Redis会将数据存储在当前目录的`db/`子目录下,端口设为6379,日志文件名为`redis.log`。你可以在`redis.conf`中修改...

Global site tag (gtag.js) - Google Analytics