Gibson缓存服务器的Python客户端
pygibson的Python项目详细描述
Version: | 0.2.1 |
---|
皮吉布森
用于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 name | Parameters | Description |
---|---|---|
__init__ | host=”127.0.0.1”, port=10128, unix_socket=None, timeout=1000 | If 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. |
set | key, value, ttl=0 | Required parameters are key and value. Optional parameter ttl can be used to set entry TTL in seconds. Default is 0, which means infinite TTL. |
mset | prefix, value | Set value for all keys which are starting with prefix. This method will raise NotFoundError if there are no keys starting with prefix at server. |
ttl | key, ttl | Set TTL in seconds for key. |
mttl | prefix, ttl | Set TTL in seconds for all keys string with prefix. |
get | key | Get value for given key. |
mget | prefix | Get values for keys starting with prefix. |
dl | key | Delete given key from server. Renamed to dl to avoid clashes with python’s keyword. |
mdl | prefix | Delete keys starting with prefix from server. |
inc | key | Increment key by 1. |
minc | prefix | Increment keys starting with prefix by 1. |
dec | key | Decrement key by 1. |
mdec | prefix | Decrement keys starting with prefix by 1. |
lock | key, time | Lock key for time seconds. Any write operations to that key will fail and LockedError will be raised. |
unlock | key | Unlock key. |
mlock | prefix, time | Lock keys starting with prefix for time seconds. |
munlock | prefix | Unlock keys starting with prefix. |
count | prefix | Get count of keys starting with prefix. |
meta | key, field | Get 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 ;) |
keys | prefix | Get list of keys starting with prefix. |
stats | Get useful statistics from server. See gibson protocol docs for details. | |
ping | Ping server. Raise PyGibsonError if failed. | |
quit | Disconnect. |
NOTE: values packed in bytes are returned from get, mget and keys under python 3.
异常
以下是pygibson模块中可用的异常列表:
Exception | Description |
---|---|
PyGibsonError | Generic 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 |
NotFoundError | Not found error. Raised when REPL_ERR_NOT_FOUND received from server |
NaNError | Not a number. Raised from inc, minc, dec and mdec when incrementing/decrementing not a numerical values |
NoMemoryError | Raised when server has no free memory for your stuff |
LockedError | Raised when values that you are trying to modify are locked |
路线图
- 连接池
- 能够连接多个服务器
- 更好的Pypy支持
许可证
Pygibson代码是在MIT许可条件下发布的,请参见许可 细节。
pygibson发行版包含libgibsonclient库的捆绑副本,该库由 Simone Margaritelli,根据BSD许可条款发行。