Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Redis Data Types and Command Operations Guide

Tech 1

Download and install the appropriate Redis distribution for your operating system from the official releases page. Once installed, launch the Redis CLI to verify the connection:

redis-cli

Validate the server responsiveness:

127.0.0.1:6379> PING
PONG

The PONG response confirms successful connectivity.

String Data Type Operations

Store a descriptive sttring value:

SET task_desc "Redis homework assignment"

Retrieve the stored value:

GET task_desc

Initialize and increment a numeric counter:

SET counter 100
INCR counter

Decrement the same counter:

DECR counter

Check the byte length of a string value:

STRLEN task_desc

List Data Type Operations

Append multiple elements to a list:

RPUSH locations Beijing Shenzhen Guangzhou

Remove and return the first element:

LPOP locations

Atomically move the last element of one list to another:

RPUSH users_list Alice Bob Charlie
RPOPLPUSH users_list recipients_list

Insert an element before a specific existing element:

LINSERT locations BEFORE Shenzhen Chengdu

Count the number of elements:

LLEN locations

Hash Data Type Operations

Create a hash with individual field assignments:

HSET purchase id 101
HSET purchase customer_name "John Doe"

Bulk insert multiple fields:

HSET profile user_id 3 username "alex_k" level 25

Retrieve all field names within a hash:

HKEYS purchase

Count fields in a hash:

HLEN purchase

Access a specific field value:

HGET purchase id

Key Management Commands

Check key existence:

EXISTS sample_key

Find keys matching a pattern:

KEYS *session*

Inspect remaining time-to-live:

TTL temp_key

Iterate through the keyspace efficiently:

SCAN 0

Alternative iteration methods include:

  • KEYS * for all key (use cautiously in production)
  • SSCAN set_key 0 for set members
  • HSCAN hash_key 0 for hash fields
  • ZSCAN zset_key 0 for sorted set members

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.