é«€§èƒ½No sql•°®“redis

download é«€§èƒ½No sql•°®“redis

of 30

  • date post

    19-Aug-2014
  • Category

    Education

  • view

    12.239
  • download

    3

Embed Size (px)

description

redis

Transcript of é«€§èƒ½No sql•°®“redis

  • NoSQLRedis

    http://www.paitoubing.cn
  • NoSQL

    APP

    memcached
    Disk

    Jim Gray
  • Redis
    Redis
    Redis
    RedisAPI
    Redis,
  • Redis
    What is
    sponsored by:
    Redis is...
    an advanced key-value store
    b y
    S A LVATO R E S A N F I L I P P O
    ( @ a n t i r e z )
  • Redisvs Memcached
    Memcached
    (keys)
    (values)
    page:index.html
    [...]
    xDrSdEwd4dSlZkEkj+
    user:101:session
    login_count
    100001
    user:100:last_login_time
    102736485756
    2
    GETSET2,
  • Redisvs Memcached
    Memcached (1G 1M)

    ;
    Strings() Lists()
    Sets()ZSets()Hashes()
    API ;
    More commands
    and More.
    Is Redis
  • Redisvs Memcached
    Redis
    (keys)
    (values)
    page:index.html
    [...]
    String
    { 1, 2, 3, 4, 5 }
    users_logged_in_today
    Sets
    latest_post_ids
    [201, 204, 209,..]
    List
    users_and_scores
    joe ~ 1.3483
    bert ~ 93.4
    fred ~ 283.22
    chris ~ 23774.17
    ZSets
  • RedisAPI
    Strings
    value
    C client
    key
    ./redis-cli SETmystring hello world
    return
    ./redis-cli GETmystring
    hello world
  • RedisAPI
    Strings
    GETSET
    MGET
    SETNX
    SETEX
    MSET
    MSETNX
    INCR
    INCRBY
    DECR
    DECRBY
    APPEND
    SUBSTR
  • RedisAPI
    Expiration
    Redis,,(string,list,zsets,sets,hash)

    EXPIRE paitoubing1234

    TTL paitoubing
    == 1234

  • RedisAPI
    Deleting Keys
    DEL paitoubing
    EXISTSpaitoubing
    == 0 (false)
  • RedisAPI
    Lists
    LPUSH
    RPUSH
    a
    b
    c
    d
    e
    f
    RPOP
    LPOP
    LPUSHpaitoubing a
  • RedisAPI
    Lists
    LLEN == 6
    x
    a
    b
    c
    d
    e
    f
    LRANGE 2 3
    LREM 1 b
    LINDEX 5
  • RedisAPI
    Queues
    RPUSH
    a
    b
    c
    d
    e
    f
    LPOP
    RPUSH paitoubing abc
    RPUSH paitoubing def
    LPOP paitoubing == abc
    LPOP paitoubing == def
    LPOP paitoubing == (nil)
  • RedisAPI
    Sets
    bruce tom zhangsan lisi
    wangermazi xiaoyueyue fengjie
    uid:1:followers
    x
    SREMuid:1:followers wangermazi
    SMOVEuid:1:followers uid:2:followers lisi
    xiaoyueyue fengjie liyuchun
    furongjiejie
    uid:2:followers
    SADD uid:2:followers tom
  • RedisAPI
    Sets
    bruce tom zhangsan lisi
    wangermazi xiaoyueyue fengjie
    uid:1:followers
    SCARD uid:1:followers == 7
    SISMEMBER uid:1:followers xinxin == 0 (meaning false)
    SRANDMEMBER uid:1:followers == xiaoyueyue
    xiaoyueyue fengjie liyuchun
    furongjiejie
    uid:2:followers
    SMEMBERS uid:2:followers
    == xiaoyueyue fengjie liyuchun
    furongjiejie
  • RedisAPI
    Sets
    bruce tom zhangsan lisi
    wangermazi xiaoyueyue fengjie
    uid:1:followers
    xiaoyueyue fengjie
    xiaoyueyue fengjie liyuchun
    furongjiejie
    uid:2:followers
    SINTER uid:1:followers uid:2:followers == xiaoyueyue fengjie
    SINTERSTORE
    SUNION SUNIONSTORE
    SDIFF SDIFFSTORE
  • RedisAPI
    ZSets
    Like Sets
    ,rank,score
    no time!
  • RedisAPI
    Hashes
    :Product 1
    HSET product:1 created_at 1290149988
    HSET product:1 name
    created_at : 1290149988
    product_id : 1
    name :
    available : 100
    HSET product:1 available 100
    HGETproduct:1 name ==
    HLEN product:1== 3
    HKEYS product:1
    == created_at, name,available
    HGETALLproduct:1 ==
    created_at => 102374657
    name=>
    available=> 100
    HVALS HEXISTS HINCRBY HMGET HMSET
  • RedisAPI
    Redis Social Network
    UGC


    text
    photo
    blogMessagephoto
    more..
  • RedisAPI
    Redis Social Network
    Int

    username
    userid
    INCR next_user_id
    Return s [uid]
    SET user:[uid]:name [username]
    SET username:[username] [id]


    I NCR next_post_id
    Return s [pid]
    content
    author
    SET post:[pid]:content [content]
    SET post:[pid]:author [uid]
    LPUSH user:[uid]:posts [pid]
    LPUSH posts:global [pid]
    Unique IDs
  • RedisAPI
    Enough commands!
    SUBSCRIBE
    SORT
    SLAVEOF
    RENAME
    MONITOR
    PUBLISH
    ZCARD
    SELECT
    SAVE
  • Redis
    http://code.google.com/p/redis/
    Redistar zxvfredis-version.tar.gzcdredis-versionmakemake installcp redis.conf /etc/cp redis-benchmark redis-cliredis-server /usr/bin/
    /etc/redis.confdaemonize yes
    redis
    # /usr/bin/redis-server /etc/redis.conf
  • Redis
    Redis.conf
    daemonize yes =>
    maxmemory => Redis ,,
    vm,key,valueswap,
    consistent hashing
    => 9001
    30010
    6010000
    rediskey
    save 900 1save 300 10save 60 10000
    dbfilename dump.rdb

    slaveof 192.168.1.2 6379 => REDISMASTER

    MASTERSLAVE
    MASTER
    SLAVEREDIS
  • Redis
    masterauth =>

    requirepass=> )
    rdbcompression => yes
    maxclients =>
    appendonly=>

    redissave
    no
    appendfsync => 3
    no
    alwaysfsync()
    everysec
    vm-enabled
  • Redis-
    https://github.com/antirez/redis/raw/master/design-documents/REDIS-CLUSTER
    slave
    slave
    slave
    slave
    Sample demo,

    master
    master
    master
    NO PRODUCT !
    read
    write

    CONSISTENT HASH /
    client
    client
    client
    SESSION
  • Redis
    Language Support
    Ruby, Python, PHP, Erlang,
    Tcl, Perl, Lua, Java, Scala,
    Clojure, C#, C/C++,
    JavaScript/Node.js, Haskell,
    IO, Go
  • Redis
    Why?
    6379
    6379MERZ
    MERZAlessia Merz
  • Redis
    Redis?
    1http://code.google.com/p/redis/
    2http://redis.io
    3http://antirez.com/
    4http://www.google.com
  • END
    &
    QA