Redis And Python PyCon India, 2011 (Work in Progress) Sunil Arora.

Slides:



Advertisements
Similar presentations
Running Your Startup on Amazon Web Services Alex Iskold Founder/CEO AdaptiveBlue Feature Writer ReadWriteWeb.
Advertisements

More about Ruby Maciej Mensfeld Presented by: Maciej Mensfeld More about Ruby dev.mensfeld.pl github.com/mensfeld.
P2P data retrieval DHT (Distributed Hash Tables) Partially based on Hellerstein’s presentation at VLDB2004.
A persistent key-value database
Parallel Processing (CS526) Spring 2012(Week 6).  A parallel algorithm is a group of partitioned tasks that work with each other to solve a large problem.
Distributed Storage March 12, Distributed Storage What is Distributed Storage?  Simple answer: Storage that can be shared throughout a network.
K ALI ROHAN KOKA AZEEM HIRANI. A Simple database Implementing a Dictionary where keys are associated with values. For e.g.: It can set the key “surname_1987”
Secure web browsers, malicious hardware, and hardware support for binary translation Sam King.
Kafka high-throughput, persistent, multi-reader streams
MSN 2004 Network Memory Servers: An idea whose time has come Glenford Mapp David Silcott Dhawal Thakker.
Ken Birman Cornell University. CS5410 Fall
Typical Caching Patterns Web Tier Data Storage SQL Data.
1 JBus, A Platform Independent Publish/Subscribe Bus for CWave 2000 M.S. Thesis Defense Joseph W. Longson March 30, 2000.
Overview Memory definitions Random Access Memory (RAM)
1 Lecture 1  Getting ready to program  Hardware Model  Software Model  Programming Languages  The C Language  Software Engineering  Programming.
Homework 2 In the docs folder of your Berkeley DB, have a careful look at documentation on how to configure BDB in main memory. In the docs folder of your.
Introduction to a Programming Environment
Fundamentals of Python: From First Programs Through Data Structures
Google Distributed System and Hadoop Lakshmi Thyagarajan.
Authentication Approaches over Internet Jia Li
Bertrand Bellenot root.cern.ch ROOT I/O in JavaScript Reading ROOT files from any web browser ROOT Users Workshop
For more notes and topics visit:
Selecting and Implementing An Embedded Database System Presented by Jeff Webb March 2005 Article written by Michael Olson IEEE Software, 2000.
ECE 526 – Network Processing Systems Design Network Processor Architecture and Scalability Chapter 13,14: D. E. Comer.
علیرضا فراهانی استاد درس: جعفری نژاد مهر Version Control ▪Version control is a system that records changes to a file or set of files over time so.
M i SMob i S Mob i Store - Mobile i nternet File Storage Platform Chetna Kaur.
Written by Margo Seltzer Presented by Mark Simko.
Chapter 3.5 Memory and I/O Systems. 2 Memory Management Memory problems are one of the leading causes of bugs in programs (60-80%) MUCH worse in languages.
 70s - Database access is hard and depends on the app  80s – Relational databases come on the scene  90s – Object oriented programming and DBs  00s.
Search - on the Web and Locally Related directly to Web Search Engines: Part 1 and Part 2. IEEE Computer. June & August 2006.
Redis Key-Value Database: Practical Introduction
Róbert Móro. redis In-memory key-value store Master-slave replication Persistence – RDB (snapshots) – AOF (append-only log file) Supported languages –
File Organization Lecture 1
INNOV-10 Progress® Event Engine™ Technical Overview Prashant Thumma Principal Software Engineer.
Google App Engine MemCache ae-09-session
CS 127 Introduction to Computer Science. What is a computer?  “A machine that stores and manipulates information under the control of a changeable program”
Chapter 5 Files and Exceptions I. "The Practice of Computing Using Python", Punch & Enbody, Copyright © 2013 Pearson Education, Inc. What is a file? A.
Elementary Data Organization. Outline  Data, Entity and Information  Primitive data types  Non primitive data Types  Data structure  Definition 
How to Build High Performance Apps Using Microsoft Azure Redis Cache
What is a Servlet? Java Program that runs in a Java web server and conforms to the servlet api. A program that uses class library that decodes and encodes.
Copyright © 2006, GemStone Systems Inc. All Rights Reserved. Increasing computation throughput with Grid Data Caching Jags Ramnarayan Chief Architect GemStone.
AMQP, Message Broker Babu Ram Dawadi. overview Why MOM architecture? Messaging broker like RabbitMQ in brief RabbitMQ AMQP – What is it ?
XROOTD AND FEDERATED STORAGE MONITORING CURRENT STATUS AND ISSUES A.Petrosyan, D.Oleynik, J.Andreeva Creating federated data stores for the LHC CC-IN2P3,
FILE ORGANIZATION.
 Packages:  Scrapy, Beautiful Soup  Scrapy  Website  
Bigtable: A Distributed Storage System for Structured Data
Onlinedeeneislam.blogspot.com1 Design and Analysis of Algorithms Slide # 1 Download From
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 24: GFS.
Final Fantasy ½: IOC Overview Team Q CSE 403 Winter ‘03 I’ve got something special for you.
Get more than a cache back! The Microsoft Azure (Redis) Cache Maarten
Amazon Web Services. Amazon Web Services (AWS) - robust, scalable and affordable infrastructure for cloud computing. This session is about:
Log-Structured Memory for DRAM-Based Storage Stephen Rumble and John Ousterhout Stanford University.
NOSQL Yan
Redis and Redis with .NET
EMERALDS Landon Cox March 22, 2017.
Redis:~ Author Anil Sharma Data Structure server.
open source, advanced key-value store, data structure server
Background on the need for Synchronization
Computational Models Database Lab Minji Jo.
The Variable-Increment Counting Bloom Filter
Say Hello to my Little Friend - Fedora Messaging Infrastructure
Emitter: Scalable, fast and secure pub/sub in Go
Final Fantasy ½: LCO Overview
Emitter: Scalable, fast and secure pub/sub in Go
FILE ORGANIZATION.
Designing Parallel Algorithms (Synchronization)
Lecture Topics: 11/1 General Operating System Concepts Processes
Redis Presenter: Crystal.
CSE 326: Data Structures Lecture #14
Presentation transcript:

Redis And Python PyCon India, 2011 (Work in Progress) Sunil Arora

Raising Hands... How many of you have used Redis before ? How many of you have got a laptop here ?

Who Sunil Arora Work for ShopSocially ( Interests: Backend, Frontend, scaling, internet technologies in general, startups... all kind of shit

Who Sunil Arora Work for ShopSocially ( Interests: Backend, Frontend, scaling, internet technologies in general, startups...

Today's talk What is Redis How it works and what you can do with it Real life use-cases

What is Redis ? Its between lot of stuff, so difficult to categorize it precisely

What is Redis ? I see Redis definitely more as a flexible tool that as a solution specialized to solve a specific problem: his mixed soul of cache, store, and messaging server shows this very well -Salvatore Sanfilippo Picture by herzogbr

Brief History of Redis Released in March 2009 by Salvator Sanfilippo Open source, BSD licensed VMWare sponsored its development in March, 2010

A few fundamentals Written in C (25K LOC) Uses memory as main storage Single Threaded Uses disk for persistence Screamingly fast performance 50K read/write operations per seconds 200K read/write ops per second on a regular EC2 instance

Installation $ git clone $ cd redis $ make $./src/redis-server

redis-py The most popular python client library Andy McCurdy Github: easy_install redis OR pip install redis Optional: easy_install hiredis or pip install hiredis

Lets get started... $ cd redis $./src/redis-server >>> from redis import Redis >>> redis_client = Redis() >>> redis_client.keys() >>> help(redis_client)

Redis Keys Not binary safe. Should not contain space or newline character A few rules about keys: Too long keys are not a good idea Too short keys is also not a good idea “object-type:id:field” can be a nice idea, i.e. “user:1001:name”

Operations on Keys KEYS EXISTS DEL EXPIRE OBJECT PERSIST RANDOMKEY RENAME TYPE TTL EXPIREAT MOVE

Lets play with keys >>>redis_client.keys() >>>redis_client.exists('key') >>>redis_client.delete('key') >>>redis_client.type('key') >>>......

Data Structures Strings Lists Sets Sorted Sets Hashes

Strings SET GET MSET MGET SETEX INCR INCRBY DECR DECRBY

Strings – with redis client >>> redis_client.set('key', 'value') >>> redis_client.get('key') >>> redis_client.delete('key')

Fetch multiple keys at once mget/mset redis_client.mset({'key1': 'val1', 'key2': 'val2'}) redis_client.mget('key1', 'key2',......)

Expiration Set a value with expire >>>redis_client.setex('key', 'value', 2) #key to expire in 2 secs >>>redis_client.expire('key', 2) >>>redis_client.get('key') >>>None

Uses To store transient states in your web application

Uses Who is online?

Uses Redis as LRU cache ( as-LRU-cache.html)

Atomic Increments >>>help(redis_client.incr) >>>help(redis_client.decr) >>> >>> redis_client.incr('counter', 1) >>>1 >>> redis_client.incr('counter') >>>2 >>> redis_client.incr('counter') >>>3

Uses High Speed counters (views/clicks/votes/likes..)

Uses API Rate Limiting

Uses Generating unique IDs

Lists Ordered list of binarysafe strings Doubly linked list Memory footprint optimized for smaller list O(1) insertion/deletion at both ends

Lists - operations LPUSH RPUSH LSET LRANGE LPOP BLPOP BRPOP BRPOPLPUSH LINSERT RPOP RPOPLPUSH LPUSHX RPUSHX

Uses Web apps are full of lists :)

Uses Capped List

Uses Normal Queue Real time message Queue

Uses Social Activity Streams

Sets An unordered collection of distinct byte strings Nothing different from the data type in python

Sets - Operations SADD SCARD SDIFF SDIFFSTORE SINTER SINTERSTORE SISMEMBER SMEMBERS SMOVE SPOP SRANDMEMBER SREM SUNION SUNIONSTORE

Uses Picking random items from a set using SRANDMEMBER

Uses Primitive to construct filtering mechanism on items

Which of my friend's are online right now? Uses

Sorted Sets ZADD ZCARD ZCOUNT ZINCRBY ZINTERSTORE ZRANGE ZRANGEBYSCORE ZRANK ZREM ZREMRANGEBYRA NK ZREMRANGEBYSC ORE ZREVRANGE ZREVRANGEBYSCO RE ZSCORE ZUNIONSTORE

SORT SORT KEY SORT key BY pattern (e.g. object-type:*:age) SORT key LIMIT 0 10 SORT key GET user:*:username SORT key BY pattern STORE dstkey

Uses Generating sorted transient views

Publish/Subscribe A simple and efficient implementation of publish/subscribe messaging paradigm Client can subscribe/psubscribe to receive messages on channels (key patterns)

Publish/Subscribe PSUBSCRIBE PUBLISH PUNSUBSCRIBE SUBSCRIBE UNSUBSCRIBE

Uses Many to Many message passing

Uses Web Chat

Questions