Continuing on with our Redis for .NET Developer, the Redis String Datatype is also used to store integers, float and other utility commands to manipulate strings.

Redis String Datatype using Integers

In Redis float and integers are represented by string. Redis parses the string value as an integer and the neat thing about them is when you do operations on strings they are atomic. When there are multiple clients issuing INCR against the same key, it will never enter into a race condition.

  • INCR key : Increment the value by one O(1)
  • INCRBY key value: Increments the value by the given value (integer) O(1)
  • DECR key: Decrements the value by one O(1)
  • DECRBY key value: Decrements the value by the given value (integer) O(1)
  • APPEND key value: Concatenate the existing integer with the new integer O(1)
  • INCRBYFLOAT key value : Increment the float value by given value (float) O(1)

C# Code using integer and float

For source code please visit
https://github.com/taswar/RedisForNetDevelopers/tree/master/3.RedisStringsAsInt

For our next blog post, I will cover more functionality and other datatype in Redis.

For previous Redis topics

  1. Intro to Redis for .NET Developers
  2. Redis for .NET Developer – Connecting with C#
  3. Redis for .NET Developer – String Datatype