Memcached Replace操作的Python示例

替换操作将更改现有键值。如果键值不存在,我们将得到如下响应 未存储 . 其语法类似于add。

null
replace key flags expiretime bytesvalue
  • 代替 是动词的名称
  • 钥匙 更换的钥匙
  • 旗帜 作为标志
  • 过期时间 存储在memcached中的键值的时间范围
  • 字节 新值的大小
  • 价值 新价值

让我们添加新数据 并检查它是否存在。

add poftut 0 100 4 test STORED get poftut VALUE poftut 0 4 test END

我们将替换 波夫图特 具有新值的键值。

replace poftut 0 100 7 testnew STORED
  • 代替 动词
  • 波夫图特 是我们要替换其数据的关键
  • 0 旗帜
  • 100 第二次我们要举行新的 关键字值
  • 7 是新值的大小
  • 测试新 是新的价值
  • 存储 替换操作成功的结果

Python应用程序

import memcache client=memcache.Client([('127.0.0.1',11211)])  #Add samp={"poftut2":"test"} client.add("sample",samp,time=1000)  #Replace samp={"poftut":"testnew"} client.replace("sample",samp,time=1000) print(client.get("sample"))

我们把代码保存为文件名 替换.py。 在运行代码之后,我们得到了输出。

$ python3 replace.py{'poftut': 'testnew'}

相关文章: 如何设置、获取和更改Bash环境变量?

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享