Datastore Clients¶
The main component for pulsar datastore clients is the Store
class which encapsulates the essential API for communicating and executing
asynchronous commands on remote servers.
Getting Started¶
To create a data Store client one uses the create_store()
function with a valid connection string:
>>> from pulsar.apps.data import create_store
>>> store = create_store('redis://user:password@127.0.0.1:6500/11')
>>> store.name
'redis'
>>> store.database
'11'
>>> store.dns
'redis://user:password@127.0.0.1:6500/11'
Additional parameters can be passed via the connection string or as key-valued parameters. For example:
>>> store = create_store('redis://user:password@127.0.0.1:6500/11',
namespace='test_')
>>> store.dns
'redis://user:password@127.0.0.1:6500/11?namespace=test_'
Connection String¶
The connection string is a way to specify the various parameters for the
data store connection. All Store support a connection string
of the form:
<scheme>://<username>:<password>@<host>/<database>?param1=...¶m2=...
where:
schemais the store namedatabaseis the database name (or number for redis)usernameis an optional database usernamepasswordis an optional database password
Implement a Store¶
When implementing a new Store there are several methods which need
to be covered:
ping()to check if the server is availableconnect()to create a new connectionexecute()to execute a command on the store server
All registered data stores are stored in the data_stores dictionary:
from pulsar.apps.data import data_stores
Pulsar provides two implementations, the redis client and the pulsards client.
API¶
The main component of the data store API is the create_store()
function which creates in one function call a new Store
object which can be used to interact with the backend database.
Create store¶
-
pulsar.apps.data.store.create_store(url, **kw)[source]¶ Create a new
Storefor a validurl.Parameters: - url –
a valid
urltakes the following forms:pulsar://user:password@127.0.0.1:6410
redis://user:password@127.0.0.1:6500/11?namespace=testdb
- kw – additional key-valued parameters to pass to the
Storeinitialisation method. It can contains parameters such asdatabase,userandpasswordto override theurlvalues. Additional parameters are processed by theStore._init()method.
Returns: a
Store.- url –
Start store¶
-
pulsar.apps.data.pulsards.startds.start_store(app, url, workers=0, **kw)[source]¶ Equivalent to
create_store()for most cases excepts when theurlis for a pulsar store not yet started. In this case, aPulsarDSis started.
Register a new store¶
Store¶
-
class
pulsar.apps.data.store.Store(name, host, database=None, user=None, password=None, encoding=None, **kw)[source]¶ Base class for an asynchronous data stores.
A
Storeshould not be created directly, the high levelcreate_store()function should be used instead.-
_host¶ The remote host, tuple or string
-
_user¶ The user name
-
_password¶ The user password
-
name¶ Store name
-
database¶ Database name/number associated with this store.
-
encoding¶ Store encoding (usually
utf-8)
-
dns¶ Domain name server
-
urlparams¶ url parameters in dns query
-
RemoteStore¶
-
class
pulsar.apps.data.store.RemoteStore(name, host, loop=None, protocol_factory=None, **kw)[source]¶ Base class for remote data stores.
It is an
Producerfor accessing and retrieving data from remote data servers such as redis.