ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Redisv2.2.122011.8.18 ???Knight76 at gmail.comKnight76.tistory.com???
?? ?? ?????, ?? ??.?TCP
??? ?? ?? ???Mysql??Memcached??* ?? Redis? ??? ???- ??? ?? ??? ??? ??? ??? ? ??Memcached? ?? : (1 MB??? ??? ??, ??? ??? ??, Replication ??)
Mysql? ?? : (??,??? ??)Redis ?Vmware (2010.3.15 ???)?? ?? ??Remote Dictionary Server???Key-value store, Cache ???? ?: Github, blizzard, digg, stackoverflow?? ?? : 2.2.12 (stable)2011/08/17http://redis.io/
??? ?/????PersistenceSpeed (??? ??? 2?? ?? 1.28?? ??)Data StructureAtomic Operation (tx)Sharding / Replication ? ??Pub/sub / notification (message queue ?? comet)  - real timeString(1G), Hash, List, Set, Sorted Set(score??), intersection, union, difference In-memory??? TTL, ExpireNode.js? ???? ?????? ??? ??????. operation cost : O(1)Multiple Instance? ???? item? ??(select)? ??(move) ? ??(locking??)?? / ??Ram mode??? ??? ???, VM mode ????? ??? ??? ? ??? ?? ??? In-memory? ????? ? ???? ???? ?? ? ??(VM ??? ??? ?? ??? ??? ??) -> 2.4?? VM ?? deprecatedPersistence ? snapshotting ???I/O ??? ??????? ??Sharding? ??????? ? ??? ??? ??Replication? blocking? (2.4?? non-blocking??? ????)
? Redis? ??????Vmware? CloudFoundryStroage???? ?? (mysql, mongoDB? ?? ??). ??? memcached? ??? (?? ??? ?? ??? ? ??)Nonblocking IO, Single Threadedepoll,?kqueue?and?select ??Libevent (??? ?? ?? ??) ? ???? ?? ?? ??. => Dependent? ??. ????? ??Single-thread ServerANSIC ??????/ ???? porting? ??
Portable ??!2.4??? ????Replication ??? ??* Node.js + redis???????? ??? ?? ??* 2011? ??? Redis clustering? ??? ??    (???? ?? ???? ??? ????? ??? ? ??? ???? ??? ?? ??? ?..)
2.4 Release ???http://antirez.com/post/everything-about-redis-24Redis Main ??? ???Small sorted sets now use significantly less memory.RDB Persistence is much much faster for many common data sets.Many write commands now accept multiple arguments, so you can add multiple items into a Set or List with just a single command. This can improve the performance in a pretty impressive way.Our new allocator is jemalloc.Less memory is used by the saving child, as we reduced the amount of copy on write.INFO is more informative. However it is still the old 2.2-alike INFO, not the new one into unstable composed of sub sections.The new OBJECT command can be used to introspect Redis values.The new CLIENT command allows for connected clients introspection.Slaves are now able to connect to the master instance in a non-blocking fashion.Redis-cli was improved in a few ways.Redis-benchmark was improved as well.Make is now colorized ;)VM has been deprecated.In general Redis is now faster than ever.We have a much improved Redis test framework.
Demo (try.redis-db.com)2.0.2 version ??? ? ??? ???? ???? API? ??? ? ??
?? / ??http://redis.io/download// ??$ wget http://redis.googlecode.com/files/redis-2.2.12.tar.gz $ tar xzf redis-2.2.12.tar.gz $ cd redis-2.2.12 $ make// ?? ??$ cd src$ cd redis-server(daemon).. Log..// ????? ??$ cd????/src ; redis-cli redis> set foo bar OK redis> get foo "bar"
Example Code>?set foo 0"OK">?incr foo1>?incr foo2>?incr foo3>?get foo"3¡°>?decr foo2>?set hello world"OK">?get hello"world">?exists hellotrue>?type hello"string">?rename hello olleh"OK">?get olleh"world">?del olleh1>?get ollehnull>?set a 1"OK">?set b 2"OK">?set c 3"OK">?mget a b c["1","2","3"]>?set hello world"OK">?get hello"world"> ?set a 1¡®1¡¯>?expire a 100true>?get a"`1">?get a"`1¡°(100? ?)>?get anull>?sadd seta footrue>?sadd seta bartrue>?saddsetb footrue>?sinter seta setb["foo"]
Example Code>?hset user:1 name xtrue>?hset user:1 lastname ytrue>?hset user:2 name aatrue>?hget user:1wrong number of arguments (1 for 2)>?hget user:1 name"x">?hgetall user:1{"name":"x","lastname":"y"}>?hget user:2wrong number of arguments (1 for 2)>?hget user:2 name"aa">?lpush list a1>?lpush list b2>?lpush list c3>?lpush list d4>?lrange list 0 2["d","c","b"]>?lrange list 0 3["d","c","b","a"]>?lrange list 2 3["b","a"]>?sadd set 1true>?sadd set 2true>?sadd set 3true>?smembers set["3","1","2"]>?zaddss 1 aatrue>?zaddss 10 zztrue>?zaddss 9 yytrue>?zaddss 2 bbtrue>?zrangess 0 -1["aa","bb","yy","zz"]LISTSETSortedSETHash
Example Code>?multi"OK">?lpushclist a"QUEUED">?lpushclist b"QUEUED">?lpushclist c"QUEUED">?lrangeclist 0 -1"QUEUED">?exec[1,2,3,["c","b","a"]]>?multi"OK">?lpushdlist a"QUEUED">?lpushdlist b"QUEUED">?discard"OK"TXTXCheck and Set ? ??(watch)
Example Code[test /home/www/redis/redis-2.2.12/src]# ./redis-cliredis 127.0.0.1:6379> psubscribenews.article.*;Reading messages... (press Ctrl-C to quit)1) "psubscribe"2) "news.*;"3) (integer) 1redis 127.0.0.1:6379> multiOKredis 127.0.0.1:6379> set article.tech.1000 "Google"QUEUEDredis 127.0.0.1:6379> saddarticle.tech 1000QUEUEDredis 127.0.0.1:6379> publish news.article.tech 1000QUEUEDredis 127.0.0.1:6379> exec1) OK2) (integer) 13) (integer) 01) "pmessage"2) "news.article.*"3) "news.article.tech"4) "1000"
DEMORedis?? ??Command ??Java Client (jedis)??
Java client - Jedis?? ?? java ????? ?????https://github.com/xetorthio/jedis??? Map, Set ?? Collection? ???? ?? ??Sharding? ????? ?????, ???? ??? ??@Controller@RequestMapping("/restful")@ResponseStatus(value = HttpStatus.ACCEPTED)public class RestfulController {@RequestMapping(value = "/set/key/{key}/value/{value}", method = RequestMethod.GET)public String getString(@PathVariable String key, @PathVariable String value, ModelMap model) {System.out.println("key : " + key);System.out.println("value : " + value);Jedis jedis = new Jedis("1.1.1.1");jedis.set(key, value);String kValue = jedis.get(key);model.addAttribute("key", key);model.addAttribute("value", kValue);return "test";}} <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.0.0</version> <type>jar</type> <scope>compile</scope> </dependency>
??? ????? ?????? ??Master ¨C Slave Replication? ??/????? scale ??(?? ??? ???) ?? ??? Clustering ?? ?? ??https://github.com/antirez/redis/blob/master/design-documents/REDIS-CLUSTER?? ??? cache? ??? ??memcached? ??? ? ???? ??
??? ??Slave ??? ??? ??? ?? ????. Replication ??slave asks for SYNCmaster BGSAVE, slave waitsmaster BGSAVE finished, the initial bulk data (the .rdb file) is transfered to slavemaster accumulates all the new differences for the slavemaster finishes sending the whole initial rdb file to slavemaster start feeding the slave with the accumulated buffer, and with anything new arriving from clients, if they are writes.
??? ?? & ?????? ?? ????? File system?? ??Snapshotting  (???)?? ???? ??(fork)?? ??????? ??(new)RDB?? ???, ??? ? ???? ??(old) ?? ???? ?? (copy-on-write)?? ??? ??? ?? ????Append-only file (AOF)  - ??? ??2.0? 2.2? ??? ??.?? Snapshotting ??? Kill ??? ???? ??? ???? ?? ???? ?? ??(Log Rewriting)?? ?? ???? ??? ???? ??? AOF ??? ?? ?? ???? ??(fork)??, ?? ????? ?? AOF ??? ????. ?? ????? in-memory buffer? ?? ??? ??? ????. ?? ????? ?? ??? ???? ?? ????? in-memory buffer? ??? AOF ??? ????. ??? ??? ??.
??? ??AOF? ?????, ?? ????? ???? ?? Redis???/ ????? ?? (?? ??)???? ?? ??? ?????? ??? redis?? ????? ?? ??, ??? ??? ???? ??? client??? ?? ??? ???? ??? ??. (client ??)=> ??? ?? ??. ?? ?? ?? ??
??? ??????https://scoutapp.com/plugin_urls/271-redis-monitoring
??? ???consistent hashing ? ???? client? ???? distribute ?? Sharding? ??? ????? API? ???? ??? ?. API?? ??? ??2011.8.18??? 2.2Stable (?? 2.4)????? clustering ?? ? ? (?? ??? release ??? ??)
????? ????? ?? (?? ? ????? ?? ??)?? ?? row? ???? ??? ?? ??? ?? ??? ??? ???? (limit)?? 30?, ????(lpush, ltrim)??(zadd, zrank)Expire? ? ? ?? ??? ??
Arcus??? Redis??? ??? ?? (SDEC 2011.6)Radis 1.2 ?? ?? ?? ?? 2.2 ?? Sorted set?? no (offset, count) option=> ?? ????? offset, count ?? ??No capped collection=> ????? ???, FIFO??? ?? ?? ???? ???? capped collection??? ?. ?? Redis?? ??. ?? ??? ??.Not enough cache statisticsCannot control memory use=> info???? ???? ???? ??? ??? ?? ??
??? Referencehttp://redis.io/   , http://redis.io/topics/faqhttp://simonwillison.net/static/2010/redis-tutorial/http://www.slideshare.net/tag/redis/http://blog.mjrusso.com/2010/10/17/redis-from-the-ground-up.htmlhttp://www.slideshare.net/Cyworld/004-ctohttp://pauladamsmith.com/articles/redis-under-the-hood.htmlhttp://hi./roger_long/blog/item/611b1d017f57f89de950cd87.htmlhttp://redis.io/presentation/Redis_Cluster.pdfhttp://www.slideshare.net/karmi/redis-the-ak47-of-postrelational-databaseshttp://pauladamsmith.com/blog/2011/03/redis_get_set.html
Cache ??? ?? ?????value(field)? ???? ? ??? ???? ??. (??? ????)DB ???????? ???? ???? ?????? ?? ??? ?? ????????Replication? ? ??. ?? admin ??Java client? ???? Sharding? ? ? ? ??? admin ??Cache ??Web AppServerRedisJava Client(legacy ??)(Clustering)RedisJava Client+ Cron+ Spring Batch (admin)Mysql(??)MessageQueueRedisDB

More Related Content

Redis

  • 1. Redisv2.2.122011.8.18 ???Knight76 at gmail.comKnight76.tistory.com???
  • 2. ?? ?? ?????, ?? ??.?TCP
  • 3. ??? ?? ?? ???Mysql??Memcached??* ?? Redis? ??? ???- ??? ?? ??? ??? ??? ??? ? ??Memcached? ?? : (1 MB??? ??? ??, ??? ??? ??, Replication ??)
  • 4. Mysql? ?? : (??,??? ??)Redis ?Vmware (2010.3.15 ???)?? ?? ??Remote Dictionary Server???Key-value store, Cache ???? ?: Github, blizzard, digg, stackoverflow?? ?? : 2.2.12 (stable)2011/08/17http://redis.io/
  • 5. ??? ?/????PersistenceSpeed (??? ??? 2?? ?? 1.28?? ??)Data StructureAtomic Operation (tx)Sharding / Replication ? ??Pub/sub / notification (message queue ?? comet) - real timeString(1G), Hash, List, Set, Sorted Set(score??), intersection, union, difference In-memory??? TTL, ExpireNode.js? ???? ?????? ??? ??????. operation cost : O(1)Multiple Instance? ???? item? ??(select)? ??(move) ? ??(locking??)?? / ??Ram mode??? ??? ???, VM mode ????? ??? ??? ? ??? ?? ??? In-memory? ????? ? ???? ???? ?? ? ??(VM ??? ??? ?? ??? ??? ??) -> 2.4?? VM ?? deprecatedPersistence ? snapshotting ???I/O ??? ??????? ??Sharding? ??????? ? ??? ??? ??Replication? blocking? (2.4?? non-blocking??? ????)
  • 6. ? Redis? ??????Vmware? CloudFoundryStroage???? ?? (mysql, mongoDB? ?? ??). ??? memcached? ??? (?? ??? ?? ??? ? ??)Nonblocking IO, Single Threadedepoll,?kqueue?and?select ??Libevent (??? ?? ?? ??) ? ???? ?? ?? ??. => Dependent? ??. ????? ??Single-thread ServerANSIC ??????/ ???? porting? ??
  • 7. Portable ??!2.4??? ????Replication ??? ??* Node.js + redis???????? ??? ?? ??* 2011? ??? Redis clustering? ??? ?? (???? ?? ???? ??? ????? ??? ? ??? ???? ??? ?? ??? ?..)
  • 8. 2.4 Release ???http://antirez.com/post/everything-about-redis-24Redis Main ??? ???Small sorted sets now use significantly less memory.RDB Persistence is much much faster for many common data sets.Many write commands now accept multiple arguments, so you can add multiple items into a Set or List with just a single command. This can improve the performance in a pretty impressive way.Our new allocator is jemalloc.Less memory is used by the saving child, as we reduced the amount of copy on write.INFO is more informative. However it is still the old 2.2-alike INFO, not the new one into unstable composed of sub sections.The new OBJECT command can be used to introspect Redis values.The new CLIENT command allows for connected clients introspection.Slaves are now able to connect to the master instance in a non-blocking fashion.Redis-cli was improved in a few ways.Redis-benchmark was improved as well.Make is now colorized ;)VM has been deprecated.In general Redis is now faster than ever.We have a much improved Redis test framework.
  • 9. Demo (try.redis-db.com)2.0.2 version ??? ? ??? ???? ???? API? ??? ? ??
  • 10. ?? / ??http://redis.io/download// ??$ wget http://redis.googlecode.com/files/redis-2.2.12.tar.gz $ tar xzf redis-2.2.12.tar.gz $ cd redis-2.2.12 $ make// ?? ??$ cd src$ cd redis-server(daemon).. Log..// ????? ??$ cd????/src ; redis-cli redis> set foo bar OK redis> get foo "bar"
  • 11. Example Code>?set foo 0"OK">?incr foo1>?incr foo2>?incr foo3>?get foo"3¡°>?decr foo2>?set hello world"OK">?get hello"world">?exists hellotrue>?type hello"string">?rename hello olleh"OK">?get olleh"world">?del olleh1>?get ollehnull>?set a 1"OK">?set b 2"OK">?set c 3"OK">?mget a b c["1","2","3"]>?set hello world"OK">?get hello"world"> ?set a 1¡®1¡¯>?expire a 100true>?get a"`1">?get a"`1¡°(100? ?)>?get anull>?sadd seta footrue>?sadd seta bartrue>?saddsetb footrue>?sinter seta setb["foo"]
  • 12. Example Code>?hset user:1 name xtrue>?hset user:1 lastname ytrue>?hset user:2 name aatrue>?hget user:1wrong number of arguments (1 for 2)>?hget user:1 name"x">?hgetall user:1{"name":"x","lastname":"y"}>?hget user:2wrong number of arguments (1 for 2)>?hget user:2 name"aa">?lpush list a1>?lpush list b2>?lpush list c3>?lpush list d4>?lrange list 0 2["d","c","b"]>?lrange list 0 3["d","c","b","a"]>?lrange list 2 3["b","a"]>?sadd set 1true>?sadd set 2true>?sadd set 3true>?smembers set["3","1","2"]>?zaddss 1 aatrue>?zaddss 10 zztrue>?zaddss 9 yytrue>?zaddss 2 bbtrue>?zrangess 0 -1["aa","bb","yy","zz"]LISTSETSortedSETHash
  • 13. Example Code>?multi"OK">?lpushclist a"QUEUED">?lpushclist b"QUEUED">?lpushclist c"QUEUED">?lrangeclist 0 -1"QUEUED">?exec[1,2,3,["c","b","a"]]>?multi"OK">?lpushdlist a"QUEUED">?lpushdlist b"QUEUED">?discard"OK"TXTXCheck and Set ? ??(watch)
  • 14. Example Code[test /home/www/redis/redis-2.2.12/src]# ./redis-cliredis 127.0.0.1:6379> psubscribenews.article.*;Reading messages... (press Ctrl-C to quit)1) "psubscribe"2) "news.*;"3) (integer) 1redis 127.0.0.1:6379> multiOKredis 127.0.0.1:6379> set article.tech.1000 "Google"QUEUEDredis 127.0.0.1:6379> saddarticle.tech 1000QUEUEDredis 127.0.0.1:6379> publish news.article.tech 1000QUEUEDredis 127.0.0.1:6379> exec1) OK2) (integer) 13) (integer) 01) "pmessage"2) "news.article.*"3) "news.article.tech"4) "1000"
  • 15. DEMORedis?? ??Command ??Java Client (jedis)??
  • 16. Java client - Jedis?? ?? java ????? ?????https://github.com/xetorthio/jedis??? Map, Set ?? Collection? ???? ?? ??Sharding? ????? ?????, ???? ??? ??@Controller@RequestMapping("/restful")@ResponseStatus(value = HttpStatus.ACCEPTED)public class RestfulController {@RequestMapping(value = "/set/key/{key}/value/{value}", method = RequestMethod.GET)public String getString(@PathVariable String key, @PathVariable String value, ModelMap model) {System.out.println("key : " + key);System.out.println("value : " + value);Jedis jedis = new Jedis("1.1.1.1");jedis.set(key, value);String kValue = jedis.get(key);model.addAttribute("key", key);model.addAttribute("value", kValue);return "test";}} <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.0.0</version> <type>jar</type> <scope>compile</scope> </dependency>
  • 17. ??? ????? ?????? ??Master ¨C Slave Replication? ??/????? scale ??(?? ??? ???) ?? ??? Clustering ?? ?? ??https://github.com/antirez/redis/blob/master/design-documents/REDIS-CLUSTER?? ??? cache? ??? ??memcached? ??? ? ???? ??
  • 18. ??? ??Slave ??? ??? ??? ?? ????. Replication ??slave asks for SYNCmaster BGSAVE, slave waitsmaster BGSAVE finished, the initial bulk data (the .rdb file) is transfered to slavemaster accumulates all the new differences for the slavemaster finishes sending the whole initial rdb file to slavemaster start feeding the slave with the accumulated buffer, and with anything new arriving from clients, if they are writes.
  • 19. ??? ?? & ?????? ?? ????? File system?? ??Snapshotting (???)?? ???? ??(fork)?? ??????? ??(new)RDB?? ???, ??? ? ???? ??(old) ?? ???? ?? (copy-on-write)?? ??? ??? ?? ????Append-only file (AOF) - ??? ??2.0? 2.2? ??? ??.?? Snapshotting ??? Kill ??? ???? ??? ???? ?? ???? ?? ??(Log Rewriting)?? ?? ???? ??? ???? ??? AOF ??? ?? ?? ???? ??(fork)??, ?? ????? ?? AOF ??? ????. ?? ????? in-memory buffer? ?? ??? ??? ????. ?? ????? ?? ??? ???? ?? ????? in-memory buffer? ??? AOF ??? ????. ??? ??? ??.
  • 20. ??? ??AOF? ?????, ?? ????? ???? ?? Redis???/ ????? ?? (?? ??)???? ?? ??? ?????? ??? redis?? ????? ?? ??, ??? ??? ???? ??? client??? ?? ??? ???? ??? ??. (client ??)=> ??? ?? ??. ?? ?? ?? ??
  • 22. ??? ???consistent hashing ? ???? client? ???? distribute ?? Sharding? ??? ????? API? ???? ??? ?. API?? ??? ??2011.8.18??? 2.2Stable (?? 2.4)????? clustering ?? ? ? (?? ??? release ??? ??)
  • 23. ????? ????? ?? (?? ? ????? ?? ??)?? ?? row? ???? ??? ?? ??? ?? ??? ??? ???? (limit)?? 30?, ????(lpush, ltrim)??(zadd, zrank)Expire? ? ? ?? ??? ??
  • 24. Arcus??? Redis??? ??? ?? (SDEC 2011.6)Radis 1.2 ?? ?? ?? ?? 2.2 ?? Sorted set?? no (offset, count) option=> ?? ????? offset, count ?? ??No capped collection=> ????? ???, FIFO??? ?? ?? ???? ???? capped collection??? ?. ?? Redis?? ??. ?? ??? ??.Not enough cache statisticsCannot control memory use=> info???? ???? ???? ??? ??? ?? ??
  • 25. ??? Referencehttp://redis.io/ , http://redis.io/topics/faqhttp://simonwillison.net/static/2010/redis-tutorial/http://www.slideshare.net/tag/redis/http://blog.mjrusso.com/2010/10/17/redis-from-the-ground-up.htmlhttp://www.slideshare.net/Cyworld/004-ctohttp://pauladamsmith.com/articles/redis-under-the-hood.htmlhttp://hi./roger_long/blog/item/611b1d017f57f89de950cd87.htmlhttp://redis.io/presentation/Redis_Cluster.pdfhttp://www.slideshare.net/karmi/redis-the-ak47-of-postrelational-databaseshttp://pauladamsmith.com/blog/2011/03/redis_get_set.html
  • 26. Cache ??? ?? ?????value(field)? ???? ? ??? ???? ??. (??? ????)DB ???????? ???? ???? ?????? ?? ??? ?? ????????Replication? ? ??. ?? admin ??Java client? ???? Sharding? ? ? ? ??? admin ??Cache ??Web AppServerRedisJava Client(legacy ??)(Clustering)RedisJava Client+ Cron+ Spring Batch (admin)Mysql(??)MessageQueueRedisDB