zoukankan      html  css  js  c++  java
  • python连redis测试





    python 版本 3.x
    执行环境需要安装redis模块: pip install redis

    执行脚本前,有redis-cli中查询key值:

     执行脚本:


    ****************************** redis的乐观锁 脚本如下 *****************************
    import redis
    def key_for(user_id):
    return "account_{}".format(user_id)

    def double_account(client, user_id):
    key = key_for(user_id)
    while True:
    client.watch(key)
    value = int(client.get(key))
    value *=2
    pipe = client.pipeline(transaction=True)
    pipe.multi()
    pipe.set(key,value)
    try:
    pipe.execute()
    break
    except redis.WatchError:
    continue
    return int(client.get(key))

    if __name__ == "__main__":
    client = redis.StrictRedis(host="192.168.1.100", port = 7000)
    user_id = "abc"
    client.setnx(key_for(user_id),5)
    print (double_account(client,user_id))
  • 相关阅读:
    安装Hive2及配置HiveSever2
    sqoop语句
    Sqoop配置
    IO流的概述
    List集合的简单使用
    包装类
    访问权限修饰符
    接口
    抽象类
    final关键字
  • 原文地址:https://www.cnblogs.com/linlianhuan/p/9794395.html
Copyright © 2011-2022 走看看