zoukankan      html  css  js  c++  java
  • redis 学习笔记(string)

    string

      set key value //存入字符串键值对

      mset key value [key value ...] //批量存储字符串键值对

      setnx key value //存入一个不存在的字符串键值对

      get key //获取一个字符串键值

      mget key [key...] //批量获取字符串键值

      del key [key...] //删除一个键

      expire key seconds //设置一个键的过期时间(秒)

    原子加减

      incr key //将key中存储的数字值加1

      decr key //将key中存储的数字值减1

      incrby key increment //将key所存储的值加上increment

      decrby key decrement //将key所存储的值减去decrement

    单值缓存:

      set key value

      get key

    对象缓存:

      set user:1 value(json)

      mset user:1:name username1 user:1:balance 1000

    id name balance
    1 username1 1000
    2 username2 2000

      mget user:1:name user:1:balance

    分布式锁:

      setnx product:10001 true //返回1代表获取锁成功

      setnx product:10001 true //返回0代表获取锁失败

      。。。执行业务操作

      del product:10001  //执行完业务释放锁

      set product:10001 true ex 10 nx  //防止程序意外终止导致死锁

  • 相关阅读:
    python 类
    hdu 5761 Rowe Bo 微分方程
    calendar 示例
    hdu 5753 Permutation Bo
    hdu 5752 Sqrt Bo
    finally 语句
    throws 和 throw
    python打开.pkl的文件并显示里面的内容
    Python 类变量,成员变量,静态变量,局部变量
    python 实例方法,类方法,静态方法,普通函数
  • 原文地址:https://www.cnblogs.com/lfhphp/p/12291625.html
Copyright © 2011-2022 走看看