使用Python的Memcached添加操作示例

Add operation is similar to the set operation but the difference is that is a key is all ready exists NOT_STORED code is returned. This makes add operation more reliable than set and aware of the key overwrite. Syntax is like below

添加操作类似于设置操作,但区别在于,键已全部准备就绪,并且已返回NOT_STORED代码。 这使添加操作比设置和意识到密钥覆盖更可靠。 语法如下

add key flags expiretime bytes
value
  • key is the identifier of the value

    是值的标识符

  • flags is operations details

    标志是操作详细信息

  • expiretime  is the time the key-value will be hold in memory.

    expiretime是键值将保留在内存中的时间。

  • bytes is total size of the value as byte

    个字节是该值的总大小,以字节为单位

  • value is data we want to save

    价值是我们要保存的数据

Let’s try this with our simple telnet connection.

让我们通过简单的telnet连接尝试一下。

add poftut 0 100 4 
test 
STORED 
add poftut 0 100 4 
test 
NOT_STORED
  • potut is out key

    关键是关键

  • is flag

    0是标志

  • 100 is the timeout for the key-value

    100是键值的超时

  • is the size of the value

    4是数值的大小

  • test is our value

    测试是我们的价值

  • STORED successfully saved

    成功保存

  • NOT_STORED failed to save

    NOT_STORED保存失败

As we see when we try again the same key we get a response NOT_STORED like we stated before.

正如我们看到的,当我们再次尝试相同的键时,将得到一个NOT_STORED的响应,就像我们之前所说的那样。

Python应用 (Python Application)

This application will import memcache library and then create a client object where we will provide some configuration like the memcache host IP address or hostname and the port number. We will than create a python dictionary which holds some value-key pairs and than use client object add function to put the samp dictionary values to the memcache server.

此应用程序将导入memcache库,然后创建一个客户端对象,在此处我们将提供一些配置,例如内存缓存主机IP地址或主机名以及端口号。 我们将创建一个包含一些值-密钥对的python字典,然后使用client对象add功能将samp字典值放入内存缓存服务器。

import memcache 
client=memcache.Client([('127.0.0.1',11211)]) 
samp={"poftut2":"test"} 
client.add("sample",samp,time=1000)
LEARN MORE  Memcached Get Check and Set Operation
了解更多Memcached获取检查和设置操作

翻译自: https://www.poftut.com/memcached-add-operation-python-example/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值