ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
°Â±ð²ú¥¨¥ó¥¸¥Ë¥¢¤Î¤¿¤á¤Î¤Ï¤¸¤á¤Æ¤Î°ù±ð»å¾±²õ°Â±ð²ú¥¨¥ó¥¸¥Ë¥¢¤Î¤¿¤á¤Î¤Ï¤¸¤á¤Æ¤Î°ù±ð»å¾±²õ
@nasa9084@nasa9084
$ whoami$ whoami
Masahiro Kitamura
@nasa9084
VirtualTech Japan Inc.
KEYWORDS: emacs python golang(new!) whiske?y
redisredis
What is "redis"?What is "redis"?
remote dictionary server
Key-Value Store (KVS)
Varied Data Structure
in-memory
having persistence
easy and fast
compatible w/Python, Ruby, ¡­
¡úweb engineers should learn redis!
Key-value Store (KVS)Key-value Store (KVS)
dict(Python)
hash(Perl, Ruby)
map(C++, Java, Go)
namespaces
Comparison with RDBMSsComparison with RDBMSs
Function RDBMS Redis
using simply ¡÷ ¡ò
high speed processing ¡÷ ¡ò
horizontal distribution ¡Á ¡ò
high availability ¡÷ ¡ò
persistency ¡ò ¡ð
complex query ¡ò ¡Á
transaction ¡ò ¡÷
consistency ¡ò ¡÷
Comparison with memcachedComparison with memcached
memcached redis
good at Cache Cache
data structure only string varied structure
persistency ¡Á ¡ð
Disk I/O NOT DO can be disable
speed high high
multi thread ¡ð ¡Á
memory ef?ciency ¡÷ ¡ð
Redis Data StructureRedis Data Structure
StringString
String
replace
get length
number
INCR / DECR
max: 512MB
binary safe
can insert pictures, etc
StringString
redis python
> SET hoge fugafuga
OK
> GET hoge
"fugafuga"
> SET point 10
OK
> GET point
"10"
> INCR point
(integer) 11
> GET point
"11"
from redis import Redis
redis = Redis()
redis.set('hoge', 'fugafuga')
print(redis.get('hoge'))
#=> b'fugafuga'
redis.set('point', 10)
print(redis.get('point'))
#=> b'10'
redis.incr('point')
print(redis.get('point'))
#=> b'11'
ListList
List of Strings
Implemented with Linked List
insert or access to head or tail:
access to mid:
max size: 232-1 elements
O(1)
O(N)
ListList
redis python
> LPUSH 1 2 3
(integer) 3
> LRANGE piyo 0 -1
"3"
"2"
"1"
> LPOP piyo
"3"
> LRANGE piyo 0 -1
"2"
"1"
from redis import Redis
redis = Redis()
redis.lpush('piyo', 1, 2, 3)
print(redis.lrange('piyo', 0, -1))
#=> [b'3', b'2', b'1']
print(redis.lpop('piyo'))
#=> b'3'
print(redis.lrange('piyo', 0, -1))
#=> [b'2', b'1']
SetSet
Set of Strings
un-ordered
no duplication
add, delete, access avarage:
max size: 232-1 elements
O(1)
SetSet
redis python
> SADD foo 1 3 5
(integer) 3
> SMEMBERS foo
"1"
"3"
"5"
> SADD foo 1
(integer) 0
> SMEMBERS foo
"1"
"3"
"5"
from redis import Redis
redis = Redis()
redis.sadd('foo', 1, 3, 5)
print(redis.smembers('foo'))
#=>{b'3', b'5', b'1'}
redis.sadd('foo', 1)
print(redis.smembers('foo'))
#=>{b'3', b'5', b'1'}
Sorted Set (ZSet)Sorted Set (ZSet)
Set of Strings
no duplication
each members are ordered with its Score
take Score:
add:
O(1)
O(log N)
Sorted Set (ZSet)Sorted Set (ZSet)
redis python
> ZADD bar 20 ham
(integer) 1
> ZADD bar 10 egg
(integer) 1
> ZADD bar 30 spam
(integer) 1
> ZRANGE bar 0 -1 WITHSCORES
1) "egg"
2) "10"
3) "ham"
4) "20"
5) "spam"
6) "30"
from redis import Redis
redis = Redis()
redis.zadd('bar', 'ham', 20)
redis.zadd('bar', 'egg', 10)
redis.zadd('bar', 'spam', 30)
print(
redis.zrange('bar', 0, -1, withscores=True)
)
#=>[(b'egg', 10.0), (b'ham', 20.0), (b'spam', 30.0)]
HashHash
String to String map
Java: HashMap<String, String>
Go: ~map[string]string
add, delete, access:
max size: 232-1 pairs
O(1)
HashHash
redis python
> HSET bar 0:00 5
(integer) 1
> HGETALL bar
1) "0:00"
2) "5"
> HMSET bar 1:00 5 2:00 6
(integer) 2
> HKEYS bar
1) "0:00"
2) "1:00"
3) "2:00"
> HGET bar 0:00
"5"
from redis import Redis
redis = Redis()
redis.hset('bar', '0:00', '5')
print(redis.hgetall('bar'))
#=>{b'0:00': b'5'}
add_dict = {
'1:00': '5',
'2:00': '6'
}
redis.hmset('bar', add_dict)
print(redis.hkeys('bar'))
#=>[b'0:00', b'1:00', b'2:00]
print(redis.hget('bar', '0:00'))
#=>b'5'
UsecasesUsecases
data having expirationdata having expiration
can set expiration to key
EXPIRE key seconds
`key` is expired after `seconds` seconds
EXPIREAT key timestamp
`key` is expired on `timestamp`
for example,for example,
Session ID
One Time Token
Sample CodeSample Code
from redis import Redis
from uuid import uuid4
class User:
def generate_apikey(self):
redis = Redis(host='localhost', port=6389)
if redis.exists(self.token):
return self.token
new_apikey = 'hbt-' + str(uuid4())
ttl = 10 * 60 * 60 # 10 minutes
redis.setex(new_apikey, self.name, ttl)
self.apikey = new_apikey
return self.apikey
https://github.com/web-apps-tech/hubotmaker.git
https://hubot.web-apps.tech/
Real Time RankingReal Time Ranking
sorted set
zadd key score member
key¤Ëscoreµã¤ò³Ö¤Ã¤¿member¤ò×·¼Ó¤¹¤ë add
a `member` that has `score` to `key`
zincrby key increment member
increment score of `member` of `key`
zrange key start stop
get `key`s members from `start` to `stop`
Sample CodeSample Code
from redis import Redis
redis = Redis()
while True:
print('input member:score> ', end='')
ipt = input()
if ipt == 'show': # command 'show'
ranking = redis.zrange('ranking', 0, 5, withscores=True)[::-1]
for i, m in enumerate(ranking):
values = {
'rank': i+1,
'member': m[0].decode(),
'point': m[1]
}
print('{rank}: {member} ({point}pt)'.format(**values))
continue
member, score = args.split(':')
redis.zadd('ranking', member, int(score))
print('good bye')
https://github.com/nasa9084/samples.git
try to use redistry to use redis
try redistry redis
http://try.redis.io/
of?cial docker containerof?cial docker container
$ docker run redis
in conclusionin conclusion
in-memory KVS
having persistency
very varied data structure
String, List, Set, Hash, SortedSet
you can try to use redis with `try redis`

More Related Content

Similar to °Â±ð²ú¥¨¥ó¥¸¥Ë¥¢¤Î¤¿¤á¤Î¤Ï¤¸¤á¤Æ¤Î°ù±ð»å¾±²õ (20)

Ruby on Big Data (Cassandra + Hadoop)
Ruby on Big Data (Cassandra + Hadoop)Ruby on Big Data (Cassandra + Hadoop)
Ruby on Big Data (Cassandra + Hadoop)
Brian O'Neill
?
Web Performance Workshop - Velocity London 2013
Web Performance Workshop - Velocity London 2013Web Performance Workshop - Velocity London 2013
Web Performance Workshop - Velocity London 2013
Andy Davies
?
Better d3 charts with tdd
Better d3 charts with tddBetter d3 charts with tdd
Better d3 charts with tdd
Marcos Iglesias
?
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
Itamar Haber
?
NoSQL - An introduction to CouchDB
NoSQL - An introduction to CouchDBNoSQL - An introduction to CouchDB
NoSQL - An introduction to CouchDB
Jonathan Weiss
?
OpenCog Developer Workshop
OpenCog Developer WorkshopOpenCog Developer Workshop
OpenCog Developer Workshop
Ibby Benali
?
An introduction to Scala.js
An introduction to Scala.jsAn introduction to Scala.js
An introduction to Scala.js
Knoldus Inc.
?
Introduction to R
Introduction to RIntroduction to R
Introduction to R
Sander Kieft
?
ITCamp 2018 - Magnus M?rtensson - Azure Resource Manager For The Win
ITCamp 2018 - Magnus M?rtensson - Azure Resource Manager For The WinITCamp 2018 - Magnus M?rtensson - Azure Resource Manager For The Win
ITCamp 2018 - Magnus M?rtensson - Azure Resource Manager For The Win
ITCamp
?
Introducing redis
Introducing redisIntroducing redis
Introducing redis
Nuno Caneco
?
Redis is not just a cache, Andrew Lavers, ConFoo Montreal 2020
Redis is not just a cache, Andrew Lavers, ConFoo Montreal 2020Redis is not just a cache, Andrew Lavers, ConFoo Montreal 2020
Redis is not just a cache, Andrew Lavers, ConFoo Montreal 2020
Andrew Lavers
?
Om (Cont.)
Om (Cont.)Om (Cont.)
Om (Cont.)
Taku Fukushima
?
Redis in Practice: Scenarios, Performance and Practice with PHP
Redis in Practice: Scenarios, Performance and Practice with PHPRedis in Practice: Scenarios, Performance and Practice with PHP
Redis in Practice: Scenarios, Performance and Practice with PHP
Chen Huang
?
5 R Tutorial Data Visualization
5 R Tutorial Data Visualization5 R Tutorial Data Visualization
5 R Tutorial Data Visualization
Sakthi Dasans
?
Python redis talk
Python redis talkPython redis talk
Python redis talk
Josiah Carlson
?
Webinar: Data Processing and Aggregation Options
Webinar: Data Processing and Aggregation OptionsWebinar: Data Processing and Aggregation Options
Webinar: Data Processing and Aggregation Options
MongoDB
?
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
?
Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.
Mike Brevoort
?
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuPostgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Redis Labs
?
CouchDB on Rails
CouchDB on RailsCouchDB on Rails
CouchDB on Rails
Jonathan Weiss
?
Ruby on Big Data (Cassandra + Hadoop)
Ruby on Big Data (Cassandra + Hadoop)Ruby on Big Data (Cassandra + Hadoop)
Ruby on Big Data (Cassandra + Hadoop)
Brian O'Neill
?
Web Performance Workshop - Velocity London 2013
Web Performance Workshop - Velocity London 2013Web Performance Workshop - Velocity London 2013
Web Performance Workshop - Velocity London 2013
Andy Davies
?
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
Itamar Haber
?
NoSQL - An introduction to CouchDB
NoSQL - An introduction to CouchDBNoSQL - An introduction to CouchDB
NoSQL - An introduction to CouchDB
Jonathan Weiss
?
OpenCog Developer Workshop
OpenCog Developer WorkshopOpenCog Developer Workshop
OpenCog Developer Workshop
Ibby Benali
?
An introduction to Scala.js
An introduction to Scala.jsAn introduction to Scala.js
An introduction to Scala.js
Knoldus Inc.
?
ITCamp 2018 - Magnus M?rtensson - Azure Resource Manager For The Win
ITCamp 2018 - Magnus M?rtensson - Azure Resource Manager For The WinITCamp 2018 - Magnus M?rtensson - Azure Resource Manager For The Win
ITCamp 2018 - Magnus M?rtensson - Azure Resource Manager For The Win
ITCamp
?
Redis is not just a cache, Andrew Lavers, ConFoo Montreal 2020
Redis is not just a cache, Andrew Lavers, ConFoo Montreal 2020Redis is not just a cache, Andrew Lavers, ConFoo Montreal 2020
Redis is not just a cache, Andrew Lavers, ConFoo Montreal 2020
Andrew Lavers
?
Redis in Practice: Scenarios, Performance and Practice with PHP
Redis in Practice: Scenarios, Performance and Practice with PHPRedis in Practice: Scenarios, Performance and Practice with PHP
Redis in Practice: Scenarios, Performance and Practice with PHP
Chen Huang
?
5 R Tutorial Data Visualization
5 R Tutorial Data Visualization5 R Tutorial Data Visualization
5 R Tutorial Data Visualization
Sakthi Dasans
?
Webinar: Data Processing and Aggregation Options
Webinar: Data Processing and Aggregation OptionsWebinar: Data Processing and Aggregation Options
Webinar: Data Processing and Aggregation Options
MongoDB
?
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
?
Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.
Mike Brevoort
?
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, HerokuPostgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Postgres & Redis Sitting in a Tree- Rimas Silkaitis, Heroku
Redis Labs
?

More from nasa9084 (14)

°Â±ð²ú¥¨¥ó¥·?¥Ë¥¢¤Î¤¿¤á¤Î¤Ï¤·?¤á¤Æ¤Î°ù±ð»å¾±²õ.±è»å´Ú
°Â±ð²ú¥¨¥ó¥·?¥Ë¥¢¤Î¤¿¤á¤Î¤Ï¤·?¤á¤Æ¤Î°ù±ð»å¾±²õ.±è»å´Ú°Â±ð²ú¥¨¥ó¥·?¥Ë¥¢¤Î¤¿¤á¤Î¤Ï¤·?¤á¤Æ¤Î°ù±ð»å¾±²õ.±è»å´Ú
°Â±ð²ú¥¨¥ó¥·?¥Ë¥¢¤Î¤¿¤á¤Î¤Ï¤·?¤á¤Æ¤Î°ù±ð»å¾±²õ.±è»å´Ú
nasa9084
?
·É±ð²ú¥¨¥ó¥¸¥Ë¥¢¤Î¤¿¤á¤Î¤Ï¤¸¤á¤Æ¤Î°ù±ð»å¾±²õ
·É±ð²ú¥¨¥ó¥¸¥Ë¥¢¤Î¤¿¤á¤Î¤Ï¤¸¤á¤Æ¤Î°ù±ð»å¾±²õ·É±ð²ú¥¨¥ó¥¸¥Ë¥¢¤Î¤¿¤á¤Î¤Ï¤¸¤á¤Æ¤Î°ù±ð»å¾±²õ
·É±ð²ú¥¨¥ó¥¸¥Ë¥¢¤Î¤¿¤á¤Î¤Ï¤¸¤á¤Æ¤Î°ù±ð»å¾±²õ
nasa9084
?
±á³Ü²ú´Ç³Ù¤ò¤Ï¤¸¤á¤ë
±á³Ü²ú´Ç³Ù¤ò¤Ï¤¸¤á¤ë±á³Ü²ú´Ç³Ù¤ò¤Ï¤¸¤á¤ë
±á³Ü²ú´Ç³Ù¤ò¤Ï¤¸¤á¤ë
nasa9084
?
Web Environments
Web EnvironmentsWeb Environments
Web Environments
nasa9084
?
Efsta student session
Efsta student sessionEfsta student session
Efsta student session
nasa9084
?
LT!
LT!LT!
LT!
nasa9084
?
³õ¤á¤Æ¤Î³§²Ï³¢
³õ¤á¤Æ¤Î³§²Ï³¢³õ¤á¤Æ¤Î³§²Ï³¢
³õ¤á¤Æ¤Î³§²Ï³¢
nasa9084
?
³§³ó±ð±ô±ôÈëÃÅ
³§³ó±ð±ô±ôÈëÃų§³ó±ð±ô±ôÈëÃÅ
³§³ó±ð±ô±ôÈëÃÅ
nasa9084
?
DIVE INTO /regexp?/
DIVE INTO /regexp?/DIVE INTO /regexp?/
DIVE INTO /regexp?/
nasa9084
?
Flowchart w/program structure
Flowchart w/program structureFlowchart w/program structure
Flowchart w/program structure
nasa9084
?
±á°Õ°Õ±Ê¤Î¤ª»°
±á°Õ°Õ±Ê¤Î¤ª»°±á°Õ°Õ±Ê¤Î¤ª»°
±á°Õ°Õ±Ê¤Î¤ª»°
nasa9084
?
¥¨¥Ç¥£¥¿‘éÕù¤Î¤ª»°
¥¨¥Ç¥£¥¿‘éÕù¤Î¤ª»°¥¨¥Ç¥£¥¿‘éÕù¤Î¤ª»°
¥¨¥Ç¥£¥¿‘éÕù¤Î¤ª»°
nasa9084
?
³¢¾±²Ô³Ü³æ¥Ç¥£¥¹¥È¥ê¥Ó¥å©`¥·¥ç¥ó¤Î¤ª»°
³¢¾±²Ô³Ü³æ¥Ç¥£¥¹¥È¥ê¥Ó¥å©`¥·¥ç¥ó¤Î¤ª»°³¢¾±²Ô³Ü³æ¥Ç¥£¥¹¥È¥ê¥Ó¥å©`¥·¥ç¥ó¤Î¤ª»°
³¢¾±²Ô³Ü³æ¥Ç¥£¥¹¥È¥ê¥Ó¥å©`¥·¥ç¥ó¤Î¤ª»°
nasa9084
?
Introduction of Programming language
Introduction of Programming languageIntroduction of Programming language
Introduction of Programming language
nasa9084
?
°Â±ð²ú¥¨¥ó¥·?¥Ë¥¢¤Î¤¿¤á¤Î¤Ï¤·?¤á¤Æ¤Î°ù±ð»å¾±²õ.±è»å´Ú
°Â±ð²ú¥¨¥ó¥·?¥Ë¥¢¤Î¤¿¤á¤Î¤Ï¤·?¤á¤Æ¤Î°ù±ð»å¾±²õ.±è»å´Ú°Â±ð²ú¥¨¥ó¥·?¥Ë¥¢¤Î¤¿¤á¤Î¤Ï¤·?¤á¤Æ¤Î°ù±ð»å¾±²õ.±è»å´Ú
°Â±ð²ú¥¨¥ó¥·?¥Ë¥¢¤Î¤¿¤á¤Î¤Ï¤·?¤á¤Æ¤Î°ù±ð»å¾±²õ.±è»å´Ú
nasa9084
?
·É±ð²ú¥¨¥ó¥¸¥Ë¥¢¤Î¤¿¤á¤Î¤Ï¤¸¤á¤Æ¤Î°ù±ð»å¾±²õ
·É±ð²ú¥¨¥ó¥¸¥Ë¥¢¤Î¤¿¤á¤Î¤Ï¤¸¤á¤Æ¤Î°ù±ð»å¾±²õ·É±ð²ú¥¨¥ó¥¸¥Ë¥¢¤Î¤¿¤á¤Î¤Ï¤¸¤á¤Æ¤Î°ù±ð»å¾±²õ
·É±ð²ú¥¨¥ó¥¸¥Ë¥¢¤Î¤¿¤á¤Î¤Ï¤¸¤á¤Æ¤Î°ù±ð»å¾±²õ
nasa9084
?
±á³Ü²ú´Ç³Ù¤ò¤Ï¤¸¤á¤ë
±á³Ü²ú´Ç³Ù¤ò¤Ï¤¸¤á¤ë±á³Ü²ú´Ç³Ù¤ò¤Ï¤¸¤á¤ë
±á³Ü²ú´Ç³Ù¤ò¤Ï¤¸¤á¤ë
nasa9084
?
Web Environments
Web EnvironmentsWeb Environments
Web Environments
nasa9084
?
Efsta student session
Efsta student sessionEfsta student session
Efsta student session
nasa9084
?
³õ¤á¤Æ¤Î³§²Ï³¢
³õ¤á¤Æ¤Î³§²Ï³¢³õ¤á¤Æ¤Î³§²Ï³¢
³õ¤á¤Æ¤Î³§²Ï³¢
nasa9084
?
³§³ó±ð±ô±ôÈëÃÅ
³§³ó±ð±ô±ôÈëÃų§³ó±ð±ô±ôÈëÃÅ
³§³ó±ð±ô±ôÈëÃÅ
nasa9084
?
DIVE INTO /regexp?/
DIVE INTO /regexp?/DIVE INTO /regexp?/
DIVE INTO /regexp?/
nasa9084
?
Flowchart w/program structure
Flowchart w/program structureFlowchart w/program structure
Flowchart w/program structure
nasa9084
?
±á°Õ°Õ±Ê¤Î¤ª»°
±á°Õ°Õ±Ê¤Î¤ª»°±á°Õ°Õ±Ê¤Î¤ª»°
±á°Õ°Õ±Ê¤Î¤ª»°
nasa9084
?
¥¨¥Ç¥£¥¿‘éÕù¤Î¤ª»°
¥¨¥Ç¥£¥¿‘éÕù¤Î¤ª»°¥¨¥Ç¥£¥¿‘éÕù¤Î¤ª»°
¥¨¥Ç¥£¥¿‘éÕù¤Î¤ª»°
nasa9084
?
³¢¾±²Ô³Ü³æ¥Ç¥£¥¹¥È¥ê¥Ó¥å©`¥·¥ç¥ó¤Î¤ª»°
³¢¾±²Ô³Ü³æ¥Ç¥£¥¹¥È¥ê¥Ó¥å©`¥·¥ç¥ó¤Î¤ª»°³¢¾±²Ô³Ü³æ¥Ç¥£¥¹¥È¥ê¥Ó¥å©`¥·¥ç¥ó¤Î¤ª»°
³¢¾±²Ô³Ü³æ¥Ç¥£¥¹¥È¥ê¥Ó¥å©`¥·¥ç¥ó¤Î¤ª»°
nasa9084
?
Introduction of Programming language
Introduction of Programming languageIntroduction of Programming language
Introduction of Programming language
nasa9084
?

Recently uploaded (20)

UNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptx
UNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptxUNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptx
UNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptx
KesavanT10
?
only history of java.pptx real bihind the name java
only history of java.pptx real bihind the name javaonly history of java.pptx real bihind the name java
only history of java.pptx real bihind the name java
mushtaqsaliq9
?
GREEN BULIDING PPT FOR THE REFRENACE.PPT
GREEN BULIDING PPT FOR THE REFRENACE.PPTGREEN BULIDING PPT FOR THE REFRENACE.PPT
GREEN BULIDING PPT FOR THE REFRENACE.PPT
kamalkeerthan61
?
Wireless-Charger presentation for seminar .pdf
Wireless-Charger presentation for seminar .pdfWireless-Charger presentation for seminar .pdf
Wireless-Charger presentation for seminar .pdf
AbhinandanMishra30
?
Power Point Presentation for Electrical Engineering 3-phase.ppt
Power Point Presentation for Electrical Engineering 3-phase.pptPower Point Presentation for Electrical Engineering 3-phase.ppt
Power Point Presentation for Electrical Engineering 3-phase.ppt
Aniket_1415
?
Engineering at Lovely Professional University (LPU).pdf
Engineering at Lovely Professional University (LPU).pdfEngineering at Lovely Professional University (LPU).pdf
Engineering at Lovely Professional University (LPU).pdf
Sona
?
Air pollution is contamination of the indoor or outdoor environment by any ch...
Air pollution is contamination of the indoor or outdoor environment by any ch...Air pollution is contamination of the indoor or outdoor environment by any ch...
Air pollution is contamination of the indoor or outdoor environment by any ch...
dhanashree78
?
US Patented ReGenX Generator, ReGen-X Quatum Motor EV Regenerative Accelerati...
US Patented ReGenX Generator, ReGen-X Quatum Motor EV Regenerative Accelerati...US Patented ReGenX Generator, ReGen-X Quatum Motor EV Regenerative Accelerati...
US Patented ReGenX Generator, ReGen-X Quatum Motor EV Regenerative Accelerati...
Thane Heins NOBEL PRIZE WINNING ENERGY RESEARCHER
?
How to Make an RFID Door Lock System using Arduino
How to Make an RFID Door Lock System using ArduinoHow to Make an RFID Door Lock System using Arduino
How to Make an RFID Door Lock System using Arduino
CircuitDigest
?
Equipment for Gas Metal Arc Welding Process
Equipment for Gas Metal Arc Welding ProcessEquipment for Gas Metal Arc Welding Process
Equipment for Gas Metal Arc Welding Process
AhmadKamil87
?
Frankfurt University of Applied Science urkunde
Frankfurt University of Applied Science urkundeFrankfurt University of Applied Science urkunde
Frankfurt University of Applied Science urkunde
Lisa Emerson
?
Name.docxVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
Name.docxVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVName.docxVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
Name.docxVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
MerijimArsedelPalmad1
?
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
slayshadow705
?
GM Meeting 070225 TO 130225 for 2024.pptx
GM Meeting 070225 TO 130225 for 2024.pptxGM Meeting 070225 TO 130225 for 2024.pptx
GM Meeting 070225 TO 130225 for 2024.pptx
crdslalcomumbai
?
CONTRACTOR ALL RISK INSURANCESAR (1).ppt
CONTRACTOR ALL RISK INSURANCESAR (1).pptCONTRACTOR ALL RISK INSURANCESAR (1).ppt
CONTRACTOR ALL RISK INSURANCESAR (1).ppt
suaktonny
?
Mathematics behind machine learning INT255 INT255__Unit 3__PPT-1.pptx
Mathematics behind machine learning INT255 INT255__Unit 3__PPT-1.pptxMathematics behind machine learning INT255 INT255__Unit 3__PPT-1.pptx
Mathematics behind machine learning INT255 INT255__Unit 3__PPT-1.pptx
ppkmurthy2006
?
15. Smart Cities Big Data, Civic Hackers, and the Quest for a New Utopia.pdf
15. Smart Cities Big Data, Civic Hackers, and the Quest for a New Utopia.pdf15. Smart Cities Big Data, Civic Hackers, and the Quest for a New Utopia.pdf
15. Smart Cities Big Data, Civic Hackers, and the Quest for a New Utopia.pdf
NgocThang9
?
Taykon-Kalite belgeleri
Taykon-Kalite belgeleriTaykon-Kalite belgeleri
Taykon-Kalite belgeleri
TAYKON
?
GROUP-3-GRID-CODE-AND-DISTRIBUTION-CODE.pptx
GROUP-3-GRID-CODE-AND-DISTRIBUTION-CODE.pptxGROUP-3-GRID-CODE-AND-DISTRIBUTION-CODE.pptx
GROUP-3-GRID-CODE-AND-DISTRIBUTION-CODE.pptx
meneememoo
?
Introduction to Safety, Health & Environment
Introduction to Safety, Health  & EnvironmentIntroduction to Safety, Health  & Environment
Introduction to Safety, Health & Environment
ssuserc606c7
?
UNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptx
UNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptxUNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptx
UNIT 1FUNDAMENTALS OF OPERATING SYSTEMS.pptx
KesavanT10
?
only history of java.pptx real bihind the name java
only history of java.pptx real bihind the name javaonly history of java.pptx real bihind the name java
only history of java.pptx real bihind the name java
mushtaqsaliq9
?
GREEN BULIDING PPT FOR THE REFRENACE.PPT
GREEN BULIDING PPT FOR THE REFRENACE.PPTGREEN BULIDING PPT FOR THE REFRENACE.PPT
GREEN BULIDING PPT FOR THE REFRENACE.PPT
kamalkeerthan61
?
Wireless-Charger presentation for seminar .pdf
Wireless-Charger presentation for seminar .pdfWireless-Charger presentation for seminar .pdf
Wireless-Charger presentation for seminar .pdf
AbhinandanMishra30
?
Power Point Presentation for Electrical Engineering 3-phase.ppt
Power Point Presentation for Electrical Engineering 3-phase.pptPower Point Presentation for Electrical Engineering 3-phase.ppt
Power Point Presentation for Electrical Engineering 3-phase.ppt
Aniket_1415
?
Engineering at Lovely Professional University (LPU).pdf
Engineering at Lovely Professional University (LPU).pdfEngineering at Lovely Professional University (LPU).pdf
Engineering at Lovely Professional University (LPU).pdf
Sona
?
Air pollution is contamination of the indoor or outdoor environment by any ch...
Air pollution is contamination of the indoor or outdoor environment by any ch...Air pollution is contamination of the indoor or outdoor environment by any ch...
Air pollution is contamination of the indoor or outdoor environment by any ch...
dhanashree78
?
How to Make an RFID Door Lock System using Arduino
How to Make an RFID Door Lock System using ArduinoHow to Make an RFID Door Lock System using Arduino
How to Make an RFID Door Lock System using Arduino
CircuitDigest
?
Equipment for Gas Metal Arc Welding Process
Equipment for Gas Metal Arc Welding ProcessEquipment for Gas Metal Arc Welding Process
Equipment for Gas Metal Arc Welding Process
AhmadKamil87
?
Frankfurt University of Applied Science urkunde
Frankfurt University of Applied Science urkundeFrankfurt University of Applied Science urkunde
Frankfurt University of Applied Science urkunde
Lisa Emerson
?
Name.docxVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
Name.docxVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVName.docxVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
Name.docxVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
MerijimArsedelPalmad1
?
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
slayshadow705
?
GM Meeting 070225 TO 130225 for 2024.pptx
GM Meeting 070225 TO 130225 for 2024.pptxGM Meeting 070225 TO 130225 for 2024.pptx
GM Meeting 070225 TO 130225 for 2024.pptx
crdslalcomumbai
?
CONTRACTOR ALL RISK INSURANCESAR (1).ppt
CONTRACTOR ALL RISK INSURANCESAR (1).pptCONTRACTOR ALL RISK INSURANCESAR (1).ppt
CONTRACTOR ALL RISK INSURANCESAR (1).ppt
suaktonny
?
Mathematics behind machine learning INT255 INT255__Unit 3__PPT-1.pptx
Mathematics behind machine learning INT255 INT255__Unit 3__PPT-1.pptxMathematics behind machine learning INT255 INT255__Unit 3__PPT-1.pptx
Mathematics behind machine learning INT255 INT255__Unit 3__PPT-1.pptx
ppkmurthy2006
?
15. Smart Cities Big Data, Civic Hackers, and the Quest for a New Utopia.pdf
15. Smart Cities Big Data, Civic Hackers, and the Quest for a New Utopia.pdf15. Smart Cities Big Data, Civic Hackers, and the Quest for a New Utopia.pdf
15. Smart Cities Big Data, Civic Hackers, and the Quest for a New Utopia.pdf
NgocThang9
?
Taykon-Kalite belgeleri
Taykon-Kalite belgeleriTaykon-Kalite belgeleri
Taykon-Kalite belgeleri
TAYKON
?
GROUP-3-GRID-CODE-AND-DISTRIBUTION-CODE.pptx
GROUP-3-GRID-CODE-AND-DISTRIBUTION-CODE.pptxGROUP-3-GRID-CODE-AND-DISTRIBUTION-CODE.pptx
GROUP-3-GRID-CODE-AND-DISTRIBUTION-CODE.pptx
meneememoo
?
Introduction to Safety, Health & Environment
Introduction to Safety, Health  & EnvironmentIntroduction to Safety, Health  & Environment
Introduction to Safety, Health & Environment
ssuserc606c7
?

°Â±ð²ú¥¨¥ó¥¸¥Ë¥¢¤Î¤¿¤á¤Î¤Ï¤¸¤á¤Æ¤Î°ù±ð»å¾±²õ

  • 2. $ whoami$ whoami Masahiro Kitamura @nasa9084 VirtualTech Japan Inc. KEYWORDS: emacs python golang(new!) whiske?y
  • 4. What is "redis"?What is "redis"? remote dictionary server Key-Value Store (KVS) Varied Data Structure in-memory having persistence easy and fast compatible w/Python, Ruby, ¡­ ¡úweb engineers should learn redis!
  • 5. Key-value Store (KVS)Key-value Store (KVS) dict(Python) hash(Perl, Ruby) map(C++, Java, Go) namespaces
  • 6. Comparison with RDBMSsComparison with RDBMSs Function RDBMS Redis using simply ¡÷ ¡ò high speed processing ¡÷ ¡ò horizontal distribution ¡Á ¡ò high availability ¡÷ ¡ò persistency ¡ò ¡ð complex query ¡ò ¡Á transaction ¡ò ¡÷ consistency ¡ò ¡÷
  • 7. Comparison with memcachedComparison with memcached memcached redis good at Cache Cache data structure only string varied structure persistency ¡Á ¡ð Disk I/O NOT DO can be disable speed high high multi thread ¡ð ¡Á memory ef?ciency ¡÷ ¡ð
  • 8. Redis Data StructureRedis Data Structure
  • 9. StringString String replace get length number INCR / DECR max: 512MB binary safe can insert pictures, etc
  • 10. StringString redis python > SET hoge fugafuga OK > GET hoge "fugafuga" > SET point 10 OK > GET point "10" > INCR point (integer) 11 > GET point "11" from redis import Redis redis = Redis() redis.set('hoge', 'fugafuga') print(redis.get('hoge')) #=> b'fugafuga' redis.set('point', 10) print(redis.get('point')) #=> b'10' redis.incr('point') print(redis.get('point')) #=> b'11'
  • 11. ListList List of Strings Implemented with Linked List insert or access to head or tail: access to mid: max size: 232-1 elements O(1) O(N)
  • 12. ListList redis python > LPUSH 1 2 3 (integer) 3 > LRANGE piyo 0 -1 "3" "2" "1" > LPOP piyo "3" > LRANGE piyo 0 -1 "2" "1" from redis import Redis redis = Redis() redis.lpush('piyo', 1, 2, 3) print(redis.lrange('piyo', 0, -1)) #=> [b'3', b'2', b'1'] print(redis.lpop('piyo')) #=> b'3' print(redis.lrange('piyo', 0, -1)) #=> [b'2', b'1']
  • 13. SetSet Set of Strings un-ordered no duplication add, delete, access avarage: max size: 232-1 elements O(1)
  • 14. SetSet redis python > SADD foo 1 3 5 (integer) 3 > SMEMBERS foo "1" "3" "5" > SADD foo 1 (integer) 0 > SMEMBERS foo "1" "3" "5" from redis import Redis redis = Redis() redis.sadd('foo', 1, 3, 5) print(redis.smembers('foo')) #=>{b'3', b'5', b'1'} redis.sadd('foo', 1) print(redis.smembers('foo')) #=>{b'3', b'5', b'1'}
  • 15. Sorted Set (ZSet)Sorted Set (ZSet) Set of Strings no duplication each members are ordered with its Score take Score: add: O(1) O(log N)
  • 16. Sorted Set (ZSet)Sorted Set (ZSet) redis python > ZADD bar 20 ham (integer) 1 > ZADD bar 10 egg (integer) 1 > ZADD bar 30 spam (integer) 1 > ZRANGE bar 0 -1 WITHSCORES 1) "egg" 2) "10" 3) "ham" 4) "20" 5) "spam" 6) "30" from redis import Redis redis = Redis() redis.zadd('bar', 'ham', 20) redis.zadd('bar', 'egg', 10) redis.zadd('bar', 'spam', 30) print( redis.zrange('bar', 0, -1, withscores=True) ) #=>[(b'egg', 10.0), (b'ham', 20.0), (b'spam', 30.0)]
  • 17. HashHash String to String map Java: HashMap<String, String> Go: ~map[string]string add, delete, access: max size: 232-1 pairs O(1)
  • 18. HashHash redis python > HSET bar 0:00 5 (integer) 1 > HGETALL bar 1) "0:00" 2) "5" > HMSET bar 1:00 5 2:00 6 (integer) 2 > HKEYS bar 1) "0:00" 2) "1:00" 3) "2:00" > HGET bar 0:00 "5" from redis import Redis redis = Redis() redis.hset('bar', '0:00', '5') print(redis.hgetall('bar')) #=>{b'0:00': b'5'} add_dict = { '1:00': '5', '2:00': '6' } redis.hmset('bar', add_dict) print(redis.hkeys('bar')) #=>[b'0:00', b'1:00', b'2:00] print(redis.hget('bar', '0:00')) #=>b'5'
  • 20. data having expirationdata having expiration can set expiration to key EXPIRE key seconds `key` is expired after `seconds` seconds EXPIREAT key timestamp `key` is expired on `timestamp`
  • 21. for example,for example, Session ID One Time Token
  • 22. Sample CodeSample Code from redis import Redis from uuid import uuid4 class User: def generate_apikey(self): redis = Redis(host='localhost', port=6389) if redis.exists(self.token): return self.token new_apikey = 'hbt-' + str(uuid4()) ttl = 10 * 60 * 60 # 10 minutes redis.setex(new_apikey, self.name, ttl) self.apikey = new_apikey return self.apikey https://github.com/web-apps-tech/hubotmaker.git https://hubot.web-apps.tech/
  • 23. Real Time RankingReal Time Ranking sorted set zadd key score member key¤Ëscoreµã¤ò³Ö¤Ã¤¿member¤ò×·¼Ó¤¹¤ë add a `member` that has `score` to `key` zincrby key increment member increment score of `member` of `key` zrange key start stop get `key`s members from `start` to `stop`
  • 24. Sample CodeSample Code from redis import Redis redis = Redis() while True: print('input member:score> ', end='') ipt = input() if ipt == 'show': # command 'show' ranking = redis.zrange('ranking', 0, 5, withscores=True)[::-1] for i, m in enumerate(ranking): values = { 'rank': i+1, 'member': m[0].decode(), 'point': m[1] } print('{rank}: {member} ({point}pt)'.format(**values)) continue member, score = args.split(':') redis.zadd('ranking', member, int(score)) print('good bye') https://github.com/nasa9084/samples.git
  • 25. try to use redistry to use redis
  • 27. of?cial docker containerof?cial docker container $ docker run redis
  • 28. in conclusionin conclusion in-memory KVS having persistency very varied data structure String, List, Set, Hash, SortedSet you can try to use redis with `try redis`