Category: redis
-
Setting Up a Maven Project for a Redis Playground
In this tutorial, we will set up a Maven-based Java project to experiment with Redis using Redisson or similar libraries. This project will serve as a playground for testing Redis operations, reactive programming, and distributed data structures. 1. Prerequisites Before starting, ensure you have the following installed: 2. Creating the Maven Project 3. Configuring the…
-
Redisson: A Comprehensive Tutorial
Redisson is a high-level Java client library for Redis that provides distributed data structures and services on top of Redis. Unlike basic Redis clients, Redisson offers Java-like abstractions such as maps, sets, lists, locks, and more, making it easier to integrate Redis into scalable, distributed Java applications. 1. Introduction to Redis Java Libraries There are…
-
Redis Persistence: Saving and Restoring Data
Redis is an in-memory database, which means all data resides in RAM for fast access. However, memory is volatile, so if Redis is restarted, all data is lost unless it is persisted to disk. Redis provides mechanisms to save the current state and restore it later, ensuring that your application can continue from a known…
-
Redis Single-Threaded Execution and Transactions with Multi-Terminal Simulation
Redis is single-threaded for command execution, which provides atomicity at the command level. However, when multiple commands are executed together, or when multiple clients perform operations simultaneously, race conditions may occur. Redis provides transactions and the WATCH command to handle these cases safely. 1. Single-Threaded Execution in Redis Example Without Transactions Two keys in Redis:…
-
Redis Sorted Sets (ZSet)
Redis Sorted Sets (ZSet) are an extension of regular sets, where each unique item has an associated score. This allows the set to be automatically ordered by score, making it extremely useful for ranking, leaderboards, and priority queues. Key Features of ZSet Common Use Cases Basic Commands 1. Adding Items (ZADD) 2. Checking Set Size…
-
Redis Set Operations: Intersection, Union, and Difference
Redis sets are unordered collections of unique elements. One of the powerful features of sets is the ability to perform set operations such as intersection, union, and difference, which can be useful for real-world scenarios like filtering candidates based on skills. Example Scenario Imagine an application similar to LinkedIn or Dice: We can model the…
-
Redis Sets
Redis sets are unordered collections of unique items. They are similar to Java Sets. Sets are useful when you need to: Why Use Sets Instead of Lists? While a list can store multiple items, a set has some advantages: Starting with Redis Sets Step 1: Clear the Database This ensures no old data interferes with…
-
Using Redis Lists as a Stack
In the previous lecture, we saw how Redis lists can be used like queues (FIFO). In this lecture, we will explore how to use Redis lists as a stack, which is last in, first out (LIFO). Stack Concept Recap A stack follows the principle: Redis lists can easily behave like a stack using the left…
-
Working with Lists in Redis
In this lecture, we will explore Redis Lists, which are ordered collections of strings. Lists in Redis can be used in many ways, including as queues, stacks, or simply as an ordered collection of elements. What is a Redis List? A Redis list is: Creating a List Redis automatically creates a list if it doesn’t…
-
Working with Hashes in Redis
So far, we have been exploring how to store simple key-value pairs in Redis. This works well for individual values, but real-world applications often require storing groups of fields that belong to a single object. For example, a user object might have multiple attributes like name, age, city, etc. Redis provides hashes to handle such…
