zoukankan      html  css  js  c++  java
  • Redis教程7-键(key)常用命令使用参考4

    1.TTL

    TTL key

    以秒为单位,返回给定 key 的剩余生存时间(TTL, time to live)。

    可用版本:>= 1.0.0

    时间复杂度:O(1)

    返回值:

    当 key 不存在时,返回 -2 。
    当 key 存在但没有设置剩余生存时间时,返回 -1 。
    否则,以秒为单位,返回 key 的剩余生存时间。
    在 Redis 2.8 以前,当 key 不存在,或者 key 没有设置剩余生存时间时,命令都返回 -1
    localhost:6379> set name redis666
    OK
    localhost:6379> set age 66
    OK
    localhost:6379> expire age 3000    // age设置过期时间3000s
    (integer) 1
    localhost:6379> ttl name   // name没有过期时间, 返回-1
    (integer) -1
    localhost:6379> ttl age    // age剩余过期时间2995s
    (integer) 2995 
    localhost:6379> ttl address    // 没有此key, 返回-2
    (integer) -2
    localhost:6379>

    2.TYPE

    TYPE key

    返回 key 所储存的值的类型。

    可用版本:>= 1.0.0

    时间复杂度:O(1)

    返回值:

    none (key不存在)
    string (字符串)
    list (列表)
    set (集合)
    zset (有序集)
    hash (哈希表)
    localhost:6379> set name redis666
    OK
    localhost:6379> lpush age 11 12 13
    (integer) 3
    localhost:6379> hmset user_info name tom age 66
    OK
    localhost:6379> sadd tel 110 120
    (integer) 2
    localhost:6379> type name    // string
    string
    localhost:6379> type age    // list
    list
    localhost:6379> type user_info    // hash
    hash
    localhost:6379> type tel    // set
    set
    localhost:6379>
  • 相关阅读:
    idea jvm 优化
    MYSQL
    mysql
    window.print() 去掉页眉页脚及打印链接【转载】
    eclipse maven插件问题:error occurred while automatically activating bundle org.eclipse.m2e.core.ui (525)
    数据挖掘的数据集资源 --转载
    Python分析《武林外传》 -----转载
    难题
    cookie格式化
    python 中变量的命名规范
  • 原文地址:https://www.cnblogs.com/no-celery/p/13704062.html
Copyright © 2011-2022 走看看