Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

DATA SHEET

Getting Started with Redis Streams


Redis Streams is a simple, and yet powerful data structure for managing Sample Use Cases:
data streams. The data structure is built into Redis, the world’s most
popular in-memory database that delivers millions of operations per second
at sub-millisecond latency with the fewest resources. Redis Streams
creates a data channel that connects producers and a variety of consumers
with different data needs.

Streams data structure offers:


• A rich choice of options to consumers to read streaming data and data
at rest
Messaging: Connect producer and one or more similar consumers
• Consumer groups to help the consumers to coordinate among
themselves while reading the data from the same stream

• Super-fast lookup queries powered by radix trees


• Automatic eviction of data based on the upper limit

Benefits:
• Collect large volumes of data arriving in high velocity (in the order of
millions per second)
Microservices: Multiple microservices consuming the same data for
different purposes
• Communicate between producers and consumers asynchronously
• Effectively manage consumption of data even when producers and
consumers don’t operate at the same rate

• Persist data when your consumers are offline or disconnected


• Scale-out the number of consumers

• Implement transaction-like data safety when consumers fail in the midst


of consuming data

Image Processing: Scaling out consumers to catch up with the production


Redis Enterprise Advantages
rate

HA, Durability, DR
Tunable features for replication and persistence to maintain high
performance when persisting data to disk; Rack-aware, cross-datacenter/
region/cloud in-memory replication with unique WAN compression
technology.

Robust Security
SSL-based encrypted communication with clients, administrators and
across clusters; certificate and password-based authentication; role-based
authorization for administration.

Redis on Flash
Supports Flash memory as a RAM extender; ideal for large dataset sizes;
uses tiered memory access to deliver the same sub-millisecond latencies as
RAM while reducing costs by 70% or more.

Automation and Support


24x7 enterprise-grade support backed by expertise in managing and
scaling 550K+ Redis databases for thousands of customers in production Artificial Intelligence: Many producers and consumers with varied data
worldwide. needs
Quick Reference Guide
Adding data to a stream Consuming data from the stream
1. THE DEFAULT METHOD FOR ADDING DATA 1. READ EVERYTHING FROM THE BEGINNING OF THE STREAM
XADD [stream name] * [key] [data] Situation: The stream already has the data you need to process, and you want
Example: to process it all from the beginning.
XADD mystream * name Anna XREAD COUNT [n] STREAMS [stream name] 0
Example:
2. ADDING DATA WITH USER-MANAGED IDS FOR EACH ENTRY XREAD COUNT 100 STREAMS mystream 0
XADD [stream name] [id] [key] [data]
2. READ EVERYTHING FROM A POINT IN THE STREAM
Example:
XADD mystream 10000000 name Anna Situation: The stream already has the data you need to process, and you
want to process it all from a point.
3. ADDING DATA WITH A MAXIMUM LIMIT XREAD COUNT [n] STREAMS [stream name] [id]
XADD [stream name] MAXLEN [length] * [key] [data] Example:
Example: XREAD COUNT 100 STREAMS mystream 1518951481323-1
XADD mystream MAXLEN 1000000 * name Anna
3. CONSUME DATA ASYNCHRONOUSLY (VIA A BLOCKING CALL)
4. ADDING DATA WITH AN APPROXIMATE MAXIMUM LIMIT Situation: Your consumer consumes and processes data faster than the rate at
XADD [stream name] MAXLEN [length] * [key] [data] which it is added to the stream.
Example: XREAD BLOCK [milliseconds or 0] STREAMS [stream name]
XADD mystream MAXLEN ~ 1000000 * name Anna [last id + 1]
Example:
XREAD BLOCK 60000 STREAMS mystream 1518951123456-1
Consuming data from the stream via consumer groups
This blocks the call indefinitely:
1. CREATE A CONSUMER GROUP XREAD BLOCK 0 STREAMS mystream 1518951123456-1
XGROUP CREATE [stream name] [group name] $ [MKSTREAM]
MKSTREAM is optional. It creates the stream if it doesn’t already exist. 4. READ ONLY NEW DATA AS IT ARRIVES
Example: Situation: You are interested in processing only the new set of data starting
XGROUP CREATE mystream mygroup $ MKSTREAM from this point in time.
XREAD BLOCK [milliseconds or 0] STREAMS [stream name] $
2. READ FROM A CONSUMER GROUP Example:
XREADGROUP GROUP [group name] COUNT [n] [consumer name] XREAD BLOCK 60000 STREAMS mystream $
STREAMS [stream name] >
The special character “>” at the end tells Redis Stream to fetch only data 5. ITERATE THE STREAM TO READ PAST DATA
entries that are not delivered to any other consumers. Situation: Your data stream already has enough data, and you want to query it
Example: to analyze data collected so far.
XREADGROUP GROUP mygroup COUNT 2 Alice STREAMS mystream XRANGE [stream name] [start id] [end id]
> Example:
XRANGE mystream 1518951123450-0 1518951123460-0
3. ACKNOWLEDGE AFTER READING With count:
XACK [stream name] [group name] [id] XRANGE mystream 1518951123450-0 1518951123460-0 COUNT
Example: 10
XACK mystream mygroup 1526569411111-0 With no lower or upper bound:
XRANGE mystream - + COUNT 10
4. FIND THE MESSAGES IN THE PENDING LIST – CONSUMED BUT NOT Reverse of XRANGE is XREVRANGE
ACKNOWLEDGE Example:
XPENDING [stream name] [group name] - + [count] XRANGE mystream + - COUNT 10
[consumer name]
Example:
XPENDING mystream mygroup - + 10 Bob

5. CLAIM PENDING MESSAGES FROM ANOTHER CONSUMER


XCLAIM [stream name] [group name] [consumer name] [min
Get Started with Redis Streams
pending time] [id] on Redis Cloud for Free Today!
Example:
Visit https://redislabs.com/get-started/
XCLAIM mystream mygroup Alice 0 1526569411113-0
Talk to a expert today. Contact [email protected].

Redis-Streams-v2

700 E El Camino Real Suite 250, Mountain View, CA 94040 | (415) 930 9666 | redislabs.com

You might also like