pygibson 0.2.1

Last updated:

0 purchases

pygibson 0.2.1 Image
pygibson 0.2.1 Images
Add to Cart

Description:

pygibson 0.2.1

Version:
0.2.1



pygibson
Python client for gibson cache server.

Which python versions are supported?
Currently testsuite runs with python 2.6, 2.7, 3.2 and 3.3.
All tests are passing successfully with PyPy 2.0.2 but since pygibson is
implemented as CPython extension it’s not recommended to use it with PyPy. We
need to find some workaround to this later.


How to install?
pip install pygibson
or
git clone https://github.com/bak1an/pygibson.git
cd pygibson
git submodule update --init
python setup.py install


How to use?
from pygibson import Client
from pygibson import NotFoundError

cl = Client() # defaults, 127.0.0.1:10128, timeout=1000
cl2 = Client(host="192.168.1.33", port=4321, timeout=1500) # non defaults
cl3 = Client(unix_socket="/var/run/gibson.sock", timeout=500) # connects to unix socket with timeout set to 500

cl.set("some_key", "some_value")
print cl.get("some_key") # "some_value" will be printed
try:
cl.get("no_such_key")
except NotFoundError:
print "Yay, no such key!"


Client() class methods


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.





Exceptions
Here is a list of exceptions which are available in pygibson module:


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






Roadmap

Connection pool
Ability to connect multiple servers
Better pypy support



License
pygibson code is distributed under MIT license conditions, see LICENSE for
details.
pygibson distribution includes bundled copy of libgibsonclient library which is written by
Simone Margaritelli and distributed on terms of BSD license.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.