Redis Setup and Client Access
Install Redis, then launch the interactive client and confirm connectivity.
String Type Commands
Work with key-value pairs where the value is treated as text or numeric data.
- Assign a value to a key:
SET itemA 8
- Retrieve the stored value:
GET itemA
- Increment numeric content by one:
INCR itemA
- Decrement numeric content by one:
DECR itemA
- Determine the character length of the value:
STRLEN itemA
List Type Commands
Manage ordered sequecnes of elements.
- Insert multiple entries at the head of list
places:
LPUSH places Nanjing Suzhou Hangzhou
- Remove the first element from
places:
LPOP places
- Transfer the tail element from
labelListto the head ofcodeList:
RPOPLPUSH labelList codeList
- Insert an entry before a specified member in
places:
LINSERT places BEFORE Nanjing Wuxi
- Get the count of items in a list:
LLEN places
LLEN labelList
LLEN codeList
Hash Type Commands
Handle mappings of fields to values within a single key.
- Create a hash
purchaseand set individual fields:
HSET purchase uid 1
HSET purchase buyer "wangwu"
- Populate a hash with multiple field-value pairs in one step:
HMSET purchase uid 1 buyer "wangwu"
- List all field names in
purchase:
HKEYS purchase
- Count the fields in
purchase:
HLEN purchase
- Fetch the value of a specific field:
HGET purchase uid
Key Management Commadns
Inspect and manipulate key metadata.
- Test if a key exists:
EXISTS sampleKey
- Find keys matching a glob-style pattern:
KEYS pattern
KEYS places
KEYS nam*
- Remove expiration from a key (make it persistent):
PERSIST places
- Enumerate all keys in the data base:
KEYS *