Using Redis
Redis is a well-known, popular open-source caching software, built for simplicity and efficiency (the simplicity part is especially important here, and defines a lot of how Redis can be used).
A basic overview
Redis functions as a key-value store: its primary purpose is to hold data in this format, where you store a value with some key, and use the key to retrieve the value later. There are only really a few "data structures" in Redis: data is always represented as a string. There are no numbers or other formats here!
While Redis has 5 data types (Strings, Hashes, Sets, Lists and Sorted Sets), we will focus on Strings and Hashes here.
Strings
Every key you store in Redis is a string. Every value is a string. You cannot, for example, store an object in Redis unless it's been put into string form first (Redis is binary safe, but it's still important to note the data type).
As a result, and due to the limitations and best uses of caching, you generally want to use Redis to store data that is small in size but e.g. took a long time to compute. When caching database results, you can store the results as a JSON-encoded string, and then decode it later.
Be aware of the string nature of keys and values when storing things you treat as integers or other data types in Redis. It's fine to do so - but make sure you are casting the value when getting back from Redis, as it will not return it to you as an integer or whatever other type your original value was intended to be.
Hashes
Hashes are a kind of collection of key-value pairs. You set a key that is the "hash", and then that hash can contain multiple fields, which are essentially normal key-value pairs bound to that hash. This is useful when you need to store many keys that are closely related to each other, like different pages of search results: it's a lot better than storing individual keys, for reasons explained later.
Redis commands
Basic use of Redis commands isn't going to be covered here, but there are a few important things to note.
EXPIRE
Normally, key-value pairs in Redis live forever (or more precisely, until you delete them or the server shuts down). The EXPIRE command tells Redis to delete a key after a given period of time.
Be aware that in the case of hashes, you cannot expire an individual field of the hash. You can only set an expiry on the hash itself, and when it expires, all its fields are deleted as well.
Also note that the EXPIRE command resets the expiry of any key you use it on; there are options such as NX to specify that you only want to set an expire time for a key if it has no current expiry time, for instance.
Possible pitfalls
Redis Library versions
Be aware of the version of Redis your library supports. For the language you are using, you are likely to be using some form of redis client that interacts with the Redis server (i.e. you are not directly querying the Redis server - the client does so for you).
Some libraries are a little old in which Redis commands they support; for example, the phpredis library for interacting with Redis via PHP doesn't support the optional commands to EXPIRE. As a result, instead of using something like EXPIRE mykey 900 NX, you have to instead perform a separate TTL command to check if there's an existing expiry on the key, then use EXPIRE depending on the result.