How to use basic Redis commands?

Category: Ruby :: Published at: 30.01.2023

Redis is quite easy to use, it's just basic key->value database which can be used in many different cases.

Let's assume, we already have Redis server setup in our application, and only need to use it.

Three most basic things we can do with Redis is:

  • setting up a new key
redis = Redis.new(url: REDIS_URL)
redis.set("lock_car_object_#{car.id}", 1)
  • getting the value from existing key
redis = Redis.new(url: REDIS_URL)
redis.get("lock_car_object_#{car.id}")
=> 1
  • removing an existing key
redis = Redis.new(url: REDIS_URL)
redis.del("lock_car_object_#{car.id}")

- Click if you liked this article

Views: 1007