zoukankan      html  css  js  c++  java
  • redis-key(键)

    #  删除单个 key
    
    redis> SET name huangz
    OK
    
    redis> DEL name
    (integer) 1
    
    
    # 删除一个不存在的 key
    
    redis> EXISTS phone
    (integer) 0
    
    redis> DEL phone # 失败,没有 key 被删除
    (integer) 0
    
    
    # 同时删除多个 key
    
    redis> SET name "redis"
    OK
    
    redis> SET type "key-value store"
    OK
    
    redis> SET website "redis.com"
    OK
    
    redis> DEL name type website
    (integer) 3

    # 序列化给定 key ,并返回被序列化的值
    redis> SET greeting "hello, dumping world!"
    OK
    
    redis> DUMP greeting
    "x00x15hello, dumping world!x06x00Exa0Zx82xd8rxc1xde"
    
    redis> DUMP not-exists-key //如果是不存在的键 返回nil
    (nil)

    # 检查给定 key 是否存在
    redis> SET db "redis"
    OK
    
    redis> EXISTS db
    (integer) 1
    
    redis> DEL db
    (integer) 1
    
    redis> EXISTS db
    (integer) 0

    # 为给定 key 设置生存时间
    redis> SET cache_page "www.google.com"
    OK
    
    redis> EXPIRE cache_page 30  # 设置过期时间为 30 秒
    (integer) 1
    
    redis> TTL cache_page    # 查看剩余生存时间
    (integer) 23
    
    redis> EXPIRE cache_page 30000   # 更新过期时间
    (integer) 1
    
    redis> TTL cache_page
    (integer) 29996

    # EXPIREAT 的作用和 EXPIRE 类似 ,都用于为 key 设置生存时间。不同在于,它接受UNIX 时间戳
    redis> SET cache www.google.com
    OK
    
    redis> EXPIREAT cache 1355292000     # 这个 key 将在 2012.12.12 过期
    (integer) 1
    
    redis> TTL cache
    (integer) 45081860

    # 查找所有符合给定模式 pattern 的 key 。
    redis> MSET one 1 two 2 three 3 four 4  # 一次设置 4 个 key
    OK
    
    redis> KEYS *o*
    1) "four"
    2) "two"
    3) "one"
    
    redis> KEYS t??
    1) "two"
    
    redis> KEYS t[w]*
    1) "two"
    
    redis> KEYS *  # 匹配数据库内所有 key
    1) "four"
    2) "three"
    3) "two"
    4) "one"
     
  • 相关阅读:
    mysql cpu 占用高
    使用cron命令配置定时任务(cron jobs)
    python 获取时间
    linux 免密码登陆
    linux 查看登录日志
    shizhong
    正则(?is)
    python shell
    linux 时间设置
    java获取当前时间前一周、前一月、前一年的时间
  • 原文地址:https://www.cnblogs.com/TinyMing/p/7100111.html
Copyright © 2011-2022 走看看