redis(三):lists,sets,hashes,sorted sets

lists

按插入排序

  • lpush / rpush
  • lpop / rpop
    以上两个命令同向可实现(ex:lpush,lpop),反向可实现队列(ex:lpush,rpop)。
  • lrange: Get a range of elements from a list
  • lindex / lset :取值/更新
    以上两个命令可以对应数组数据结构
  • lrem:移除 参数为正从前向后删除重复元素
  • linsert: 插入 after/before 指定在后/前插入
  • blpop:阻塞弹出,对应于阻塞、单播队列,FIFO
  • ltrim:对start,end两个参数两端进行删除

hashes

  • hdel
  • hexists
  • hget
  • hset
  • hsetnx
  • hgetall
  • hincrby
  • hincrbyflout
  • hkeys
  • hlen
  • hmget
  • hmset
  • hscan:Incrementally iterate hash fields and associated values
  • hstrlen
  • hvals

应用场景:微博的关注点赞数,被浏览被收藏的次数等;详情页,可以通过一个key拿出所有相关内容

sets

无序,去重

  • sadd
  • scard:Get the number of members in a set
  • sdiff:差集
  • sdiffstore
  • sinter:交集,直接打印输出
  • sinterstore:交集,相比sinter指定了一个key,将输出结果保存在key中,减少了与客户端的一次I/O
  • sismember: Get the number of members in a set
  • smembers: Get all the members in a set
  • smove: Move a member from one set to another
  • spop: Remove and return one or multiple random members from a set //应用于取出不放回类型的抽奖
  • srem
  • sscan: Incrementally iterate Set elements
  • sunion: Add multiple sets
  • sunionstore: Add multiple sets and store the resulting set in a key

随机事件

  • srandmember
    参数:key count
    count为正,取出一个去重后的不超过已有集合的结果集
    count为负,取出一个可能带重复的结果集,一定满足指定数量
    count为0,不返回

应用场景:抽奖

sorted sets

有序set

  • bzpopmax:Remove and return the member with the highest score from one or more sorted sets, or block until one is available
  • bzpopmin
  • zadd
  • zcard: Add one or more members to a sorted set, or update its score if it already exists
  • zcount: Count the members in a sorted set with scores within the given values
  • zincrby
  • zincrbystore
  • zlexcount: Count the number of members in a sorted set between a given lexicographical range
  • zpopmax: Remove and return members with the highest scores in a sorted set
  • zpopmin
  • zrange
  • zrevrange
  • zrangebylex: Return a range of members in a sorted set, by lexicographical range
  • zrevrangebylex
  • zrangebyscore
  • zrevrangebyscore
  • zrank
  • zrevrank
  • zrem
  • zremrankbylex: Remove all members in a sorted set between the given lexicographical range
  • zremrankbyrank
  • zremrankbystore
  • zscan
  • zscore
  • zunionstore

  • 按物理内存左小右大排序,不随命令而发生变化(如何做到反向排序的?有逆向索引)
  • 支持集合操作:并集,交集(注意权重和聚合指令)
  • 排序是如何实现的?CRUD速度? --------- SkipList

应用场景:歌曲排行榜

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值