Redis Intro Osc2010 Tokyo Spring

2,351 views

Published on

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,351
On SlideShare
0
From Embeds
0
Number of Embeds
164
Actions
Shares
0
Downloads
20
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Redis Intro Osc2010 Tokyo Spring

  1. 1. Redisをドキュメント指向DBとし て使う 2010/2/27(Sat) OSC 2010 Tokyo/Spring z.ohnami
  2. 2. 1.2.2 2/18 Released !!
  3. 3. Redisの特徴 インメモリーなKVS ゆえに、高速 それでいて、データは永続化 4種類のデータ型 型ごとに豊富なAPIを備える
  4. 4. コンパイルしましょう $ wget http://redis.googlecode.com/files/redis-1.2.2.tar.gz $ tar xvzf redis-1.2.2.tar.gz $ cd redis-1.2.2 $ make
  5. 5. 使ってみましょう Redisの起動  $ ./redis-server データ格納  $ ./redis-cli set name z.ohnami データを入手  $ ./redis-cli get name z.ohnami docフォルダにはHTMLドキュメントも充実!!
  6. 6. Document-Oriented Database For example here's a document: FirstName="Bob", Address="5 Oak St.", Hobby="sailing". Another document could be: FirstName="Jonathan", Address="15 Wanamassa Point Road", Children=("Michael, 10", "Jennifer,8", "Samantha,5", "Elena,2"). Notice that both documents have some similar information and some different - but unlike a relational database where each record would have the same set of fields and unused fields might be kept empty, there are no empty 'fields' in either document (record) in this case. This system allows information to be added any time without wasting storage space for "empty fields" as in relational databases. From Wikipedia Document-Oriented Database http://en.wikipedia.org/wiki/Document-oriented_database
  7. 7. Semi Structured Data ゆるーくデータを管理する
  8. 8. CouchDBの場合 { {  _id:xxx,  _id:yyy, "なまえ":"まこと", "なまえ":"ぽったー", "せいべつ":"おとこ", "せいべつ":"おとこ", "しょくぎょう":"SE", "しょくぎょう": "とくぎ":["小走り","歯ぎしり"], ["SE","魔法使い"] "そうび":"{ "まほう":["JScript","bash"], "あたま":"めがね", "そうび":"{ "からだ":"桃色ニット", "あたま":"めがね", "あし":"ぞうり", "からだ":"くさりかたびら", "PC":"ネットブック" "あし":"ホーキンス", "PC":"MacBook Air", }" "そのた":"" } }" }
  9. 9. Redisならどうやる!? ???
  10. 10. set profile:1:name z.ohnami key & value
  11. 11. set profile:1:name z.ohnami set profile:1:blood A set profile:1:age 30 set profile:2:name y.konami set profile:2:blood C++ set profile:2:height 140
  12. 12. 4種類のデータ型 四
  13. 13. String型 $ ./redis-cli set OSC "OSC 2010 Tokyo/Spring" $ ./redis-cli get OSC OSC 2010 Tokyo/Spring
  14. 14. 計算もできます $ ./redis-cli set cnt 0 $ ./redis-cli incr cnt (integer) 1 $ ./redis-cli incrby cnt 10 (integer) 11 $ ./redis-cli decrby cnt 10 (integer) 1 $ ./redis-cli decr cnt (integer) 0
  15. 15. List型 $ ./redis-cli rpush msg "CouchDB" $ ./redis-cli rpush msg "MongoDB" $ ./redis-cli rpush msg "Redis" $ ./redis-cli rpush msg "Lotus/Domino" $ ./redis-cli lrange msg 0 3 1. CouchDB 2. MongoDB 3. Redis 4. Lotus/Domino
  16. 16. Sets型 $ ./redis-cli sadd hobby:baseball z.ohnami $ ./redis-cli sadd hobby:swiming z.ohnami $ ./redis-cli sadd hobby:swiming y.ohnami $ ./redis-cli sadd hobby:swiming x.ohnami $ ./redis-cli sinter hobby:swiming 1. z.ohnami 2. y.ohnami 3. x.ohnami
  17. 17. Sorted sets型 $ ./redis-cli zadd relax 120 マッサージ $ ./redis-cli zadd relax -20 二日酔い $ ./redis-cli zadd relax 50 爪切り $ ./redis-cli zadd relax -50 深爪 $ ./redis-cli zadd relax 100 お風呂 $ ./redis-cli zrange relax 0 -1 1. 深爪 2. 二日酔い 3. 爪切り 4. 風呂 5. マッサージ
  18. 18. 使ってみての感想 ドキュメント指向DBとして使えそう アスタリスクでキーの検索可能 ./redis-cli keys profile:1:* 添付ファイルは格納できるか? 今回、未チェックです。。 はじめる際の敷居が低い インストールが楽でした APIも覚えやすいはず コードも少ないから学習にも

×