Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Redis Data Types and Key Management Commands

Tech 1

Connecting to the Redis CLI:

$ redis-cli
127.0.0.1:6379> PING
PONG

String Operations

Store and retrieve simple values:

127.0.0.1:6379> SET metrics:page:home 100
127.0.0.1:6379> GET metrics:page:home

Atomic counter operations:

127.0.0.1:6379> INCR metrics:page:home
127.0.0.1:6379> DECR metrics:page:home

Check string length:

127.0.0.1:6379> STRLEN metrics:page:home

List Operations

Create a list with multiple elements:

127.0.0.1:6379> LPUSH workflow:steps "validation" "processing" "completion"

Remove the first element:

127.0.0.1:6379> LPOP workflow:steps

Move elements between lists:

127.0.0.1:6379> RPOPLPUSH workflow:pending workflow:active

Insert at specific position:

127.0.0.1:6379> LINSERT workflow:steps BEFORE "processing" "authentication"

Count list elements:

127.0.0.1:6379> LLEN workflow:steps

Hash Operations

Set individual fields:

127.0.0.1:6379> HSET user:session:5001 username "alice"
127.0.0.1:6379> HSET user:session:5001 last_active "2024-01-15"

Batch field insertion:

127.0.0.1:6379> HMSET user:session:5002 username "bob" login_count 5

Inspect hash structure:

127.0.0.1:6379> HKEYS user:session:5001
127.0.0.1:6379> HLEN user:session:5002

Retrieev specific values:

127.0.0.1:6379> HGET user:session:5001 username

Key Management

Verify key existence:

127.0.0.1:6379> EXISTS user:session:5001

Pattern matching searches:

127.0.0.1:6379> KEYS user:session:*
127.0.0.1:6379> KEYS metrics:*

Check expiration status:

127.0.0.1:6379> TTL workflow:steps

List all keys:

127.0.0.1:6379> KEYS *
Tags: RedisNoSQL

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.