// In this approach, each polling operation is going to correspond to a unique key // in our Redis database. pollID = createUUID(); // Since we don't actually have any background processing in this demo, we're just // going to simulate some background job with a CFThread tag. The tag will sleep for // a bit and then "finalize" the job by pushing a value onto the Redis List. thread name = "simulatedBackgroundTask" pollID = pollID { // Simulated latency for our processing task. sleep( 8 * 1000 ); // We're going to denote task completion by pushing an item onto a list in Redis. // The long-polling operation will be monitoring this list, waiting for an item // to be poppable. application.redisGateway.withRedis( ( redis ) => { var list = "poll:#pollID#"; var listItem = { jobID: 4, status: "done" }; // CAUTION: While we are expecting a polling operation to POP this item // off the list, we cannot depend on that happening. As such, we want to // make sure that we use an ATOMIC TRANSACTION to both PUSH the list item // AND set the list to EXPIRE. This way, if the polling operation never // happens, this list-key will eventually expire and get expunged from // our Redis database. var multi = redis.multi(); multi.rpush( list, [ serializeJson( listItem ) ] ); multi.expire( list, 60 ); multi.exec(); } ); } // END: Thread. Using Redis Blocking List Operations To Power Long-Polling In Lucee CFML 5.3.7.47

Using Redis Blocking List Operations To Power Long-Polling In Lucee CFML 5.3.7.47

Our polling process will hit a ColdFusion end-point that uses Redis' blocking list operations to check on the status of a job.