Top Banner
By: Vishal Sahu
21

Introduction to redis

Apr 14, 2017

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to redis

By: Vishal Sahu

Page 2: Introduction to redis

AgendaWhat is Redis?

History

Installation

Sample commands

Redis with Grails

Demo

Case Studies

References

Page 3: Introduction to redis

What is Redis?Redis means REmote DIrectory Server. Redis is an advanced key-value NoSQL data store.

It is similar to memcached except the dataset is not volatile. Like memcached, Redis can store string values, but it can also store lists, sets, and ordered sets.

All these data types can be manipulated with atomic operations that push, pop, add and remove elements, perform server side union, intersection, difference between sets, and more.

Redis also supports different kinds of sorting.

Page 4: Introduction to redis

HistoryEarly 2009 - Salvatore Sanfilippo, an Italian developer, started the Redis project

He was working on a real-time web analytics solution and found that MySQL could not provide the necessary performance.

June 2009 - Redis was deployed in production for the LLOOGG real-time web analytics website

March 2010 - VMWare hired Sanfilippo to work full-time on Redis (remains BSD licensed)

Subsequently, VMWare hired Pieter Noordhuis, a major Redis contributor, to assist on the project.

Page 5: Introduction to redis

Who’s using Redis?Twitter

GitHub

Weibo

Pinterest

Snapchat

Craigslist

Digg

StackOverflow

Flickr

Kickstarter

Flickr

Airbnb

Shopify

Page 6: Introduction to redis

Installationsudo add-apt-repository ppa:chris-lea/redis-server

sudo apt-get update

sudo apt-get install redis-server

Start/Stop:sudo service redis-server start

sudo service redis-server stop

redis-benchmark

Page 7: Introduction to redis

Sample CommandsCommand Line : redis-cli

SET users:GeorgeWashington "job: President, born:1732, dislikes: cherry trees"GET users:GeorgeWashington

> SET population 6OK> INCRBY population 10(integer) 16> INCR population(integer) 17

Page 8: Introduction to redis

Data Model

Page 9: Introduction to redis

Redis with GrailsPlugin: https://grails.org/plugin/redis

The Redis plugin provides integration with a Redis datastore.

This plugin gives grails apps a pooled connection to a Redis instance and provides a number

of helper methods and caching/memoization methods that can greatly speed up your

application performance.

Page 10: Introduction to redis

Redis with Grailsdef redisServiceThe redisService bean wraps the pool connection. It has a number of caching/memoization helper functions, template methods, and basic Redis commands, it will be your primary interface to Redis.redisService.foo = "bar"assert "bar" == redisService.foo

redisService.sadd("months", "february")assert true == redisService.sismember("months", "february")

Page 11: Introduction to redis

Demo

Page 12: Introduction to redis

MemoizationMemoization is a write-through caching technique. The plugin gives a number of methods that take a key

name, and a closure as parameters. These methods first check Redis to see if the key exists. If it does, it

returns the value of the key and does not execute the closure. If it does not exist in Redis, it executes the

closure and saves the result in Redis under the key. Subsequent calls will then be served the cached value

from Redis rather than recalculating.

This technique is very useful for caching values that are frequently requested but expensive to calculate.

Page 13: Introduction to redis

Demo

Page 14: Introduction to redis

Redis TaglibThe redis:memoize TagLib lets you leverage memoization within your GSP files. Wrap it

around any expensive to generate text and it will cache it and quickly serve it from Redis.

<redis:memoize key="mykey" expire="3600"> <!-- insert expensive to generate GSP content here

taglib body will be executed once, subsequent calls will pull from redis till the key expires --> <div id='header'> ... expensive header stuff here that can be cached ... </div></redis:memoize>

Page 15: Introduction to redis

Demo

Page 16: Introduction to redis

Redis Session PluginStores HTTP sessions in a Redis data store.

This plugin lets you store HTTP session data in a redis store using

Database Session Plugin.

https://grails.org/plugin/redis-database-session

Page 17: Introduction to redis

Redis Persistence#Snapshotting (RDB) : Snapshots at predefined intervals, which may also depend on the number of changes. Any changes between these intervals will be lost at a power failure or crash.

# Append-Only files (AOF): Writing a kind of change log at every data change. You can fine-tune how often this is physically written to the disk, but if you chose to always write immediately (which will cost you some performance), then there will be no data loss caused by the in-memory nature of Redis

Page 18: Introduction to redis

Redis @ TwitterRedis on Twitter supports over 30 billion timeline updates per day based on 5000 tweets per second or 400,000,000 tweets per day. There is no doubt, Twitter’s infrastructure deals with extremely high scale demands. So, next time you get a Tweet from Katy Perry, remember 39 million inserts just occurred on Redis.

While there might be 5000 tweets per second on average and peaks up to 12,000, views are actually what keeps the datastore busy. There are over 300,000 queries per second on home timelines and 30,000 on search-based timelines.

Page 19: Introduction to redis

Redis @ PinterestThings which Redis stores for a Pinterest Profile.

A list of users who you followA list of boards (and their related users) who you followA list of your followersA list of people who follow your boardsA list of boards you followA list of boards you unfollowed after following a userThe followers and unfollowers of each board

Redis stores the above lists for each of it’s 70 million users—it basically stores the entire follower graph.

Page 20: Introduction to redis

Referenceshttps://grails.org/plugin/redis

https://github.com/grails-plugins/grails-redis

http://techstacks.io/tech/redis

http://www.slideshare.net/tednaleid/redis-and-groovy-and-grails-gr8conf-2011

https://cs.brown.edu/courses/cs227/archives/2011/slides/mar07-redis.pdf

http://stackoverflow.com/questions/10558465/memcached-vs-redis

http://blog.andolasoft.com/2014/02/memcached-vs-redis-which-one-to-pick-for-large-web-app.html

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-redis

Page 21: Introduction to redis

Thanks :)

Questions?Shoot them at [email protected]