Redis data types

Redis data types

Reids is not a plain-value store, actually it is a data structures server, supporting different kinds of values.

Redis keys

  • Any binary sequences can be used as a key, from a string to the content of a JPEG file.

Rules about keys

  • Very long keys are not a good idea. (in order to antenuate the key-comparison cost)
    – Hashing a very long key first (SHA1) is a better idea.
  • Very short keys are often not a good idea, too short to be readable.
    – “u1000flw” vs “user:1000:followers”
  • The maximum allowed key size is 512MB.

Redis Strings

Operations on Redis Strings

  1. set, get, getset
  2. Parsing the Redis String Values as an integer/float
    • incr, decr, incrby, decrby, incrbyfloat
  3. Altering and querying key space
    • commands useful in order to interact with space of keys, not defined on particular types
    • exists, del, type
  4. Setting or retrieving the value of multiple keys in a single command
    • mset, mget
  5. Bitmaps
    • constant-time single bit operations: setbit, getbit
    • operations on groups of bits: bitop, bitcount, bitpos

Redis Lists

  • Redis lists are implemented via Linked Lists.

Common use cases for lists

  1. Remember the latest updates posted by users into a social network
  2. Communication process, using a consumer-producer patern

Operations on Redis Lists

  1. Push and Pop
    • rpush, lpush, rpop, lpop
  2. Retrieving a range of elements at one time
    • lrange
  3. Capped lists
    • ltrim
  4. Blocking operations on lists
    • Why need these operations?
      – Non-blocking operations may lead to useles commands or unnecessary waiting time.
    • blpop, brpop
      – BLPOP and BRPOP are able to block waiting for elements from multiple lists.

Redis Hashes

  • Hashes are handy to represent objects, with the keys representing the objects’ attributes.
    1. Setting or retrieving the value (one or multiple)
  • hmset, hmget, hset, hget
    1. Performing opertions on individual fields
  • hincrby, hincrbyfloat
    1. full list of hash commands in the documentation
  • hexists, hkeys, hvals, hgetall

Redis Sets (unordered)

  1. Setting or retrieving
    • sadd, srem
  2. Operations on multiple sets
    • sdiff, sinter, sunion, sdiffstore, sinterstore, sunionstore

Redis Sored Sets

  1. Setting or retrieving
    • zadd, zrange, zrevrange
    • using withscores to return scores in zrange order
  2. Operating on ranges
    • zrangebyscore, zremrangebyscore, zrank, zrevrank,
      – zrangebyscore hackers -inf 1950
  3. Lexicographical scores
    • zrangebylex, zrevrangebylex, zremrangebylex, zlexcount

Redis HyperLogLogs

A HyperLogLog is a probabilistic data structure used in order to count unique things (technically this is referred to estimating the cardinality of a set).

  1. pfadd, pfcount
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值