---
title: "（一）Redis基础类型"
author: "mistbow"
date: "2013-08-19T22:26:26Z"
tags: []
categories: ["互联网"]
slug: "redis"
draft: false
lastmod: "2013-08-19T22:27:15Z"
id: 1927300
url: "https://mistbow.iteye.com/blog/1927300"
---

Redis有五种基础类型：

```java
String  List Set Hash Zset(sorted set)
```

一下图片均来自Redis in action

<span style="color:red">String:</span>

![](http://dl2.iteye.com/upload/attachment/0088/3855/27ff0ec4-3443-35f7-aa78-79174f006d99.png)


string command:
<http://redis.io/commands#string>

set hello world
get hello
del hello
get hello

<span style="color:red">list:</span>

![](http://dl2.iteye.com/upload/attachment/0088/3857/8d9db9a3-e724-3bdd-926a-4f78714d193e.png)

List command:
<http://redis.io/commands#list>

rpush list-key item
rpush list-key item2
rpush list-key item
lrange list-key 0 -1
"item"
"item2"
"item"
lindex list-key 1
lpop list-key
lrange list-key 0 -1

<span style="color:red">Set:</span>

![](http://dl2.iteye.com/upload/attachment/0088/3859/8f5c3cb1-5438-3614-8d5a-23e15895653b.png)


Set command :
<http://redis.io/commands#set>

sadd set-key item
sadd set-key item2
sadd set-key item3
sadd set-key item
smembers set-key
1) "item"
2) "item2"
3) "item3"

<span style="color:red">Hash</span>

![](http://dl2.iteye.com/upload/attachment/0088/3861/5dfb5bfc-4279-3917-95de-f460d58f42b4.png)


hash command :
<http://redis.io/commands#hash>

hset hash-key sub-key1 value1
hset hash-key sub-key2 value2
hset hash-key sub-key1 value1
hgetall hash-key
1) "sub-key1"
2) "value1"
3) "sub-key2"
4) "value2"

<span style="color:red">sorted set:</span>

![](http://dl2.iteye.com/upload/attachment/0088/3863/6b02696b-1c11-3d35-a19d-c90cc8900875.png)

sorted set command :
<http://redis.io/commands#sorted_set>

zadd zset-key 728 member1
zadd zset-key 982 member0
zadd zset-key 982 member0
zrange zset-key 0 -1 withscores
1) "member1"
2) "728"
3) "member0"
4) "982"
zrangebyscore zset-key 0 800 withscores
zrem zset-key member1
zrem zset-key member1
zrange zset-key 0 -1 withscores