Redis学习笔记
原文链接:http://www.yiibai.com/redis/redis_quick_guide.html
1.启动Redis
$redis-server
2. 检查Redis是否在工作
$redis-cli
3.Redis的5种数据类型 :字符串,哈希,列表,集合,有序集合
例子:
1)字符串
redis 127.0.0.1:6379> SET name "yiibai" OK redis 127.0.0.1:6379> GET name "yiibai"
2)哈希
redis 127.0.0.1:6379> HMSET user:1 username yiibai password yiibai points 200 OK redis 127.0.0.1:6379> HGETALL user:1 1) "username" 2) "yiibai" 3) "password" 4) "yiibai" 5) "points" 6) "200"
3)列表
redis 127.0.0.1:6379> lpush tutoriallist redis (integer) 1 redis 127.0.0.1:6379> lpush tutoriallist mongodb (integer) 2 redis 127.0.0.1:6379> lpush tutoriallist rabitmq (integer) 3 redis 127.0.0.1:6379> lrange tutoriallist 0 10 1) "rabitmq" 2) "mongodb" 3) "redis"
4)集合
redis 127.0.0.1:6379> sadd tutoriallist redis (integer) 1 redis 127.0.0.1:6379> sadd tutoriallist mongodb (integer) 1 redis 127.0.0.1:6379> sadd tutoriallist rabitmq (integer) 1 redis 127.0.0.1:6379> sadd tutoriallist rabitmq (integer) 0 redis 127.0.0.1:6379> smembers tutoriallist 1) "rabitmq" 2) "mongodb" 3) "redis"
5)有序集合
redis 127.0.0.1:6379> zadd tutoriallist 0 redis (integer) 1 redis 127.0.0.1:6379> zadd tutoriallist 0 mongodb (integer) 1 redis 127.0.0.1:6379> zadd tutoriallist 0 rabitmq (integer) 1 redis 127.0.0.1:6379> zadd tutoriallist 0 rabitmq (integer) 0 redis 127.0.0.1:6379> ZRANGEBYSCORE tutoriallist 0 1000 1) "redis" 2) "mongodb" 3) "rabitmq"