Introduction to Redis   Byeongweon Moon / Redduck
Ready to Redis

• Document-oriented Database

• Key-Value Data Store Program

• Key can contain strings, hashes, lists, sets and
  sorted sets

• Value can contain strings, lists, sets, sorted set

• Redis use RAM for data store
Key-Value Data Store

• Insert data with specific key

• Get data with key by O(1) compexity

• Value can contain structured strings like as JSON,
  XML
List Control

• SET : LINSERT, LPUSH, RPUSH, LSET

• GET : LPOP, LRANGE, RPOP

• DEL : LREM

• ETC : LTRIM, LLEN
Pushing IDs instead of the actual data

$ redis-cli incr next.news.id
(integer) 1
$ redis-cli set news:1:title "Redis is simple"
OK
$ redis-cli set news:1:url
"http://code.google.com/p/redis"
OK
$ redis-cli lpush submitted.news 1
OK
$ redis-cli lrange submitted.news 0 -1
1) “1”
Set Control

• SET : SADD,

• GET : SPOP, SRANDMEMBER, SMEMBERS

• DEL : SREM

• ETC : SINTER, SUNION, SCARD, SDIFF, SMOVE,
  SISMEMBER
Redis Sets

$ redis-cli sadd news:1000:tags 1
(integer) 1
$ redis-cli sadd news:1000:tags 2
(integer) 1
$ redis-cli sadd news:1000:tags 5
(integer) 1
$ redis-cli sadd tag:1:objects 1000
(integer) 1
$ redis-cli sadd tag:2:objects 1000
(integer) 1
$ redis-cli sadd tag:5:objects 1000
(integer) 1
$ redis-cli sinter tag:1:objects tag:2:objects tag:5:objects
1000
1) “1000”
Sorted Set Control

• SET : ZADD, ZINCRBY

• GET : ZRANGE, ZRANGEBYSCORE, ZSCORE,
  ZCARD, ZRANK, ZCOUNT

• DEL : ZREM, ZREMRANGEBYRANK,
  ZREMRANGEBYSCORE

• ETC : ZINTERSTORE, Z UNIONSTORE
Sorted sets

$ redis-cli zadd hackers 1940 "Alan Kay"
(integer) 1
$ redis-cli zadd hackers 1953 "Richard Stallman"
(integer) 1
$ redis-cli zadd hackers 1969 "Linus Torvalds"
(integer) 1
$ redis-cli zadd hackers 1912 "Alan Turing"
(integer) 1
$ redis-cli zrange hackers 0 -1
1. Alan Turing
2. Alan Kay
3. Richard Stallman
4. Linus Torvalds
Replication

• Master-Slave replication

• Master can have multiple slaves

• Slaves are able to accept other slaves
  connections

• Slaves can also be connected to other slaves in
  graph-like structure

• Redis replication is non-blocking on the master
  side. but blocking on the slave side.
How replication works

• To configure add below line to slave's
  configuration file slaveof IP PORT

• After configuration done. when upon connection
  slave sends a SYNC command

• Master start background data saving and collect
  all new commands received that will modify
  dataset

• When background saving complete, transfers the
  dataset to slave, then send saved commands
Publish / Subcribe

• Messaging pattern where senders of messages
  do not program the messages to be sent directly
  to specific receiver.

• SUBCRIBE [channel] command create channel or
  subscribe channel

• PUBLISH [channel] [message] command send
  message via

• Support pattern matching subscribe with
  PSUBSCRIBE
Pipelining

• Whatever network speed fast or slow, there's
  always latency.

• To avoid network latency. Redis support multi
  commands send with one request.

• Send commands with new line delemiter
        echo -en "PINGrnPINGrnPINGrn" | nc
  localhost 6379

• Result wiil received after all commands processed
Benchmarks
Who's using Redis?

• Twitter

• github

• stackoverflow

• blizzard

• digg

• .....
Thanks, Any Questions?

Redis

  • 1.
    Introduction to Redis Byeongweon Moon / Redduck
  • 2.
    Ready to Redis •Document-oriented Database • Key-Value Data Store Program • Key can contain strings, hashes, lists, sets and sorted sets • Value can contain strings, lists, sets, sorted set • Redis use RAM for data store
  • 3.
    Key-Value Data Store •Insert data with specific key • Get data with key by O(1) compexity • Value can contain structured strings like as JSON, XML
  • 4.
    List Control • SET: LINSERT, LPUSH, RPUSH, LSET • GET : LPOP, LRANGE, RPOP • DEL : LREM • ETC : LTRIM, LLEN
  • 5.
    Pushing IDs insteadof the actual data $ redis-cli incr next.news.id (integer) 1 $ redis-cli set news:1:title "Redis is simple" OK $ redis-cli set news:1:url "http://code.google.com/p/redis" OK $ redis-cli lpush submitted.news 1 OK $ redis-cli lrange submitted.news 0 -1 1) “1”
  • 6.
    Set Control • SET: SADD, • GET : SPOP, SRANDMEMBER, SMEMBERS • DEL : SREM • ETC : SINTER, SUNION, SCARD, SDIFF, SMOVE, SISMEMBER
  • 7.
    Redis Sets $ redis-clisadd news:1000:tags 1 (integer) 1 $ redis-cli sadd news:1000:tags 2 (integer) 1 $ redis-cli sadd news:1000:tags 5 (integer) 1 $ redis-cli sadd tag:1:objects 1000 (integer) 1 $ redis-cli sadd tag:2:objects 1000 (integer) 1 $ redis-cli sadd tag:5:objects 1000 (integer) 1 $ redis-cli sinter tag:1:objects tag:2:objects tag:5:objects 1000 1) “1000”
  • 8.
    Sorted Set Control •SET : ZADD, ZINCRBY • GET : ZRANGE, ZRANGEBYSCORE, ZSCORE, ZCARD, ZRANK, ZCOUNT • DEL : ZREM, ZREMRANGEBYRANK, ZREMRANGEBYSCORE • ETC : ZINTERSTORE, Z UNIONSTORE
  • 9.
    Sorted sets $ redis-clizadd hackers 1940 "Alan Kay" (integer) 1 $ redis-cli zadd hackers 1953 "Richard Stallman" (integer) 1 $ redis-cli zadd hackers 1969 "Linus Torvalds" (integer) 1 $ redis-cli zadd hackers 1912 "Alan Turing" (integer) 1 $ redis-cli zrange hackers 0 -1 1. Alan Turing 2. Alan Kay 3. Richard Stallman 4. Linus Torvalds
  • 10.
    Replication • Master-Slave replication •Master can have multiple slaves • Slaves are able to accept other slaves connections • Slaves can also be connected to other slaves in graph-like structure • Redis replication is non-blocking on the master side. but blocking on the slave side.
  • 11.
    How replication works •To configure add below line to slave's configuration file slaveof IP PORT • After configuration done. when upon connection slave sends a SYNC command • Master start background data saving and collect all new commands received that will modify dataset • When background saving complete, transfers the dataset to slave, then send saved commands
  • 12.
    Publish / Subcribe •Messaging pattern where senders of messages do not program the messages to be sent directly to specific receiver. • SUBCRIBE [channel] command create channel or subscribe channel • PUBLISH [channel] [message] command send message via • Support pattern matching subscribe with PSUBSCRIBE
  • 13.
    Pipelining • Whatever networkspeed fast or slow, there's always latency. • To avoid network latency. Redis support multi commands send with one request. • Send commands with new line delemiter echo -en "PINGrnPINGrnPINGrn" | nc localhost 6379 • Result wiil received after all commands processed
  • 14.
  • 15.
    Who's using Redis? •Twitter • github • stackoverflow • blizzard • digg • .....
  • 16.

Editor's Notes

  • #5 리스트 형태로 이루어져 있으며 , index 를 통한 접근이 가능하고 , 중간에 데이터를 추가할 수 있다 .
  • #7 데이터를 중간에 추가하거나 인덱스를 이용한 접근이 불가능 . Set 간의 집합 연산을 이용할 수 있다 .
  • #9 데이터를 중간에 추가하거나 인덱스를 이용한 접근이 불가능 . Set 간의 집합 연산을 이용할 수 있다 .