zoukankan      html  css  js  c++  java
  • redis基本数据结构-散列

    redis基本数据结构-hash散列数据结构 

    1. 基本情况

    1. 一个散列键最多可以包含 2^32 - 1 个字段
    2. 散列类型不能嵌套其他数据类型

     

    2.命令

     

    • 插入/更新字段
    hset key field1 value1
    hset car name BMP
    
    hset car price 30

     插入返回1  更新返回0

     

    • 插入/更新多个字段
    hmset key field1 value1 filed2 value2 ...
    hmet car name AUDI price 100

     

    • 获取字段值
    hget key filed
    hget car name

    返回AUDI

    hget car price

    返回 "100"

     

    • 获取多个字段的值
    hmget key filed1 filed2 ..
    hmget car name price

     返回

    "AUDI"

    "100"

     

    • 返回键的所有字段和值
    hgetall key
    hgetall car

     返回

    "price"

    "500"

    "name"

    "AUDI"

     

    • 判断字段是否存在
    hexists key filed
    hexists car name

    返回1

    hexists car  factory

    返回0

     

    • 给字段增加数值
    hincrby key filed  increment
    hincrby car price 20

    返回"120"

     

    • 删除字段
    hdel key field1  field2 field3 ...
    hdel car  price

     删除car的price字段 返回1

    删除不存在的字段返回0

     

    • 当字段不存在时赋值(* 该操作为原子操作)
    hsetnx key filed value
    hsetnx car factory madeinchina 

     当car不存在字段factory时添加字段factory并赋值madeinchina

     

    • 获取键的所有字段名
    hkeys key
    hkeys car

     返回

    "name"

    "price"

    "factory"

     

    • 获取键的所有字段值
    hvals key
    hvals car

     返回

    "AUDI"

    "120"

    "madeinchina"

     

    • 获取键的字段数量
    hlen key 
    hlen car

     返回3 

     

    **********************技术交流请 email:cuihao0532#163.com 欢迎转载,转载请注明出处!***************************** 如果对本文满意请扫描文章左侧【二维码添加微信】获取更多好玩、有趣、有益、有营养的料, 你我共同成长!Y(^_^)Y
  • 相关阅读:
    JS的IE和FF兼容性问题汇总
    解决flash挡住层的问题
    javascript 代码优化工具 UglifyJS
    理解面向对象
    js中的等号与非等号
    js 的数据类型转换
    js优化 ----js的有序加载
    各浏览器对页面外部资源加载的策略
    js 执行效率
    脚本的加载,解析,与执行
  • 原文地址:https://www.cnblogs.com/cuish/p/14687532.html
Copyright © 2011-2022 走看看