XRANGE command is used to query a range of messages from a stream by specifying the minimum and maximum IDs. In PHP, you might use this when you want to fetch historical data from a stream for processing or analysis. It's also useful when you’re building an application that needs to process stream data in batches.
This script will connect to your local Redis server, then retrieve and print up to 100 messages from
mystream. Note that
"+" are special ID values representing the smallest and largest IDs respectively.
In this example, only messages with IDs between
1637625832060-0 will be retrieved.
XRANGErequest to prevent blocking your PHP application. Use pagination by specifying the maximum number of items to retrieve using the
Q: How to handle large streams with XRANGE in PHP?
A: For large streams, you can use the
$count parameter to limit the number of entries returned by XRANGE. You can then increment the
$minId based on the last ID returned and repeat the process until all desired data has been fetched.