Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте String | Data Types in Redis
Introduction to Redis
course content

Зміст курсу

Introduction to Redis

Introduction to Redis

1. Redis Fundamentals
2. The Essential Redis Commands
3. Data Types in Redis
4. Advanced Features and Security
5. Caching with Redis and Spring Boot

book
String

We've already covered basic Redis commands like SET, GET, and DEL, which allow you to work with keys and their values. These commands primarily deal with strings.

Now, let's explore advanced string commands that provide additional functionality.

Advanced String Commands

Redis provides a range of advanced commands to enhance string manipulation. These commands allow you to perform conditional operations, work with multiple keys at once, and modify existing values efficiently.

SETNX

The SETNX command (Set if Not Exists) sets a value only if the key does not already exist. If the key exists, the command will make no changes. This command is useful when you want to avoid overwriting existing values.

If mykey does not exist, it will be created and assigned the value "value". If the key already exists, its value will remain unchanged.

STRLEN

The STRLEN command returns the length of the string associated with a given key. It provides the number of characters in the string.

If mykey exists and its value is a string, Redis will return its length.

MSET and MGET

The MSET command allows you to set multiple keys and their values in a single operation. All keys will be updated, and if any of them already exist, their values will be overwritten.

In this example, three keyskey1, key2, and key3 are set with their respective values.

The MGET command retrieves the values of multiple keys in a single operation. It returns the values as a list.

This command will return the values of all three keys. If a key does not exist, its value will be nil.

APPEND

The APPEND command adds data to the end of the string associated with a given key. If the key does not exist, Redis creates it with the specified value.

If mykey exists, the string "additional value" will be appended to its current value. If the key does not exist, it will be created with the value "additional value".

1. Which Redis command sets a value only if the key does not already exist?

2. Which Redis command retrieves the length of the string associated with a key?

Which Redis command sets a value only if the key does not already exist?

Which Redis command sets a value only if the key does not already exist?

Виберіть правильну відповідь

Which Redis command retrieves the length of the string associated with a key?

Which Redis command retrieves the length of the string associated with a key?

Виберіть правильну відповідь

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 1
We're sorry to hear that something went wrong. What happened?
some-alt