Date post: | 27-Jun-2015 |
Category: |
Technology |
Upload: | hari-bachala |
View: | 174 times |
Download: | 0 times |
1
Remote Dictionary Server
Redis
Presented By
HARI
2
Agenda
I . Introduction Context, Popular Redis Users
II. Basics
How to use, Real time use cases , Data Types.
few Advance supported features …………
Transactions, public/subscribe, Clusters, Replication
Agenda
3
Redis is an open source, networked, single threaded, in- memory Advanced key value store with optional
durability .
It is often referred to as a data structure server since keys can contain strings ,hashes, lists, sets, and sorted sets.
Context
4
Popular Redis Users
5
Document DBs
‣ Mongo DB, Couch DB,…
Graph DBs
‣ Neo4j, Flock DB…
Column oriented DBs
‣ HBase, Cassandra, BigTable…
Key-Value DBs
‣ Memcache, MemcacheDB, Redis,……
No SQL Data Bases
6
Written in C(No external dependence)
Uses memory as main storage
Uses disk for persistence
Single Threaded
Fast performance
~50k read/write operations per second
Few Fundamentals
7
How to use
Download Latest Version here
Extract it And start sever
configurations: redis.conf
Connect via client/s
For practice you can use http://try.redis.io/
8
Arbitrary ASCII strings
‣ Define some format convention and adhere to it
‣ Key length matters!
Multiple name spaces are available
‣ Separate DBs indexed by an integer value
‣ SELECT command
Keys can expire automatically (if you specify TTL)
Keys
9
Data Types
10
• APPEND
• GET
• SET
• STRLEN
• INCR
• DECR
• INCRBY
• DECRBY
• few more #string commands
String Commands
11
• LLEN
• LPOP
• LPUSH
• LRANGE
• LREM
• LINSERT
• RPOP
• RPUSH
Lists Commands
12
• SADD
• SCARD
• SDIFF
• SMEMBERS
• SMOVE
• SPOP
• SREM
Sets Commands
13
• ZADD
• ZCARD
• ZCOUNT
• ZRANGE
• ZRANK
• ZREM
• ZSCORE
• ZSCAN
Sorted Sets Commands
14
C (hiredis,credis,libredis)
C# (ServiceStack.Redis,StackExchange.Redis)
C++(redis3m, C++ Client)
Java(Jedis,Jredis, JDBC-Redis)
Perl(Redis, RedisDB)
PHP(Predis, phpredis)
• few more clients
•
Redis Clients
15
Public class TestJedis {
public static void main(String[] args) {
Jedis jedis = new Jedis("localhost");
jedis.set("key", "value");
System.out.println(jedis.get("key"));
}
}
Redis with java client (Jedis)
16
Jedis(String host)
Jedis (String host, int port)
Maven dependency
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.5.2</version>
</dependency>
Jedis constructor
17
Redis pipelines are just a RTT optimization
‣Deliver multiple commands together without waiting for replies
‣Fetch all replies in a single step
‣ Server needs to buffer all replies!
Pipelines are NOT transactional or atomic
‣ Much more flexible alternative
Pipe lines
18
Classic pattern decoupling publishers & subscribers
You can subscribe to channels; when someone publish in a channel matching your interests Redis will send it to you
PUBLISH
SUBSCRIBE,
UNSUBSCRIBE
Publish/Subscribe
19
Commands are executed as an atomic & single isolated operation
DISCARD
MULTI
EXEC
Transactions
20
One master — Multiple slaves
Scalability & redundancy
Client side failover, eviction, query routing…
Slaves are able to accept other slave connections
Asynchronous but periodically acknowledged
Automatic slave reconnection
Replication
21
Released in Redis 3.0
High performance & linearly scalable complex distributed DB
Sharding across multiple nodes
Graceful handling of network partitions
Redis Cluster
22
Need a faster response
Need a Atomic operations
Need a transactions
Need a publish/subscribe model
Support for persistence
Job queue, session store, Real Time Ranking
Real Time Use cases
23
Name Memchahe Redis
Description In-memory key-value store, originally intended for caching
In-memory database with configurable options performance vs. persistency
Release : 2003 2009
Implementation language C C
Server-side scripts NO Lua
Replication methods None Master-Slave
SQL No NO
Database model Key-value Key-value
Database schema No NO
Supported programming languages Net,C,C++,ColdFusion,Erlang,Java,LispLua,Ocaml,Perl,PHP,Python,Ruby
C,C#,C++,Clojure,Dart,Erlang,Go,Java,JavaScript,Lisp,Lua,Objective-CPerl,PHP,Python,Ruby,Scala,SmalltalkTcl
Redis vs Memcache
24
FastSimpleReliable
PredictableLight weight
Widely supported
Summary