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>
  • 相关阅读:
    Network | DNS
    Network | Cookie and Session
    Network | HTTP protocol
    全源最短路径
    最小生成树
    最小生成树
    10. Regular Expression Matching *HARD*
    4. Median of Two Sorted Arrays *HARD* -- 查找两个排序数组的中位数(寻找两个排序数组中第k大的数)
    44. Wildcard Matching *HARD*
    43. Multiply Strings 字符串表示的大数乘法
  • 原文地址:https://www.cnblogs.com/no-celery/p/13704062.html
Copyright © 2011-2022 走看看