Redis数据库支持五种数据类型。
- 字符串(string)
- 哈希(hash)
- 列表(list)
- 集合(set)
- 有序集合(sorted set)
1.字符串:
SET name "redis.com.cn" OK GET name "redis.com.cn"
2.哈希
HMSET user:1 username ajeet password javatpoint alexa 2000 OK HGETALL user:1 "username" "ajeet" "password" "javatpoint" "alexa" "2000"
3.列表
127.0.0.1:6379> lpush javatpoint java
(integer) 1
127.0.0.1:6379> lpush javatpoint java
(integer) 2
127.0.0.1:6379> lpush javatpoint java
(integer) 3
127.0.0.1:6379> lpush javatpoint java
(integer) 4
127.0.0.1:6379> lrange javatpoint 0 10
1) "java"
2) "java"
3) "java"
4) "java"
127.0.0.1:6379>
4.集合
127.0.0.1:6379> sadd tutoriallist redis
(integer) 1
127.0.0.1:6379> sadd tutoriallist sql
(integer) 1
127.0.0.1:6379> sadd tutoriallist postgresql
(integer) 1
127.0.0.1:6379> sadd tutoriallist postgresql
(integer) 0
127.0.0.1:6379> sadd tutoriallist postgresql
(integer) 0
127.0.0.1:6379> smembers tutoriallist
1) "redis"
2) "postgresql"
3) "sql"
127.0.0.1:6379>