美文网首页
Redis 基本操作

Redis 基本操作

作者: 一颗北上广的心 | 来源:发表于2017-09-27 17:00 被阅读0次
  • 启动
启动server:redis-server.exe redis.windows.conf
启动client:redis-cli.exe -h 127.0.0.1 -p 6379
  • 配置
--get all config 
config get *
config get configname

--set config
config set configname configvalue
  • Abount key
-- key
set key value    --set key and value
del key          -- delete key
exists key       -- if exists
expire aaa 10    -- set the timeout 10s
pexpire aaa 5000  -- set timeout 5000mm
expireat aaa 1504771560  --set timeout at unixstamp
ttl key --show the seconds left before expire
rename key key1
  • String(字符串,整数,浮点数)
127.0.0.1:6379> set name zouyufei
127.0.0.1:6379> mset name zouyufei age 20 (multi set)
127.0.0.1:6379> get name
127.0.0.1:6379> getrange name 1 3   (index from 0)
127.0.0.1:6379> setrange name 7 aa (name = name from 0-7  +  aa)
127.0.0.1:6379> mget name age  (get multi keys)
127.0.0.1:6379> setex gender 10 male (set gender=male, and timeout=10s)
127.0.0.1:6379>setnx name zouyf (set name=zouyf if name doesn't exist)
127.0.0.1:6379> msetnx name zouyufei age 20 (multi set when all keys don't exist)
127.0.0.1:6379> strlen name (get name length)
127.0.0.1:6379> incr age (age ++)
127.0.0.1:6379> incrby age 10 (age+=10)
127.0.0.1:6379> decr age (age--)
127.0.0.1:6379> decrby age 10 (age -=10)
127.0.0.1:6379> append name dtc (name=name+dtc)
  • Hash(包含键值队的无序散列表)
127.0.0.1:6379> hset mac cpu i7
127.0.0.1:6379> hmset mac cpu i5 memory 10G price 4999 (set multi)
127.0.0.1:6379> hgetall mac
127.0.0.1:6379> hget mac cpu
127.0.0.1:6379> hmget mac screen memory (get multi )
127.0.0.1:6379> hdel mac address screen (delete address and screen from mac)
127.0.0.1:6379> hexists mac name
127.0.0.1:6379> hincrby mac price 10 (mac's price +=10)
127.0.0.1:6379> hkeys mac (get all keys in mac)
127.0.0.1:6379> hlen mac (key count)
127.0.0.1:6379> hsetnx mac cpu i8 (set value only key doesn't exist)
127.0.0.1:6379> hvals mac (get all values)
  • List (一个链表,链表上每个结点都包含一个字符串)
127.0.0.1:6379> lpush list 1 (if list doesn't exist, create the list)
127.0.0.1:6379> lpush list 2 3 4 (push the elements from left)
127.0.0.1:6379> lpushx list 6 (if list doesn't exist, do nothing)
127.0.0.1:6379> lrange list 0 2
127.0.0.1:6379> lindex list 2 (get the second element)
127.0.0.1:6379> llen list (get length)
127.0.0.1:6379> lpop list (get first element from left - head)
127.0.0.1:6379> lrem list 2 5 (remove 5 twice from head)
127.0.0.1:6379> lset list 0 100 (set the first element from left to 100)
127.0.0.1:6379> ltrim list 0 4 (remain from 0 -4 elements)
127.0.0.1:6379> rpoplpush list list (pop first element from right and push to list from left)

127.0.0.1:6379> rpush list 2 3 4 (push the elements from right)
127.0.0.1:6379> rpushx list 6 (if list doesn't exist, do nothing)
127.0.0.1:6379> rpop list (get first element from right - tail)
  • Set (字符串无序收集器,每个元素唯一)
127.0.0.1:6379> sadd set 1 2 3 4
127.0.0.1:6379> srem set 4 (remove)
127.0.0.1:6379> smembers set (show all)
127.0.0.1:6379> scard set  (show size)
127.0.0.1:6379> sdiff set set1 (get the difference between set and set1)
127.0.0.1:6379> sdiffstore diffset set set1 ( store the difference between set and set1 to diffset)
127.0.0.1:6379> sinter set set1 (交集)
127.0.0.1:6379> sinterstore interset set set1
127.0.0.1:6379> sunion set set1 (并集)
127.0.0.1:6379> sunionstore unionset set set1
127.0.0.1:6379> sismember set 1 (if 1 belongs to set)
127.0.0.1:6379> smove set set1 1 (remove 1 from set to set1)
127.0.0.1:6379> spop set 2 (drop 2 elements randomly from set)
127.0.0.1:6379> srandmember set 2 (get 2 elements randomly from set)
  • Sorted Set (字符串成员与浮点数分值之间的有序映射)
127.0.0.1:6379> zadd zet 1 a
127.0.0.1:6379> zadd zet 2 b
127.0.0.1:6379> zadd zet 1 a 2 b 3 c (add a,b,c with weight 1 2 3)

127.0.0.1:6379> zrank zet a (show the index of a order by score asc- from 0)
127.0.0.1:6379> zrevrank zet2 a (show the index of a order by score desc)
127.0.0.1:6379> zscore zet1 a(show the score of a)
127.0.0.1:6379> zrange zet 0 10 withscores (show the elements whose index between 0 and 10)
[127.0.0.1:6379>zrangebylex zet1 [a [c (show the elements whose score between a and c's score)]


127.0.0.1:6379> zcard zet (size)
127.0.0.1:6379> zcount zet 1 2 (get the count whose score between 1 and 2)
127.0.0.1:6379> zlexcount zet1 [a [b (get the count which weight between a and b's weight )
127.0.0.1:6379> zincrby zet 10 a (add 10 to the weight of a)
127.0.0.1:6379> zinterstore interzet 2 zet zet1 (交集)
127.0.0.1:6379> zunionstore unionzet 2 zet zet1(并集)
127.0.0.1:6379> zrem zet a

127.0.0.1:6379> zremrangebylex zet [a [b (remove elements whose score between a and b's)
127.0.0.1:6379> zremrangebyscore zet 0 4 (remove elements whose score between 0 and 4)
127.0.0.1:6379> zrevrange zet1 0 1(get the last 2 elements)

相关文章

  • php操作redis大全

    php连接redis测试 php操作redis函数封装 php操作redis大全,基本上php操作redis常用的...

  • Redis学习之路(二):Redis数据结构简介

    Redis提供的5种结构 Redis中的字符串 基本命令 操作练习: Redis中的列表 基本命令 基本操作: R...

  • php对redis的基本操作

    php对redis的基本操作 对key的基本操作

  • php操作redis大全

    php连接redis测试 php操作redis大全,基本上php操作redis常用的函数都在下面了

  • redis 基本操作

    连接redis 选择数据库 查看所有key 查看list的全部值 返回列表 key 中指定区间内的元素,区间以偏移...

  • Redis 基本操作

    本人郑重承诺以下都是基本操作,请坐下请坐下。内容是跟着http://try.redis.io/做的。边学边笔记。更...

  • Redis基本操作

    通用操作 rename name xm 把键name重设为xm select 选择数据库(线上慎用) keys *...

  • Redis 基本操作

    启动与关闭Redis服务、进入Redis环境 1.启动Redis服务 redis-server 拷贝的redis....

  • Redis基本操作

    NoSQL(Not Only SQL) NoSQL指的是非关系型数据库,是对不同于传统关系型数据库的数据库管理系统...

  • redis基本操作

    Redis可以存储键与5种不同数据结构类型之间的映射,这5种数据结构类型分别为STRING(字符串)、LIST(列...

网友评论

      本文标题:Redis 基本操作

      本文链接:https://www.haomeiwen.com/subject/mysvjxtx.html