Your SlideShare is downloading. ×
0
A Brief Introduction to
Redis
Charles Anderson	

!

Salem Dynamic Languages User Group	

January 2014
Overview
• Redis is a networked “data structure
server”	


• Fast, powerful, simple
Abstract Data Types
• In the Before Time, we didn’t have classes
and objects - we had abstract data types	


•

and, we li...
Example: Stack
• push(stack, item)	

• pop(stack): item	

• size(stack): int	

• etc.
Stack ADT
• We had a single, global name space. So:	

• stack_push(stack, item)	

• stack_pop(stack)	

• stack_size(stack)...
Redis Types
• String - scalar value	

• List	

• Set	

• Sorted Set	

• Hash
Redis List
• A small subset of the operations:	

• LPUSH key value	

• LPOP key	

• LLEN key	

• LRANGE key start stop
Redis API
• Every object has a name/key	

• First parameter to each call	

• Every object has a type	

• Operation must ma...
Using API via CLI
$ redis-cli	
redis 127.0.0.1:6379> lpush mylist 1	
(integer) 1	
redis 127.0.0.1:6379> lpush mylist cat	
...
Redis Clients
• The wire protocol for Redis is dead-simple	

• Therefore, lots of clients for lots of
languages
Ruby Client Demo
irb(main):015:0> r.lpush('mylist', 1)	
=> 1	
irb(main):016:0> r.lpush('mylist', 'cat')	
=> 2	
irb(main):0...
Complete Redis API
• http://redis.io/commands	

• Each command includes the time

complexity of the operation - unique
Set
• SADD key member, SREM key member	

• SCARD key	

• SISMEMEBER key member	

• SINTER, SUNION
Sorted Set
• ZADD key score member	

• ZSCORE key member	

• ZRANK key member	

• ZRANGE key start stop	

• Use case: lead...
Hash
• HSET key field value	

• HGET key field	

• HEXISTS key field, HKEYS, HLEN	

• Use case: a structured record like User
Other Stuff
• Key Expiration	

• Transactions/batches	

• Publish-Subscribe	

• Server-side scripting via Lua	

• Replicat...
Implementation Details
• Everything is stored in memory	

•
•

Hella fast	

Not memcache - expiration is not LRU	


• Pers...
But, is it Web
Scale?
• NoSQL key/value store	

• Kickass benchmarks	

• Simpler (smaller scope) than HBase or
Cassandra	
...
More Information
• http://redis.io	

• “The Little Redis Book” Seguin	

• “Redis in Action” Carlson	

• “Redis Cookbook” M...
Questions

•?
Upcoming SlideShare
Loading in...5
×

A Brief Introduction to Redis

986

Published on

This is a brief, high-level overview of Redis, a networked data structure server.

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

No Downloads
Views
Total Views
986
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
16
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "A Brief Introduction to Redis"

  1. 1. A Brief Introduction to Redis Charles Anderson ! Salem Dynamic Languages User Group January 2014
  2. 2. Overview • Redis is a networked “data structure server” • Fast, powerful, simple
  3. 3. Abstract Data Types • In the Before Time, we didn’t have classes and objects - we had abstract data types • and, we liked it! • Procedural interface • First (or last) parameter is the ADT
  4. 4. Example: Stack • push(stack, item) • pop(stack): item • size(stack): int • etc.
  5. 5. Stack ADT • We had a single, global name space. So: • stack_push(stack, item) • stack_pop(stack) • stack_size(stack) • This is what the Redis API looks like
  6. 6. Redis Types • String - scalar value • List • Set • Sorted Set • Hash
  7. 7. Redis List • A small subset of the operations: • LPUSH key value • LPOP key • LLEN key • LRANGE key start stop
  8. 8. Redis API • Every object has a name/key • First parameter to each call • Every object has a type • Operation must match the type of object
  9. 9. Using API via CLI $ redis-cli redis 127.0.0.1:6379> lpush mylist 1 (integer) 1 redis 127.0.0.1:6379> lpush mylist cat (integer) 2 redis 127.0.0.1:6379> lpush mylist 3.14 (integer) 3 redis 127.0.0.1:6379> llen mylist (integer) 3 redis 127.0.0.1:6379> lrange mylist 0 1 1) "3.14" 2) "cat" redis 127.0.0.1:6379> lrange mylist 0 -1 1) "3.14" 2) "cat" 3) "1"
  10. 10. Redis Clients • The wire protocol for Redis is dead-simple • Therefore, lots of clients for lots of languages
  11. 11. Ruby Client Demo irb(main):015:0> r.lpush('mylist', 1) => 1 irb(main):016:0> r.lpush('mylist', 'cat') => 2 irb(main):017:0> r.lpush('mylist', 3.14) => 3 irb(main):019:0> r.lrange('mylist', 0, -1) => ["3.14", "cat", "1"]
  12. 12. Complete Redis API • http://redis.io/commands • Each command includes the time complexity of the operation - unique
  13. 13. Set • SADD key member, SREM key member • SCARD key • SISMEMEBER key member • SINTER, SUNION
  14. 14. Sorted Set • ZADD key score member • ZSCORE key member • ZRANK key member • ZRANGE key start stop • Use case: leader board
  15. 15. Hash • HSET key field value • HGET key field • HEXISTS key field, HKEYS, HLEN • Use case: a structured record like User
  16. 16. Other Stuff • Key Expiration • Transactions/batches • Publish-Subscribe • Server-side scripting via Lua • Replication • Clustering
  17. 17. Implementation Details • Everything is stored in memory • • Hella fast Not memcache - expiration is not LRU • Persistent - tunable disk storage • Single-threaded - simple, fast, single CPU • Support (@antirez) is awesome
  18. 18. But, is it Web Scale? • NoSQL key/value store • Kickass benchmarks • Simpler (smaller scope) than HBase or Cassandra • Sharding done by clients • Not usually a system of record • I already work on a farm
  19. 19. More Information • http://redis.io • “The Little Redis Book” Seguin • “Redis in Action” Carlson • “Redis Cookbook” Macedo and Oliveira
  20. 20. Questions •?
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×