A simple introduction to redis
Upcoming SlideShare
Loading in...5
×
 

A simple introduction to redis

on

  • 2,916 views

A very simple introduction to Redis!

A very simple introduction to Redis!

Statistics

Views

Total Views
2,916
Views on SlideShare
2,916
Embed Views
0

Actions

Likes
2
Downloads
79
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

A simple introduction to redis A simple introduction to redis Presentation Transcript

  • 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 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 …
  • 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
  • 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");
  • 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");
  • 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
  • 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
  • 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
  • Redis Replication
  • 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"