`
sillycat
  • 浏览: 2487636 次
  • 性别: 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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics