Where to Go From Here?
In this tutorial, you learned how to run Redis in Docker with your Vapor app. You also saw how to cache and retrieve an encodable object and how to expire a key.
This was only a small part of what Redis can do. Here are some suggestions for other ways to use Redis:
You’ll notice that the value returned is greater. In a Vapor app, the command looks a little different: req.redis.increment(RedisKey("pageCount"))
.
SET pageCount 0
INCR pageCount
GET pageCount
Using these commands lets you easily add buttons for upvotes and downvotes to the dog pages, for example.
You can find the complete documentation for INCR
and its counterpart, DECR
, at the Redis documentation site.
You can download the completed project files by clicking the Download Materials button at the top or bottom of this tutorial.
The Vapor Redis library is built on RediStack. A full list of the commands available to your Vapor app can be found at the RediStack documentation site.
It’s also helpful to look at the redis and RediStack header files. Sometimes there’s extra documentation or a slight wording change between the actual Redis command and how it’s implemented for Vapor. INCR
is one example of that.
If you have any questions or comments, please join the forum discussion below.