PHPackages                             lucinda/nosql-data-access - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. lucinda/nosql-data-access

ActiveLibrary[Caching](/categories/caching)

lucinda/nosql-data-access
=========================

API abstracting communication with NoSQL key-value store databases through a PDO-like structure

v4.1.5(3y ago)023.8k13MITPHPPHP ^8.1

Since Nov 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/aherne/php-nosql-data-access-api)[ Packagist](https://packagist.org/packages/lucinda/nosql-data-access)[ Docs](https://github.com/aherne/php-nosql-data-access-api)[ RSS](/packages/lucinda-nosql-data-access/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (38)Used By (3)

NoSQL Data Access API
=====================

[](#nosql-data-access-api)

Table of contents:

- [About](#about)
- [Configuration](#configuration)
- [Execution](#execution)
- [Installation](#installation)
- [Unit Tests](#unit-tests)
- [Examples](#examples)
- [Reference Guide](#reference-guide)

About
-----

[](#about)

This API is a ultra light weight [Data Access Layer](https://en.wikipedia.org/wiki/Data_access_layer) that acts like an equivalent of [PDO](https://www.php.net/manual/en/book.pdo.php) for NoSQL [key-value databases](https://en.wikipedia.org/wiki/Key-value_database) (aka key-value stores). As a data access layer, its purpose is to to shield complexity of working with different NoSQL vendors and provide a simple as well as elegant interface for connecting and querying. At this time, following vendors are supported:

- **APC**: an extremely fast database without persistence abilities, handled directly by PHP that uses opcode cache and data store
- **APCu**: an extremely fast database without persistence abilities, handled directly by PHP that uses only data store
- **Memcache**: a very fast database with persistence abilities, requiring you to have MemCache server installed on your machine
- **Memcached**: a very fast database with persistence abilities, requiring you to have MemCache server installed on your machine
- **Redis**: a slightly slower database with persistence abilities and many extra features, requiring you to have Redis server installed on your machine
- **Couchbase**: a slower database with persistence abilities and many extra features, requiring you to have Couchbase server installed on your machine

[![diagram](https://camo.githubusercontent.com/c0e57e0d244f4f856078187b868a9fb09c5b1f39fcec25e4306492e47a781014/68747470733a2f2f7777772e6c7563696e64612d6672616d65776f726b2e636f6d2f6e6f73716c2d646174612d6163636573732d6170692e737667)](https://camo.githubusercontent.com/c0e57e0d244f4f856078187b868a9fb09c5b1f39fcec25e4306492e47a781014/68747470733a2f2f7777772e6c7563696e64612d6672616d65776f726b2e636f6d2f6e6f73716c2d646174612d6163636573732d6170692e737667)

The whole idea of working with NoSQL databases (vendors) is reduced to following steps:

- **[configuration](#configuration)**: setting up an XML file where NoSQL vendors used by your site are configured per development environment
- **[execution](#execution)**: using [Lucinda\\NoSQL\\Wrapper](https://github.com/aherne/php-nosql-data-access-api/blob/master/src/Wrapper.php) to read above XML based on development environment, compile [Lucinda\\NoSQL\\DataSource](https://github.com/aherne/php-nosql-data-access-api/blob/master/src/DataSource.php) object(s) storing connection information and inject them statically into [Lucinda\\NoSQL\\ConnectionFactory](#class-connectionfactory) class

API is fully PSR-4 compliant, only requiring PHP8.1+ interpreter, SimpleXML extension and official extension for each vendor. To quickly see how it works, check:

- **[installation](#installation)**: describes how to install API on your computer, in light of steps above
- **[unit tests](#unit-tests)**: API has 100% Unit Test coverage, using [UnitTest API](https://github.com/aherne/unit-testing) instead of PHPUnit for greater flexibility
- **[examples](#examples)**: shows a deep example of API functionality

Configuration
-------------

[](#configuration)

To configure this API you must have a XML with a **nosql** tag inside:

```

		...

	...

```

Where:

- **nosql**: holds global connection information for NoSQL vendors used
    - {ENVIRONMENT}: name of development environment (to be replaced with "local", "dev", "live", etc)
        - **server**: stores connection information about a single vendor via attributes:
            - *name*: (optional) unique identifier. Required if multiple nosql vendors are used for same environment!
            - *driver*: (mandatory) NoSQL vendor name. Supported values: apc, apcu, memcache, memcached, redis, couchbase
            - {OPTIONS}: a list of extra attributes necessary to configure respective vendor identified by *driver* above:
                - *host*: server host name (eg: 127.0.0.1), host name and port (eg: 127.0.0.1:1234) or list of host names and ports separated by commas (eg: 192.168.1.9:1234,192.168.1.10:4567). Required unless *driver* is APC/APCu!
                - *timeout*: (not recommended) time in seconds by which idle connection is automatically closed. Not supported if *driver* is APC/APCu/Couchbase!
                - *persistent*: (not recommended) whether or not connections should be persisted across sections (value can be: 0 or 1). Not supported if *driver* is APC/APCu/Couchbase!
                - *username*: user name to use in connection. Required if *driver* is Couchbase, ignored otherwise!
                - *password*: password to use in connection. Required if *driver* is Couchbase, ignored otherwise!
                - *bucket\_name*: name of bucket (equivalent of SQL schema) where key-value pairs are stored. Required if *driver* is Couchbase, ignored otherwise!
                - *bucket\_password*: (optional) bucket password. Optional if *driver* is Couchbase, ignored otherwise!

Example:

```

```

Execution
---------

[](#execution)

Once you have completed step above, you need to run this in order to be able to connect and query database(s) later on:

```
new Lucinda\NoSQL\Wrapper(simplexml_load_file(XML_FILE_NAME), DEVELOPMENT_ENVIRONMENT);
```

This will wrap each **server** tag found for current development environment into [Lucinda\\NoSQL\\DataSource](https://github.com/aherne/php-nosql-data-access-api/blob/master/src/DataSource.php) objects and inject them statically into [Lucinda\\NoSQL\\ConnectionFactory](#class-connectionfactory) class.

Class above insures a single [Lucinda\\NoSQL\\Driver](#interface-driver) is reused per server throughout session (input-output request flow) duration when . If vendor associated is not embedded (APC/APCu) and requires a server, same object also implements [Lucinda\\NoSQL\\Server](#interface-server), which can be used in connection management.

There may be situations when abstraction provided by [Lucinda\\NoSQL\\Driver](#interface-driver) is not enough and you need to run *specific* operations known only to respective vendor. You can do so by extra **getDriver** method, available unless vendor is APC/APCu:

MethodArgumentsReturnsDescriptiongetDrivervoid[Redis](https://github.com/phpredis/phpredis#class-redis)Gets access to redis native driver if data source is redis.getDrivervoid[Memcache](https://www.php.net/manual/en/class.memcache.php)Gets access to memcache native driver if data source is memcache.getDrivervoid[Memcached](https://www.php.net/manual/en/book.memcached.php)Gets access to memcached native driver if data source is memcached.getDrivervoid[CouchbaseBucket](https://docs.couchbase.com/sdk-api/couchbase-php-client-2.0.1/classes/CouchbaseBucket.html)Gets access to couchbase native driver if data source is couchbase.Installation
------------

[](#installation)

First choose a folder where API will be installed then write this command there using console:

```
composer require lucinda/nosql-data-access
```

Then create a *configuration.xml* file holding configuration settings (see [configuration](#configuration) above) and a *index.php* file (see [initialization](#initialization) above) in project root with following code:

```
require(__DIR__."/vendor/autoload.php");
new Lucinda\NoSQL\Wrapper(simplexml_load_file("configuration.xml"), "local");
```

Then you are able to query server, as in below example:

```
$driver = Lucinda\NoSQL\ConnectionFactory::getInstance("");
$driver->set("hello", "world");
```

Unit Tests
----------

[](#unit-tests)

For tests and examples, check following files/folders in API sources:

- [test.php](https://github.com/aherne/php-nosql-data-access-api/blob/master/test.php): runs unit tests in console
- [unit-tests.xml](https://github.com/aherne/php-nosql-data-access-api/blob/master/unit-tests.xml): sets up unit tests
- [tests](https://github.com/aherne/php-nosql-data-access-api/tree/v3.0.0/tests): unit tests for classes from [src](https://github.com/aherne/php-nosql-data-access-api/tree/v3.0.0/src) folder
- [tests\_drivers](https://github.com/aherne/php-nosql-data-access-api/tree/v3.0.0/tests_drivers): unit tests for classes from [drivers](https://github.com/aherne/php-nosql-data-access-api/tree/v3.0.0/drivers) folder

Examples
--------

[](#examples)

### Working With Shared Driver

[](#working-with-shared-driver)

Usage example:

```
$driver = Lucinda\NoSQL\ConnectionFactory::getInstance("");
$driver->set("i", 1, 10); // sets key i as 1 for 10 seconds
$driver->get("i"); // returns 1
$driver->contains("i"); // returns true
$driver->increment("i"); // returns 2
$driver->decrement("i"); // returns 1
$driver->delete("i"); // deletes key i from store
$driver->flush(); // clears all value in store
```

### Working With Native Driver

[](#working-with-native-driver)

Usage example (assumes driver was redis):

```
$driver = Lucinda\NoSQL\ConnectionFactory::getInstance("");
$redisDriver = $driver->getDriver();
if ($redisDriver->ping()) {
    echo "Success!";
}
```

Reference Guide
---------------

[](#reference-guide)

### Class ConnectionFactory

[](#class-connectionfactory)

[Lucinda\\NoSQL\\ConnectionFactory](https://github.com/aherne/php-nosql-data-access-api/blob/master/src/ConnectionFactory.php) class insures a single [Lucinda\\NoSQL\\Driver](#interface-driver) is used per session and server name. Has following public static methods:

MethodArgumentsReturnsDescriptionstatic setDataSourcestring $serverName, [Lucinda\\NoSQL\\DataSource](https://github.com/aherne/php-nosql-data-access-api/blob/master/src/DataSource.php)voidSets data source detected beforehand per value of *name* attribute @ **server** tag. Done automatically by API!static getInstancestring $serverName[Lucinda\\NoSQL\\Driver](#interface-driver)Gets driver from data source based on value of *name* attribute @ **server** tag, opens connection in case object implements [Lucinda\\NoSQL\\Server](https://github.com/aherne/php-nosql-data-access-api/blob/master/src/Server.php) and returns it for later querying. Throws [Lucinda\\NoSQL\\ConnectionException](https://github.com/aherne/php-nosql-data-access-api/blob/master/src/ConnectionException.php) if connection fails!^ if your application uses a single database server per environment and *name* attribute @ server XML tag isn't set, empty string must be used as server name!

Usage example:

```
$driver = Lucinda\NoSQL\ConnectionFactory::getInstance("myServer");
$driver->get("hello"); // gets value of "hello" key from store
```

### Interface Server

[](#interface-server)

[Lucinda\\NoSQL\\Server](https://github.com/aherne/php-nosql-data-access-api/blob/master/src/Server.php) interface defines operations to manage connection to key-value store servers via following methods:

MethodArgumentsReturnsDescriptionconnect[Lucinda\\NoSQL\\DataSource](https://github.com/aherne/php-nosql-data-access-api/blob/master/src/DataSource.php)voidConnects to database server based on matching vendor's data source. Throws [Lucinda\\SQL\\ConnectionException](https://github.com/aherne/php-nosql-data-access-api/blob/master/src/ConnectionException.php) if connection fails!disconnectvoidvoidCloses connection to database server.Above methods HANDLED BY API AUTOMATICALLY, so **to be used only in niche situations**!

### Interface Driver

[](#interface-driver)

[Lucinda\\NoSQL\\Driver](https://github.com/aherne/php-nosql-data-access-api/blob/master/src/Driver.php) interface defines operations to perform on key-value stores via following methods:

MethodArgumentsReturnsDescriptionsetstring $key, $value, int $expiration=0voidSets value in store by key, available for seconds defined by expiration (unless later is zero).getstring $keymixedGets value from store by key.containsstring $keyboolChecks if key exists in store.incrementstring $key, int $offset = 1intIncrements value in store by existing key and offset, then returns it. Throws [Lucinda\\NoSQL\\KeyNotFoundException](https://github.com/aherne/php-nosql-data-access-api/blob/master/src/KeyNotFoundException.php) if key doesn't exist in store!decrementstring $key, int $offset = 1intDecrements value in store by existing key and offset, then returns it. Throws [Lucinda\\NoSQL\\KeyNotFoundException](https://github.com/aherne/php-nosql-data-access-api/blob/master/src/KeyNotFoundException.php) if key doesn't exist in store!deletestring $keyvoidDeletes value from store by existing key. Throws [Lucinda\\NoSQL\\KeyNotFoundException](https://github.com/aherne/php-nosql-data-access-api/blob/master/src/KeyNotFoundException.php) if key doesn't exist in store!flushvoidvoidClears all values in store.If any of above operations fails due to server issues, a [Lucinda\\NoSQL\\OperationFailedException](https://github.com/aherne/php-nosql-data-access-api/blob/master/src/OperationFailedException.php) is thrown!

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity84

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~63 days

Recently: every ~98 days

Total

37

Last Release

846d ago

Major Versions

v2.0.5 → v3.0.02019-11-24

v1.1.0.3 → v3.0.12020-01-17

v3.0.4 → v4.0.02021-12-28

v3.0.5 → v4.0.x-dev2022-01-09

v3.0.x-dev → v4.1.32022-12-25

PHP version history (3 changes)v3.0.0PHP ^7.1

v4.0.0PHP ^8.1

v3.0.5PHP ^7.1|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3382770?v=4)[Lucian Gabriel Popescu](/maintainers/aherne)[@aherne](https://github.com/aherne)

---

Top Contributors

[![aherne](https://avatars.githubusercontent.com/u/3382770?v=4)](https://github.com/aherne "aherne (54 commits)")

---

Tags

redisnosqlmemcachedapcudriverapcmemcachecouchbase

### Embed Badge

![Health badge](/badges/lucinda-nosql-data-access/health.svg)

```
[![Health](https://phpackages.com/badges/lucinda-nosql-data-access/health.svg)](https://phpackages.com/packages/lucinda-nosql-data-access)
```

###  Alternatives

[phpfastcache/phpfastcache

PHP Abstract Cache Class - Reduce your database call using cache system. Phpfastcache handles a lot of drivers such as Apc(u), Cassandra, CouchBase, Couchdb, Dynamodb, Firestore, Mongodb, Files, (P)redis, Leveldb, Memcache(d), Ravendb, Ssdb, Sqlite, Wincache, Xcache, Zend Data Cache.

2.4k5.0M130](/packages/phpfastcache-phpfastcache)[tedivm/stash

The place to keep your cache.

9824.8M124](/packages/tedivm-stash)[desarrolla2/cache

Provides an cache interface for several adapters Apc, Apcu, File, Mongo, Memcache, Memcached, Mysql, Mongo, Redis is supported.

1322.5M47](/packages/desarrolla2-cache)[sabre/cache

Simple cache abstraction layer implementing PSR-16

541.2M3](/packages/sabre-cache)[ihor/cachalot

Cache a lot in a proper way (APC, XCache, Memcached, Redis, Couchbase)

2528.1k](/packages/ihor-cachalot)[apix/cache

A thin PSR-6 cache wrapper with a generic interface to various caching backends emphasising cache taggging and indexing to Redis, Memcached, PDO/SQL, APC and other adapters.

114542.8k6](/packages/apix-cache)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
