zoukankan      html  css  js  c++  java
  • Redis-PHP-Hash 表相关API

    Hashes 相关
    ================================
    hDel - 删除一个哈希 key
    hExists - 检查哈希 key是否存在
    hGet - 获得某哈希 key 的值
    hGetAll - 获得一个哈希表中所有的 key 和 value
    hIncrBy - 给哈希表中某 key 增加一个整数值
    hIncrByFloat - 给哈希表中某 key 增加一个浮点数值
    hKeys - 获得哈希表中所有的 key
    hLen - 哈表中 key 的数量
    hMGet - 获得哈希表中多个 key 的值
    hMSet - 给哈希表设置多个 key 的值
    hSet - 给哈希表中某个 key 设置值
    hSetNx - 当哈希表中不存在某 key 时,给该 key 设置一个值
    hVals - 获得哈希表中所有的值
     
    hSet
    -----------------------------------
    给哈希表中某个 key 设置值.如果值已经存在, 返回 false
     
    参数:
    key 哈希表名
    hashKey
    value
     
    返回值:
    LONG 如果成功设置,返回 1, 如果 key 已经存在,会替换成新值,且返回 0。失败返回 0
     
    示例:
    $redis->delete('h')
    $redis->hSet('h', 'key1', 'hello');
    $redis->hGet('h', 'key1');
     
    $redis->hSet('h', 'key1', 'plop');
    $redis->hGet('h', 'key1');
     
    hSetNx
    -----------------------------------
    当哈希表中不存在某 key 时,给该 key 设置一个值
     
    参数:
    key 哈希表名
    hashKey
    value
     
    返回值:
    BOOL: 成功返回 TRUE. 失败返回 FALSE.
     
    示例:
    $redis->delete('h')
    $redis->hSetNx('h', 'key1', 'hello');
    $redis->hSetNx('h', 'key1', 'world');
     
    hGet
    -----------------------------------
    获得某哈希 key 的值.如果 hash 表不存在或对应的 key 不存在,返回 false
     
    参数:
    key
    hashKey
     
    返回值:
    STRING ,如果 hash 表不存在或对应的 key 不存在,返回 false
     
    示例:
    $redis->delete('h')
    $redis->hSet('h', 'key1', 'hello');
    $redis->hGet('h', 'key1');
     
    hLen
    -----------------------------------
    哈表中 key 的数量
     
    参数:
    key
     
    返回值:
    LONG 哈表中 key 的数量.如果 hash 表不存在,或者对应的 key 的值不是 hash 类型,返回 false
     
    示例:
    $redis->delete('h')
    $redis->hSet('h', 'key1', 'hello');
    $redis->hSet('h', 'key2', 'plop');
    $redis->hLen('h');
     
    hDel
    -----------------------------------
    删除一个哈希 key.如果 hash 表不存在或对应的 key 不存在,返回 false
     
    参数:
    key
    hashKey
     
    返回值:
    BOOL: 成功返回 TRUE. 失败返回 FALSE.
     
    示例:
    $redis->delete('h')
    $redis->hSet('h', 'key1', 'hello');
    $redis->hSet('h', 'key2', 'plop');
    $redis->hSet('h', 'key2');
     
    hKeys
    -----------------------------------
    获得哈希表中所有的 key
     
    参数:
    Key: key
     
    返回值:
    数组
     
    示例:
    $redis->delete('h');
    $redis->hSet('h', 'a', 'x');
    $redis->hSet('h', 'b', 'y');
    $redis->hSet('h', 'c', 'z');
    $redis->hSet('h', 'd', 't');
    var_dump($redis->hKeys('h'));
     
    输出:
    array(4) {
      [0]=>
      string(1) "a"
      [1]=>
      string(1) "b"
      [2]=>
      string(1) "c"
      [3]=>
      string(1) "d"
    }
    顺序是随机的
     
    hVals
    -----------------------------------
    获得哈希表中所有的值
     
    参数:
    参数:
    Key
     
    返回值:
    数组
     
    示例:
    $redis->delete('h');
    $redis->hSet('h', 'a', 'x');
    $redis->hSet('h', 'b', 'y');
    $redis->hSet('h', 'c', 'z');
    $redis->hSet('h', 'd', 't');
    var_dump($redis->hVals('h'));
     
    输出:
    array(4) {
      [0]=>
      string(1) "x"
      [1]=>
      string(1) "y"
      [2]=>
      string(1) "z"
      [3]=>
      string(1) "t"
    }
    顺序是随机的
     
    hGetAll
    -----------------------------------
    获得一个哈希表中所有的 key 和 value
     
    示例:
    $redis->delete('h');
    $redis->hSet('h', 'a', 'x');
    $redis->hSet('h', 'b', 'y');
    $redis->hSet('h', 'c', 'z');
    $redis->hSet('h', 'd', 't');
    var_dump($redis->hGetAll('h'));
     
    输出:
    array(4) {
      ["a"]=>
      string(1) "x"
      ["b"]=>
      string(1) "y"
      ["c"]=>
      string(1) "z"
      ["d"]=>
      string(1) "t"
    }
    顺序是随机的
     
    hExists
    -----------------------------------
    检查哈希 key是否存在
     
    参数:
    key
    memberKey
     
    返回值:
    BOOL: 存在返回 true, 不存在返回 false
     
    示例:
    $redis->hSet('h', 'a', 'x');
    $redis->hExists('h', 'a');
    $redis->hExists('h', 'NonExistingKey');
     
    hIncrBy
    -----------------------------------
    给哈希表中某 key 增加一个整数值
     
    参数:
    key
    member
    value: (integer) 要增加的整数值
     
    返回值:
    LONG 增加后的值
     
    示例:
    $redis->delete('h');
    $redis->hIncrBy('h', 'x', 2);
    $redis->hIncrBy('h', 'x', 1);
     
    hIncrByFloat
    -----------------------------------
    给哈希表中某 key 增加一个浮点数值
     
    参数:
    key
    member
    value: (float) 要增加的浮点数值
     
    返回值:
    FLOAT 增加后的值
     
    示例:
    $redis->delete('h');
    $redis->hIncrByFloat('h','x', 1.5);
    $redis->hIncrByFLoat('h', 'x', 1.5);
    $redis->hIncrByFloat('h', 'x', -3.0);
     
    hMSet
    -----------------------------------
    给哈希表设置多个 key 的值
     
    参数:
    key
    members: key → value array
     
    返回值:
    BOOL
     
    示例:
    $redis->delete('user:1');
    $redis->hMset('user:1', array('name' => 'Joe', 'salary' => 2000));
     
     
    hMGet
    -----------------------------------
    获得哈希表中多个 key 的值
     
    示例:
    $redis->delete('h');
    $redis->hSet('h', 'field1', 'value1');
    $redis->hSet('h', 'field2', 'value2');
    $redis->hmGet('h', array('field1', 'field2'));
  • 相关阅读:
    B站排行榜第一的视频,看看5W弹幕都在说些什么?
    手把手教你如何用Python获取爱奇艺电视剧弹幕数据
    Python爬虫中最重要、最常见、一定要熟练掌握的库
    机器学习
    nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
    14、ERROR: for proxy Cannot start service proxy: driver failed **** Error starting userland proxy: listen tcp 0.0.0.0:80: listen: address already in use
    13、file /usr/bin/docker from install of docker-ce-18.03.0.ce-1.el7.centos.x86_64 conflicts with file from package docker-common-2:1.13.1-203.git0be3e21.el7.centos.x86_64
    12、Error response from daemon: Get https://192.168.247.151/v2/: dial tcp 192.168.247.151:443: connect: connection refused
    Selenium无法定位元素的九种解决方案
    Linux安装Oracle数据库SQLPlus客户端
  • 原文地址:https://www.cnblogs.com/kenshinobiy/p/4613142.html
Copyright © 2011-2022 走看看