设为首页 收藏本站
查看: 425|回复: 0

[经验分享] Redis(5)Upgrade and HA Solution

[复制链接]

尚未签到

发表于 2016-12-18 09:03:55 | 显示全部楼层 |阅读模式
  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.iyunv.com/blog/1553507

Hashes
http://sillycat.iyunv.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.iyunv.com/blog/1553507
LPUSH, LLEN, LRANGE, LPOP, LREM

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

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

Hash 
http://sillycat.iyunv.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.iyunv.com/blog/1549504
http://sillycat.iyunv.com/blog/1553507
http://sillycat.iyunv.com/blog/1553508
http://sillycat.iyunv.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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-315801-1-1.html 上篇帖子: redis安装以及主从的简单配置测试 下篇帖子: 五.redis pipeline
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表