Redis

What?

Open source in memory data structure store which can be used as a database and cache store.

Why?

Advantages of Redis

  • Flexible and no schema & column (NoSQL)
  • Performance (about 110, 000 SETs per second, about 81, 000 GETs per second)
  • Rich datatype support
  • Cache & Disk persistence

What Redis is not good at..

  • Data encryption is not supported

What is usage?

  • Real time analytics
  • High speed data ingest
  • Session storage
  • Application job manage
  • Message queus
  • Geo search
  • Cache!

Data Types

String
Lists
Sets
Stored Sets
Hashes
Bitmaps
Hyperlogs
Geospatial indices

GET (node.js)

client.get("missingkey", function(err, reply) {
    // reply is null when the key is missing
    console.log(reply);
});

SET (node.js)

client.set('key', 'value!', 'EX', 10);

INCR

INCR foo // 100
101

DECR

DECR foo // 100
99

EXISTS

EXISTS foo 
// 1 if it is set

DEL

DEL foo
// => 1
EXISTS foo 
// 0

FLUSHALL

FLUSHALL
0

EXPIRE

EXPIRE foo 50
// 1

TTL

TTL foo

SETEX

SETEX foo 50 "hello"

PERSIST

Make key persist

PERSIST foo
TTL foo
// -1

MSET

Set more than 1 pairs.

MSET foo "hello" bar "world"

APPEND

Append value to the value corresponding to key.

APPEND foo " world"

GET foo "hello world"

RENAME

RENAME foo foo1

List Commands

LPUSH

LPUSH people "John"
LPUSH people "Tom"

LRANGE

LRANGE allows you to pull data on the range of 0 to -1 (-1 is last index)

LRANGE people 0 -1
1) John
2) Tom

LLEN

LLEN gives length of key

LLEN people

LPOP

LPOP pops element.

LPOP people
// "Tom"

LINSERT

Insert value to key

LINSERT people BEFORE "Brad" "Jen"

Options

EX seconds -- Set the specified expire time, in seconds.

PX milliseconds -- Set the specified expire time, in milliseconds.

NX -- Only set the key if it does not already exist.

XX -- Only set the key if it already exist.

Why Redis?

Using Redis as an LRU cache

Dave Nielsen: Top 5 uses of Redis as a Database

Scaling Redis at Twitter

Redis Crash Course Tutorial

Build A Node.js & Redis App From Scratch

Memecache

https://www.youtube.com/watch?v=-h9q2FmX4eo

https://www.youtube.com/watch?v=7MLXuG83Fsw

Redis vs Memcache

Redis vs Memcached

Memcached vs. Redis?

Cache

https://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/Strategies.html

https://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/UseCases.html#UseCases.DataStore.WhatToCache

results matching ""

    No results matching ""