Redis Data Types and Command Operations Guide
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 0for set membersHSCAN hash_key 0for hash fieldsZSCAN zset_key 0for sorted set members