Five Key Takeaways for Developing with Redis

    Modern applications have a general list of needs to not only survive, but thrive in today’s fast-paced cloud environments. These include low response times (less than 100 milliseconds), limitless scalability, high availability and optimal performance. Redis, an open source data structure server, has proven to be one of the most popular options with developers among a bevy of modern database options for speed and performance.

    Many of the leading use cases for using Redis are also the most demanding, including social applications and online advertising and gaming.

    According to Itamar Haber, chief developers advocate at Redis Labs, developing an application with Redis can be a lot of fun, but you should keep a few points in mind while designing a Redis-based application to get the most from the lightning-fast database. This slideshow features a list of the top five priorities a developer should pay attention to when using Redis.

    Five Key Takeaways for Developing with Redis - slide 1

    Top Five Redis Development Priorities

    Click through for five priorities developers need to keep in mind when using Redis, as identified by Itamar Haber, chief developers advocate at Redis Labs.

    Five Key Takeaways for Developing with Redis - slide 2

    Keep Track of Your Keys

    Databases store data, but any developer can lose track of some of the data they’re putting into Redis. This is only natural, due to an application’s requirements changing or to changes in the way a database may store data. Perhaps some of the keys have not been expired, or maybe a module of the application has been retired.

    Whatever the case, chances are that some of the data in a Redis database is no longer used and taking up space with no purpose. Redis’ schema-less nature makes it extremely difficult to make sense of a dataset’s contents without a solid nomenclature for keys. Using a proper naming methodology for your keys can make housekeeping of your database much easier.

    Five Key Takeaways for Developing with Redis - slide 3

    Keep Track of the Length of Your Key Names

    This might seem contradictory to the previous point, but since key names take up memory as well, strive to keep them short. Obviously, this becomes an issue with datasets consisting of millions or billions of keys, but the fact is long key names come with a price.

    Five Key Takeaways for Developing with Redis - slide 4

    Use the Right Data Structure

    Either because of memory usage or performance, sometimes one data structure is a better fit for your data set than another. Best practices to keep in mind include: grouping related data with the hash data structure; use lists instead of sets when applicable; consider using hashes versus sorted sets; and use bitmaps or bitsets to perform bit-level operations on Redis values, including storing large amounts of data efficiently and applying lightweight analytics.

    Five Key Takeaways for Developing with Redis - slide 5

    Use SCAN, Never Use KEYS

    The SCAN command enables you to retrieve keys in the keyspace using a cursor. Unlike the KEYS command, which returns all keys matching pattern, the SCAN command makes it possible to inspect your data without the risk of blocking your server or having to rely on a slave. The KEYS command should only be used in production environments and with extreme caution, as it can ruin performance.

    SCAN is accompanied by SSCAN, HSCAN and ZSCAN, which allow you to iterate the contents of sets, hashes and sorted sets.

    Five Key Takeaways for Developing with Redis - slide 6

    Use Server-Side Lua Scripts

    As a developer, you’ll be navigating familiar ground once you embrace Redis’ ability to run Lua scripts. One of the easiest languages to pick up, Lua offers you the ability to express your creativity with code that runs inside the Redis server itself. When applied correctly, Lua scripts can make a world of difference in terms of performance and resource consumption.

    Latest Articles