MemcacheQ - Simple Queue Service over Memcache

本文介绍了一款名为MemcacheQ的消息队列系统,提供了详细的安装步骤、命令使用方法及实例代码,包括如何通过PHP memcache将消息添加到队列,以及从队列头部获取消息。此外,文章还解释了消息存储限制和一些额外的提示,如查看当前队列、删除队列等。最后,提供了反馈渠道和官方更新日期。
摘要由CSDN通过智能技术生成

Features

  • damn simple
  • very fast
  • multiple queue
  • concurrent well
  • memcache protocol compatible

Getting Started

Installation

See: <http://memcachedb.org/memcacheq/INSTALL.html>

Please take a look at 'ChangLog' file in the distribution, see what's new.

Commands

Only two commands are used to operate the queue:

Append a message to the tail of queue:

set <queue name> <flags> 0 <message_len>\r\n
<put your message body here>\r\n
STORED\r\n

Note: MQ will create a new queue automatically if your queue is not existed. The original 'expire time' field is ignored by server.

Consume a message from the head of queue:

get <queue name>\r\n
VALUE <queue name> <flags> <message_len>\r\n
<your message body will come here>\r\n
END\r\n

Examples

Assuming you are using PHP memcache<http://www.php.net/memcache>:

<?php
/* connect to memcached server */
$memcache_obj = memcache_connect('memcacheq_host', 21201);

/* append a message to queue */
memcache_set($memcache_obj, 'demoqueue1', 'message body here', 0, 0);

/* consume a message from 'demoqueue1' */
memcache_get($memcache_obj, 'demoqueue1');

memcache_close($memcache_obj);
?>

Limitation

The message body is stored in Berkeley DB with fixed length. Any message that is shorter than the declared length will automatically be padded with space character (0x20 in the ASCII character set).

In Berkeley DB, as the official document refers,

"For the Queue access method, the record length must be enough smaller than the database's page size that at least one record plus the database page's metadata information can fit on each database page."

"The minimum page size is 512 bytes, the maximum page size is 64K bytes, and the page size must be a power-of-two."

So we have a limit on the message body size with a max of a bit less than 64K.

Other tips

use 'stats queue' to see your current queues:

$ telnet 127.0.0.1 22201
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
stats queue
STAT test1
STAT test2
STAT test3
STAT test4
END

delete a queue:

$ telnet 127.0.0.1 22201
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
delete test1
DELETED

'db_stat' a queue to see how many records now in:

$ cd <your queue dir>
$ /usr/local/BerkeleyDB.4.7/bin/db_stat -d test1
Mon Sep 22 20:25:56 2008      Local time
42253   Queue magic number
4       Queue version number
1024    Fixed-length record size
0x20    Fixed-length record pad
4096    Underlying database page size
131072  Underlying database extent size
100000  Number of records in the database
33334   Number of database pages
2048    Number of bytes free in database pages (99% ff)
1       First undeleted record
100001  Next available record number

Feedback

MemcacheDB mailing list now hosts on Google Group: http://groups.google.com/group/memcachedb

Please report your bugs and issues to the Maillist.

Last updated by stvchu: 09/22/2008

to support MemcacheQ if it makes your life easy!
From: http://memcachedb.org/memcacheq/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值