Working with Numbers

Welcome back to our Redis course! Now that you know how to connect to a Redis server, it's time to move forward and explore how to work with numbers in Redis. This unit builds on our previous lesson, so make sure you're comfortable with establishing a connection to a Redis server.

What You'll Learn

In this lesson, you will learn how to:

  1. Set numeric values in Redis using C#.
  2. Retrieve and process numeric values in C#, handling the relevant data types.
Example: Setting and Getting Numbers

Here's the code snippet that we'll be working with:

Let's break down the code:

  • As in the previous lesson, we first establish a connection to the Redis server using the ConnectionMultiplexer class from the StackExchange.Redis library.
  • We use the StringSet method to store the numeric values: count with a value of 5 and completion_rate with a value of 95.5.
  • We retrieve these values using the StringGet method. Unlike some weaker type systems, in C#, you can cast directly to the appropriate numeric types, such as int and double, after fetching them, as needed.
Why It Matters

Working with numbers in Redis is crucial because many real-world applications involve numeric data. From tracking user statistics to monitoring system performance, managing numbers in Redis allows you to perform a variety of useful operations efficiently. By mastering these basic operations with numbers, you'll be well-prepared to tackle more complex tasks and optimize your applications.

Ready to dive in? Let's move on to the practice section and get hands-on experience working with numbers in Redis!

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal