2. About Me
Kris jeong(정경석)
Author a Book of REDIS
‘This is REDIS’ in korean
Software development
Over 14 years.
Web service dev.
Messaging server dev.
Recommendation dev.
Interested about NoSQL
http://www.aladin.co.kr/shop/wproduct.aspx?ISBN=8968480591
3. What is
REDIS is In-Memory Database
Variety data types
Support persistence
Key value based NoSQL
4. IMDB(In-Memory DB)
Disk based data store
In-Memory data store
Query Engine
Query Engine
Speed
Storage
Manager
Memory(Cache)
Disk
Memory
Durability
Disk is optional
Disk
5. Redis is cache server?
Not a cache server.
But, It can be.
Turn off Persistence.
7. Install and test
$ wget http://download.redis.io/redis-stable.tar.gz
$ tar xvf redis-stable.tar.gz
$ cd redis-stable
$ make
…
…
done.
$ make test
※ CentOS 6.4 64bit
10. Feature - expire
Duration cache
expire user:212:cart 259200
seconds
It will be expired 3 days later.
Specified time cache
expireat user:212:item:sward 1388534400
It will be expired 2014/01/01
Unix timestamp
11. Support data types
String
key
value
{
"product": {
"id": "2951",
"name": "testing 01",
"options": {
"color": "red"
},
"quantity": 4
}
user:1:cart_info
}
※ Up to 512MB
12. Support data types (cont.)
Hash
Key
field
value
name
min damage
13
max damage
20
durability
32/50
price
item:1:info
bastard sword
3500
add a new value
durability
31/50
13. Support data types (cont.)
Hash
Key
field
value
name
min damage
item:1:info
bastard sword
13
max damage
20
durability
31/50
32/50
price
3500
14. Support data types (cont.)
List
Key
user:1:messag
e
elements
hi~
how r you.
bye.
add a new value
15. Support data types (cont.)
List
Key
user:1:messag
e
elements
hi~
how r you.
bye.
16. Support data types (cont.)
Set
kris
mike
frank
user:1:friend
martin
tom
add a new value
chris
17. Support data types (cont.)
Set
kris
mike
user:1:friend
frank
martin
tom
chris
18. Support data types (cont.)
Sorted Set
score
Key
value
1
91
mike
200
frank
250
martin
251
user:ranking
kris
tom
add a new value
220
chris
19. Support data types (cont.)
Sorted Set
Key
score
value
1
91
user:ranking
kris
mike
200
frank
220
250
chris
martin
250
251
martin
tom
251
tom
20. Feature – RDB(Snapshot)
Redis instance
Redis data
Data dump
to disk
Dump file
(Redis.rdb)
When snapshot event raised
Check point of Redis snapshot
Redis data size vs Physical memory size ratio
vm.overcommit_memory setting
Disk I/O rate for swap
21. Feature – AOF(Append Only File)
Redis instance
Command
logging
Redis data
Data change command
Redis client
Check point of Redis aof
Disk space
Restart time is slower than RDB
appendonly.aof
22. Replication – Single slave
Redis cluster
Master Node
Slave Node
Replication
key1
test value
set key1 ‘test value’ key1
set key1 ‘test value’
Redis client
test value
25. Sharding – range
● Data range based data split
User Key 1 ~ 100
User Key 1~50
User Key 51~100
Shard 1
Shard 2
Master Node
Master Node
Slave Node
Slave Node
Slave Node
Slave Node
26. Sharding - vertical
● Schema based data split
User info
Content
Shard 1
Shard 2
Master Node
Master Node
Slave Node
Slave Node
Slave Node
Slave Node
27. Sharding - consistent hashing
● Key based data split
User Key 1 ~ 100
Key % Number of Shard(Key % 2)
Shard 1
Shard 2
Master Node
Master Node
Slave Node
Slave Node
Slave Node
Slave Node
28. Sharding – Redis client
Shard 1
Shard N
…
Sharding Calc
Read/Write
Read/Write
Redis client
Check point of Redis Sharding
Redis does not support server-side sharding
Most Redis client support hash based sharding
Re sharding issue
29. Useage
PV/UV Calculation 1Billion user
Daily logged in user count
Weekly logged in user count
List of Logged-in account at least once of week
Most popular News list - Real time
Top 10 of news by click count
News list by popular by comment count
Real time gamers ranking
Score based Top 10 ranker.
Recent user list