A Simple Introduction to Redis                   Zhichao Liang         frankey0207@gmail.com
What’s Redis?• Redis is an open source, advanced key-value store. It  is often referred to as a data structure server sinc...
How to use Redis?• We can download the source code of Redis from  http://redis.io/download and install it just by make  &&...
C Client• Hiredis is a official C client library for the Redis  database.• We can download Hiredis from  https://github.co...
Java Client• Jedis is a blazingly small and sane Redis java client.• We can download Jedis package from  https://github.co...
Redis Persistence• Redis provides a different range of persistence  options: RDB and AOF.• The RDB persistence performs po...
Redis Replication• Redis master-slave replication allows slave Redis  servers to be exact copies of master.  - A master ca...
Redis Cluster• Redis nodes are connected and functionally  equivalent, but actually there are two kinds of nodes:  master ...
Redis Replication
Who’s using Redis? • Redis has been widely used in microblog serviceredis> hset yaochen follows 547(integer) 1 by Sina Wei...
Upcoming SlideShare
Loading in …5
×

A simple introduction to redis

3,461 views

Published on

A very simple introduction to Redis!

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,461
On SlideShare
0
From Embeds
0
Number of Embeds
22
Actions
Shares
0
Downloads
98
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

A simple introduction to redis

  1. 1. A Simple Introduction to Redis Zhichao Liang frankey0207@gmail.com
  2. 2. What’s Redis?• Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.• Redis is written in ANSI C and works in most POSIX systems like Linux, *BSD, OS X and Solaris without external dependencies.• Redis can be used from most programming languages, such as C, C#, C++, Java, Lua, Node.js, Perl, Objective-C, PHP, Python, Ruby, Smalltalk, Scala, Erlang, Common Lisp …
  3. 3. How to use Redis?• We can download the source code of Redis from http://redis.io/download and install it just by make && make install.• By default, both the server and client of Redis can be found in the directory /usr/local/bin after installation.• Some common commands: - set/get/mset/mget - lpush/rpush/lpop/rpop - hset/hget/hmset/hmget - sadd/smembers/zadd/zrange
  4. 4. C Client• Hiredis is a official C client library for the Redis database.• We can download Hiredis from https://github.com/antirez/hiredis/downloads. redisContext *c = redisConnect("127.0.0.1", 6379); if (c->err) { printf("Error: %sn", c->errstr); } reply = redisCommand(redisContext , "SET foo bar");
  5. 5. Java Client• Jedis is a blazingly small and sane Redis java client.• We can download Jedis package from https://github.com/xetorthio/jedis/downloads. Jedis jedis = new Jedis("localhost"); jedis.connect(); jedis.set("foo", "bar"); String value = jedis.get("foo");
  6. 6. Redis Persistence• Redis provides a different range of persistence options: RDB and AOF.• The RDB persistence performs point-in-time snapshots of your dataset at specified intervals. - #save 900 1 or #save 300 10• The AOF persistence logs every write operation received by the server, that will be played again at server startup, reconstructing the original dataset. - no fsync at all or fsync every second or fsync at every query
  7. 7. Redis Replication• Redis master-slave replication allows slave Redis servers to be exact copies of master. - A master can have multiple slaves slave -Slaves can accept other slaves connections master - Non-blocking at the master side slave - Replication can be used for scalability - Replication can avoid saving process at master side
  8. 8. Redis Cluster• Redis nodes are connected and functionally equivalent, but actually there are two kinds of nodes: master nodes and slave nodes. 1 0 4 2 3 1 3 5 4 master 0 slave 2 0 5 2 1 5 4 3
  9. 9. Redis Replication
  10. 10. Who’s using Redis? • Redis has been widely used in microblog serviceredis> hset yaochen follows 547(integer) 1 by Sina Weibo. proviedredis> hset yaochen fans 17647778(integer) 1redis> hset yaochen microblogs5359(integer) 1redis> hgetall yaochen1) “follows"2) “547"3) "fans"4) “17647778"5) "microblogs"6) “5359"

×