Running CupidDB Server
The easiest way to run a CupidDB server is by using Docker. You can simply start a server with the following command:
docker run --rm -p 5995:5995 cupiddb/cupiddb:latest
Using CupidDB to Store DataFrame
CupidDB is ideal for storing DataFrames. When you store a DataFrame, CupidDB saves the data in Apache Arrow format.
This allows the client to request the DataFrame with filter logic, which is executed server-side, reducing data transfer over the network.
More importantly, data serialization and deserialization are avoided since CupidDB natively stores and transfers data in Apache Arrow format.
from pycupiddb import CupidClient, RowFilter
import pandas as pd
df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]})
cupid_client = CupidClient(host='localhost', port=5995)
cupid_client.set(key='key', value=df)
df = cupid_client.get_dataframe(key='key')
# Or using filters
filters = [
RowFilter(column='b', logic='gte', value=5, data_type='int')
]
df = cupid_client.get_dataframe(
key='key',
columns=['a'],
filters=filters,
)
print(df)
# You should see
# a
# 0 2
# 1 3
Using CupidDB as a Cache Server
CupidDB can be used as a cache server. It follows the get and set API you might already be familiar with.
cupid_client.set(key='key', value='value', timeout=60)
result = cupid_client.get(key='key')
print(result)
# This should print out "value"
cupid_client.set(key='key', value=1, timeout=60)
result = cupid_client.incr(key='key')
print(result) # This should print out 2
result = cupid_client.incr(key='key', delta=5)
print(result) # This should print out 7