Gibson缓存服务器的Python客户端

pygibson的Python项目详细描述


Version:0.2.1

build_status

皮吉布森

用于gibson缓存服务器的python客户端。

支持哪些python版本?

目前,testsuite使用python 2.6、2.7、3.2和3.3运行。

pypy 2.0.2成功通过了所有测试,但由于pygibson是 实现为cpython扩展,不建议与pypy一起使用。我们 以后需要找到解决办法。

如何安装?

pip install pygibson

git clone https://github.com/bak1an/pygibson.git
cd pygibson
git submodule update --init
python setup.py install

如何使用?

frompygibsonimportClientfrompygibsonimportNotFoundErrorcl=Client()# defaults, 127.0.0.1:10128, timeout=1000cl2=Client(host="192.168.1.33",port=4321,timeout=1500)# non defaultscl3=Client(unix_socket="/var/run/gibson.sock",timeout=500)# connects to unix socket with timeout set to 500cl.set("some_key","some_value")printcl.get("some_key")# "some_value" will be printedtry:cl.get("no_such_key")exceptNotFoundError:print"Yay, no such key!"

client()类方法

Method nameParametersDescription
__init__host=”127.0.0.1”, port=10128, unix_socket=None, timeout=1000If unix_socket is None connects to host:port, otherwise connects to given unix_socket. timeout parameter can be used to set timeout for IO operations. Default is 1000ms.
setkey, value, ttl=0Required parameters are key and value. Optional parameter ttl can be used to set entry TTL in seconds. Default is 0, which means infinite TTL.
msetprefix, valueSet value for all keys which are starting with prefix. This method will raise NotFoundError if there are no keys starting with prefix at server.
ttlkey, ttlSet TTL in seconds for key.
mttlprefix, ttlSet TTL in seconds for all keys string with prefix.
getkeyGet value for given key.
mgetprefixGet values for keys starting with prefix.
dlkeyDelete given key from server. Renamed to dl to avoid clashes with python’s keyword.
mdlprefixDelete keys starting with prefix from server.
inckeyIncrement key by 1.
mincprefixIncrement keys starting with prefix by 1.
deckeyDecrement key by 1.
mdecprefixDecrement keys starting with prefix by 1.
lockkey, timeLock key for time seconds. Any write operations to that key will fail and LockedError will be raised.
unlockkeyUnlock key.
mlockprefix, timeLock keys starting with prefix for time seconds.
munlockprefixUnlock keys starting with prefix.
countprefixGet count of keys starting with prefix.
metakey, fieldGet useful info about key. Allowed values for field are: ‘size’, ‘encoding’ ‘access’, ‘created’, ‘ttl’, ‘left’, ‘lock’. Click method’s name in first column for details ;)
keysprefixGet list of keys starting with prefix.
statsGet useful statistics from server. See gibson protocol docs for details.
pingPing server. Raise PyGibsonError if failed.
quitDisconnect.
NOTE:values packed in bytes are returned from get, mget and keys under python 3.

异常

以下是pygibson模块中可用的异常列表:

ExceptionDescription
PyGibsonErrorGeneric error. raised when REPL_ERR received from server or any other error occurred (connection refused, timeout, etc). All other pygibson exceptions are subclassed from this one
NotFoundErrorNot found error. Raised when REPL_ERR_NOT_FOUND received from server
NaNErrorNot a number. Raised from inc, minc, dec and mdec when incrementing/decrementing not a numerical values
NoMemoryErrorRaised when server has no free memory for your stuff
LockedErrorRaised when values that you are trying to modify are locked

路线图

  • 连接池
  • 能够连接多个服务器
  • 更好的Pypy支持

许可证

Pygibson代码是在MIT许可条件下发布的,请参见许可 细节。

pygibson发行版包含libgibsonclient库的捆绑副本,该库由 Simone Margaritelli,根据BSD许可条款发行。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
在ElasticSearch中将SearchHit转换为Java对象   第三方库类的java重写XmlAdapter   java如何使用动画类获得平滑的动画效果?   Java PDFBox如果文本内容超过PDF的第一页,如何添加新页面?   Java二叉搜索树u根到最近叶的距离   java什么是diff Scanner和BufferedReader   java如何设计不生成并行数组的程序   java多次声明变量会降低执行速度吗?   java如何使用JXLAPI读取下拉列表的值   多线程为什么自定义阻塞队列在Java中不是线程安全的   java在一个变量中每输入1000个单位,就从另一个变量中减去1?   java Mapstruct通用映射器   Java中的类能否确定它是否已被修改?   java如何在MogoOperations聚合函数中定义输出类型?