redis 五种类型:set集合 zset有序集合 list列表 string字符串 hash哈希
redis 默认有16个数据库 默认使用0数据库
select //选择数据库
keys * //查看所有键值
flushdb //清空当前数据库
flushall //清空所有数据库
string操作:
set key value
get key //return value
getrange key start end //return value from start to end
setrange key offset value
setex key seconds value
ttl //return time to live
setnx key value
mset key value key value key value
mget key key key
list操作:
lpush key value
rpush key value
lpop key value
rpop key value
lrnage key start stop
lindex key index
lset key index value
linsert key before|after value value
llen key
lrem key count element
set操作:
sadd key [value]
sinter key1 key2
sdiff key1 key2
sunion ke1 key2
srem key value
smembers key
sismember key
hash操作:
hset key field value
hget key field
hmset key [field value]
hmget key [field value]
hlen key
getall key
hexists key field
hsetnx key field value
hkeys key
hvals key
hincrby key filed value
hash中存储经常变更的值:比如用户信息: user : name-value,age-value,sex-value
hash更适合对象的存储,String更加适合字符串存储
zset操作:
zadd key scores value
zrange key start stop
zrangebyscore key min max
zrem key value
zcard key
zcount key min max