Redis支持多種數據類型,包括字符串(String)、列表(List)、集合(Set)、有序集合(Sorted Set)和哈希表(Hash)。以下是創建這些數據類型的命令:
SET key value
GET key
EXISTS key
示例:
SET mykey "Hello, Redis!"
GET mykey
LPUSH key element
RPUSH key element
LLEN key
LRANGE key index
示例:
LPUSH mylist "Hello"
RPUSH mylist "World"
LRANGE mylist 0 1
SADD key element
SMEMBERS key
SISMEMBER key element
示例:
SADD myset "apple"
SMEMBERS myset
SISMEMBER myset "banana"
ZADD key score element
ZRANGE key 0 -1 WITHSCORES
ZISMEMBER key element
示例:
ZADD myzset 1 "apple"
ZRANGE myzset 0 -1 WITHSCORES
ZISMEMBER myzset "banana"
HSET key field value
HGETALL key
HEXISTS key field
示例:
HSET myhash name "Alice"
HGETALL myhash
HEXISTS myhash age