Introduction to Redis
Redis is an open source (BSD licensed), in-memory data structure store used as a database, cache, message broker, and streaming engine. Redis provides data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes, and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions, and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.
How Sentry uses Redis
With version 9.1.222, Sentry has introduced support for Redis distributed caching. Redis is a powerful distributed caching engine that provides key-value pair caching with very low latency. Redis can significantly improve application performance when used in the correct business context. Caching works better when the data changes infrequently, i.e., when the cached data doesn't change often.
How Does Redis Work
First, Forum Sentry attempts to read data from the cache. If the requested data is unavailable in the cache, the application obtains it from the actual data source. The data is then returned and cached for future requests for the same piece of data. All subsequent requests for the same piece of data are served from the cache instead of the actual data source. Because data usually resides in memory, this enhances Sentry's performance and scalability. If the database is unavailable, requests for the data are served from the cache, thus enhancing Sentry's availability.
Setting up Redis Policies in Sentry
The first thing you are going to do is setup a Redis server within your own network. For more detailed instructions on how to setup Redis, please refer to the product documentation from the Redis website: https://redis.io/docs/getting-started/.
Step 1: Build your Redis Policy within Forum
Once you have your Redis device setup, note the IP address and the Port number that the device is listening on. This will be used in the setup of the Forum Policy.
Next login to your Forum device and navigate to the Gateway tab within the left menu. From there, locate the “Redis Policies” link and click on it.
Here you will setup the connection between the Redis device that you have on your network and the Forum Sentry.
Step 2: Setting up Forum to Read Redis Policy
Once you have your Redis Policy built you will need to locate the “Cache Policies” link in the left hand navigation menu and click on it. This will allow Forum to utilize the Redis Policy created above.
You will first need to create a new “Response Cache Policy” for Sentry to use to read from the Redis Policy created above. For this we will create a new policy named “RedisCacheTest”.
From the image above ensure that your parameters are setup as indicated and pay particular attention to the 2 parameters at the bottom of the screen. These are the ones that will be used specifically for Redis.
There are 2 parameters that you need to ensure are setup on this page in order to use Redis:
1: Check the “Use Redis” checkbox
2: Select the “Redis Policy” that was created in the previous step from the dropdown menu
Step 3: Assigning Redis Cache Policy to a Sentry Content Policy
The new Redis feature in Forum Sentry is a Content Policy Specific feature, meaning that the Redis Cache Policy has to be assigned to individual Content Policies rather than at the System Level. With this in mind, we will now assign our newly created “RedisCacheTest” Policy to an existing XML Policy.
First you will navigate to your Content Policies section located on the left had menu under the “Gateway” tab. From there select the “XML Polices” and select any existing XML Policy or create a new one.
With the policy pulled up on the screen, locate the “Settings” tab of the policy.
Under the Settings tab, at the bottom of the page, just above the “Google Analytics” section, locate the “Enable Response Caching” checkbox and select it. Once the checkbox is selected you will be able to select the Response Cache Policy that was created in Step 2.
Additional Information:
Redis also provides a command-line interface called redis-cli. Below are some commands that can be utilized within that CLI for quick reference. Please note this is not intended to be a complete list of all redis-cli commands.
- redis-cli –h <host> -p <port>
- Useful commands:
- auth <password> (if authentication is configured)
- monitor (shows active usage of the calls to Redis)
- keys * (shows a list of all keys in the cache)
- hget <key> <field> (the value associated with field in the hash stored at key)
- del <key> (manually remove a cache key)
0 Comments