Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Redis Basic Commands Tutorial

Introduction

Redis is an open-source, in-memory data structure store used as a database, cache, and message broker. It supports various data structures such as strings, hashes, lists, sets, and more. In this tutorial, we will cover some of the basic commands to help you get started with Redis.

Connecting to Redis

To start using Redis, you need to connect to your Redis server. You can do this using the Redis CLI (Command Line Interface). Here's how you do it:

redis-cli

127.0.0.1:6379>

Now that you're connected, you can start executing Redis commands.

Basic Commands

SET and GET

The SET command is used to set a value to a key. The GET command retrieves the value of a key.

SET mykey "Hello, Redis!"

OK

GET mykey

"Hello, Redis!"

DEL

The DEL command is used to delete a key.

DEL mykey

(integer) 1

EXISTS

The EXISTS command checks if a key exists.

EXISTS mykey

(integer) 0

INCR and DECR

The INCR command increments the integer value of a key by one. The DECR command decrements the integer value of a key by one.

SET counter 10

OK

INCR counter

(integer) 11

DECR counter

(integer) 10

Conclusion

In this tutorial, we covered some basic Redis commands including SET, GET, DEL, EXISTS, INCR, and DECR. These commands form the foundation of working with Redis. As you become more familiar with Redis, you'll discover many more features and commands that can help you build robust and efficient applications.