MCAS supports a Python-based client access. This can be accessed through the 'mcas-shell' program or included directly in a Python program.
Note: make sure dist/lib is added to the library path (LD_LIBRARY_PATH)
./dist/bin/mcas-shell
session = mcas.Session(ip="10.0.0.21", port=11911)
pool = session.create_pool("myPool",int(2e6),100)
pool = session.open_pool("myPool")
Key parameter is a string. Value parameter is a string or a byte array.
pool.put('key9','The Cute Little Dog')
Direct, zero-copy put can be applied to byte arrays
pickled_item = pickle.dumps(item)
pool.put_direct(keyname, bytearray(pickled_item))
myval = pool.get('key9')
Direct get:
bytearray_item = pool.get_direct(keyname)
return pickle.loads(bytes(bytearray_item))
If the index component is loaded, then keys can be 'searched':
print(get_keys(pool, "regex:.*"))
print(get_keys(pool, "next:"))
print(get_keys(pool, "prefix:tre"))
In find_key the offset variable is the position to start searching from, the returned out position plus one in the pair should be used to continue the search
(k, offset) = pool.find_key("prefix:tre"), offset)
Example function to get list of keys:
def get_keys(pool, expr):
result = []
offset=0
print(expr)
(k,offset)=pool.find_key(expr, offset)
while k != None:
result.append(k)
offset += 1
(k, offset) = pool.find_key(expr, offset)
return result
Length and crc32 attributes can be fetched:
print('Len: %d' % pool.get_attribute('array0','length'))
print('Crc: %x' % pool.get_attribute('array0','crc32'))
print('Size enquiry:%d' % pool.get_size('array0'))
Get number of objects in a pool:
print(pool.count())
pool.close()