Super lightweight Zero configuration sqlite-based key => value store with expiration time for PHP.
Basically its a simple key value storage with and expireation field which will delete the value after it expires. Also since its heavily influenced by redis, some of redis useful functions were implemented.
<?php
//include the class
include_once('SQLite_simple_store.php');
//instanceate the class
$s = new SQLite_simple_store('user_table');
//simple set key => value
$s->set('name','oha');
//simple get value by key
echo $s->get('name'); //oha
//set with expiretion time
$s->set('token','asdjjrt788dsfjjj447586',6000);
//update value
$s->set('name','ohad');
//get all keys
var_dump($s->keys());
//set a more complex value
$s->set('user_1',
array(
'user_id' => 1,
'email' => 'email@mail.com',
'meta' => array(
'user_meta1' => 'some value',
'user_meta2' => 'some other value',
)
)
);
To install and use via the composer PHP package manager just take these steps:
If you don’t already have one, create the file composer.json in the root of your new project that is going to use SQLite-simple-store. Add the following to the composer.json file..
{
"require": {
"bainternet/sqlite-simple-store": "dev-master"
}
}
git clone https://github.com/bainternet/SQLite-simple-store.git
simply download the latest version and include it.
gets a specific value based on key, if the value has expired false will be returned. you can pass a default value as a second parameter to be returned if no value exists or is expired.
stores a value in the database.
Deletes a value of the given key.
get all keys in the db.
if $validate is true (default) expired keys and values will get deleted and will not be returned. set $validate to false to get all keys even if they have expired.
checks if a key exists and is not expired
get all values in the db.
if $validate is true (default) expired values will get deleted and will not be returned. set $validate to false to get all values even if they have expired.
deletes all values from db.
increment value by $by (default = 1).
decrement value by (default = 1).
returns the count of elements in a key assuming it is an array or object.
adds an element to a key (right).
adds an element to a key (left).
sets the value of an element in a key by index.
gets an element from a key by its index.