March 4, 2022
Trying out Redis for ColdFusion caching
March 4, 2022
Trying out Redis for ColdFusion caching
ColdFusion developer for 20+ years, professional experience in 10 other languages & frameworks. Artist, nerd, Jeep enthusiast.
Newbie 35 posts
Followers: 26 people

I had a customer reach out to me last week about moving their session storage to Redis, so I decided to play around a bit with it. I’d never really had the need to utilize Redis or any of the other caches, as the companies I’d worked with used the local CF cache or other solutions. So I saw this as an opportunity to play and learn.

To start, it is dead simple to get yourself a Redis instance going. You can get a free forever account from Redis themselves, hosted in AWS at https:/ Sign up with the provider of your choice, then choose the free plan. Free plans are available from AWS, Azure and Google. I chose the AWS 30mb plan, then created a new Redis database (in US-East-1). Once you spin up your database, you’ll easily be able to see the plan usage, memory, etc. You an also, of course, download Redis and install it locally.

NOTE: There is a small chance that some of the changes you’ll be making could create a situation where CF Admin loses the ability to read session variables. To make it significantly easier to recover from this possibility, make a copy of your neo-runtime.xml file located in C:\#COLDFUSION-INSTALL-DIRECTORY#\cfusion\lib. If you find that your server has decided to not function, just go ahead and copy back that file and restart the server, and all will be well.

In your ColdFusion Administrator, go ahead and go to the package manager and add redissessionstorage to your installed packages, as well as caching (if you don’t already have them installed). We’re going to set up Redis a couple ways.

First, go to the Caching tab under server settings and enter the info for Redis Cache Settings and verify them. You’ll be putting in the server, port and password. Once verified, hit submit changes. Remember that you can specify caching engines in administrator or at the application level in code. We’ll be doing it globally at the server level in administrator.

Now go to Memory Variables under server settings and turn off J2EE session variables. Set the Session Storage Settings to use Redis (you can check “reuse redis caching server” to use the settings you set up under caching). I also set “use redis for CFLogin” but not SSL. Verify it works, then hit submit.

You’ll need to restart your CF Server, so do so. And that’s it! You’re now using Redis as your user session caching server.

To see what the current caching engine is set to, you can create a test page with the following code:

WriteDump(CacheGetEngineProperties()); // Returns the properties of the cache engine
WriteOutput("The caching engine currently used is: " & CacheGetEngineProperties().name); // Returns the name of the cache engine

For more cache related tags such as CachePut() and CacheGet() check out the Cache Functions Page.

For more info on using Redis and other caching engines, check out our docs. Happy caching!


1 Comment
2022-03-05 01:39:59
2022-03-05 01:39:59

Thanks for sharing your experience, Mark. It seems worth clarifying for folks:

  • The use of redis or other external caching engines (new since CF2018) is supported only by CF Enterprise, Developer, or Trial. For CF Standard, only the internal ehcache or jcscache is supported.
  • Fortunately there’s no such edition difference for the use of Redis for session storage. It’s supported by Standard and enterprise, since it came out with cf2016. 
  • As such, note that you don’t NEED to use Redis for caching in order to use Redis for session storage. They’re unrelated. Mark was just showing you CAN enable both, and how the config of settings of the one can be used to configure the other. 
  • But folks shouldn’t miss that the storage of sessions in Redis does REQUIRE that you disable j2ee sessions, as Mark noted. It can be as secure as j2ee sessions, via config options at the bottom of the memory variables page. 


Hope all that’s helpful to readers.

Add Comment