- Using Redis on Mac OS
- Using Redis Stack
To install Redis Stack on mac OS, use Homebrew. Make sure that you have Homebrew installed before starting on the installation instructions below.
Follow the instructions below to setup Redis Stack on your Mac OS:
Step 1. Install Redis Stack using Homebrew
First, tap the Redis Stack Homebrew tap and then run
brew install as shown below:
brew tap redis-stack/redis-stack
brew install --cask redis-stack
This will install all Redis and Redis Stack binaries. How you run these binaries depends on whether you already have Redis installed on your system.
==> Installing Cask redis-stack-redisinsight
==> Moving App 'RedisInsight-preview.app' to '/Applications/RedisInsight-preview.app'
🍺 redis-stack-redisinsight was successfully installed!
==> Installing Cask redis-stack
🍺 redis-stack was successfully installed!
If this is the first time you’ve installed Redis on your system, then all Redis Stack binaries will be installed and accessible from the
$PATH. On M1 Macs, this assumes that
/opt/homebrew/bin is in your path. On Intel-based Macs,
/usr/local/bin should be in your path.
To check this, run:
Then, confirm that the output contains
/opt/homebrew/bin (M1 Mac) or
/usr/local/bin (Intel Mac). If these directories are not in the output, see the “Existing Redis installation” instructions below.
Start Redis Stack Server
You can now start Redis Stack Server as follows:
Existing Redis installation
If you have an existing Redis installation on your system, then you’ll need to modify your
PATH environment variable to ensure that you’re using the latest Redis Stack binaries.
Open the file
~/zshrc (depending on your shell), and add the following line.
Go to Applications and click "RedisInsight Preview" to bring up the Redis Desktop GUI tool.
Step 2. Add Redis database
Step 3. Enter Redis database details
Add the local Redis database endpoint and port.
Step 5. Redis for time series
Redis Stack provides you with a native time series data structure. Let's see how a time series might be useful in our bike shop.
As we have multiple physical shops too, alongside our online shop, it could be helpful to have an overview of the sales volume. We will create one time series per shop tracking the total amount of all sales. In addition, we will mark the time series with the appropriate region label, east or west. This kind of representation will allow us to easily query bike sales performance per certain time periods, per shop, per region or across all shops.
Click "Guides" icon (just below the key) in the left sidebar and choose "Redis for the time series" for this demonstration.
Step 6. Create time series per shop
TS.CREATE bike_sales_1 DUPLICATE_POLICY SUM LABELS region east compacted no
TS.CREATE bike_sales_2 DUPLICATE_POLICY SUM LABELS region east compacted no
TS.CREATE bike_sales_3 DUPLICATE_POLICY SUM LABELS region west compacted no
TS.CREATE bike_sales_4 DUPLICATE_POLICY SUM LABELS region west compacted no
TS.CREATE bike_sales_5 DUPLICATE_POLICY SUM LABELS region west compacted no
As shown in the following query, we make the shop id (1,2,3,4,5) a part of the time series name. You might also notice the
DUPLICATE_POLICY SUM argument; this describes what should be done when two events in the same time series share the same timestamp: In this case, it would mean that two sales happened at exactly the same time, so the resulting value should be a sum of the two sales amounts.
Since the metrics are collected with a millisecond timestamp, we can compact our time series into sales per hour:
Step 7. Running the query
Step 8. Time series compaction
RedisTimeSeries supports downsampling with the following aggregations: avg, sum, min, max, range, count, first and last. If you want to keep all of your raw data points indefinitely, your data set grows linearly over time. However, if your use case allows you to have less fine-grained data further back in time, downsampling can be applied. This allows you to keep fewer historical data points by aggregating raw data for a given time window using a given aggregation function.
TS.CREATERULE bike_sales_5 bike_sales_5_per_day AGGREGATION sum 86400000
There are two ways to install Redis on Mac OS:
- Installing Redis from source
- Using Homebrew
Homebrew is the easiest and most flexible way to install Redis on Mac OS. It is a package management software for Mac OS. It automates the Redis installation process, making it quick and easy to add Redis to your system.
Follow the below steps to install Redis on Mac OS using
Step 1: Install Homebrew
Run the following command to install and start brew service:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Step 2: Install Redis using Homebrew package manager
Use the following commands to install Redis using brew service:
brew install redis
Step 3: Start Redis server
Run the following command to start the Redis database in the background:
brew services start redis
In order to run the latest version of Redis, you will need to compile Redis from the source. Follow this link to learn more about it.
Step 4: Test if Redis server is running.
It should return PONG. This command is often used to test if a connection is still alive.
Step 5: Launch Redis on system boot
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
Start Redis server via “launchctl” command
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
Step 6: Run Redis service using a Redis configuration file
Step 7: Interacting with Redis Client
redis> set foo bar
redis> get foo
Step 8: Stop the Redis service
brew services stop redis
Step 9: Uninstall Redis
brew uninstall redis