redis如何监控

1.定义:redis是什么

redis(REmote DIctionary Server), 是一个开源的高性能的key-value存储。

通常被称为数据结构服务器(data structure server), 因为它存储的key可以包括多种类型。

使用ANSI c编写。

数据都是缓存在内存中,且会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件(也可以disable永久保留的功能,当做memcached使用)。

release 3.0.0


redis不是数据库, 只是一个数据结构的存储服务器。


2. redis支持的数据结构类型

strings: 字符串, value size less than 512MB

lists: collections of string elements sorted according to the order of insertion

sets: collections of unique, unsorted string elements

sorted sets: sets that every element associated to a floating number value, called score

hashes: maps composed of fields associated with values

bitmaps(bit arrays): handle String values like an array of bits

hyperloglogs: probabilistic data structure used to estimate the cardinality of a set.


用户通过不同的redis api 来操作不同的数据结构,即用户对数据的类型负责。可以通过type keyxxx 来得知keyxxx的数据类型。


3. redis keys的特别之处

redis的key是binary safe, 即可以使用任何的binary sequence作为key,从空字符串到一个jpg文件。

maximum allowed key size is 512 MB



4. 各数据类型对应的api


通用: exists/del/type/expire/ttl/persist/keys


string: set/get/incr/incrby/decr/decrby/getset/mget/mset

list: lpush/lpop/rpush/rpop/lrange/ltrim/blpop/brpop

hash: hset/hget/hmset/hmget/hgetall/hincrby/hdel/hexists

set: sadd/smembers/sismember/sinter/sinterstore/sunion/sunionstore/spop

sorted set: zadd/zrange/zrevrange/zrangebyscore/zremrangebyscore/zrank/

zrevrank/

bitmaps: 512MB = 2^32

     setbit/getbit/bitop/bitcount/bitpos

hyperloglogs: 节约内存空间

              pfadd/pfcount/

5. Pub/Sub

消息的订阅和发布, 二者是解耦的。subscriber/publisher彼此间互不关心。被很多的任务处理系统(e.g. celery)用作消息代理(message broker)。

6. Partitioning/cluster

cluster still in beta not in production,just experimental

7. Distributed Lock Manager(DLM)

kinds of DLMs available at http://www.redis.io/topics/distlock

8. Replication

slaveof master_ip port in redis.conf

9. redis监控

方法1:使用python 的redis package里面的info()方法可以很方便地获取redis的实时数据。redis.StrictRedis().info(),可参见

https://github.com/hustcc/redis-monitor

方法2:使用redis-cli monitor, 解析输出的命令行,获取相关的数据。https://github.com/facebookarchive/redis-faina

你可能感兴趣的:(redis)