Redis 字符串与哈希
/***
* 字符串 redis里的字符串
***/
//设置key的值
redis 127.0.0.1:6379> set key 'my name is imay'
//设置值的过期时间 (单位 : 秒)
redis 127.0.0.1:6379> expire key1 30
(integer) 1
//获取key的值
redis 127.0.0.1:6379> get key
"my name is imay"
//删除这个key
redis 127.0.0.1:6379> del key
(integer) 1
//更改这个key1 为 key11
redis 127.0.0.1:6379> rename key1 key11
OK
//incr 将page 值加1
//decr 将page值减1
redis 127.0.0.1:6379> set page 0
OK
redis 127.0.0.1:6379> incr page
//给page 尾端追加字符串
redis 127.0.0.1:6379> append page "~3"
(integer) 3
redis 127.0.0.1:6379> get page
"2~3"
// decrby 给 count 减去等量的值 如果值不存在,值以0开始计算
// incrby 是给count 加,同上
redis 127.0.0.1:6379> set count 100
OK
redis 127.0.0.1:6379> decrby count 10
(integer) 90
/***
* 哈希(hash) 哈希在redis里作为一种对象存储方式
***/
// hset 单个设置member 的组 name值
redis 127.0.0.1:6379> hset member name wenbo
(integer) 1
redis 127.0.0.1:6379> hset member age 18
(integer) 1
//hget 获取member name 的值
redis 127.0.0.1:6379> hget member name
"wenbo"
// hmget 批量获取member 的值
redis 127.0.0.1:6379> hmget member name age
1) "wenbo"
2) "18"
//hgetall 获取hash表的member所有域和值
redis 127.0.0.1:6379> hgetall member
1) "name"
2) "wenbo"
3) "age"
4) "18"
//hexists 判断 member name 的值是否存在
redis 127.0.0.1:6379> hexists member name
(integer) 1
// hkeys获取 member 所有域
redis 127.0.0.1:6379> hkeys member
1) "name"
2) "age"
//hvals 获取member 所有域的值
redis 127.0.0.1:6379> hvals member
1) "wenbo"
2) "18"
//hincrby 增加或减少 域的值, 如果域不存在,则从0开始计算
redis 127.0.0.1:6379> hincrby member age 2
(integer) 20
redis 127.0.0.1:6379> hincrby member age -2
(integer) 18
//hkeys获取域
redis 127.0.0.1:6379> hkeys member
1) "name"
2) "age"
//hdel 删除一个域的值
redis 127.0.0.1:6379> hdel member sex
(integer) 1
//hdel 删除 多个( age name )域的值
redis 127.0.0.1:6379> hdel member age name
(integer) 2
//hlen 获取域的个数
redis 127.0.0.1:6379> hlen user
(integer) 1