bainternet / sqlite-simple-store
轻量级的零配置SQLite基础键值存储,带有过期时间,适用于PHP。基本上它是一个简单的键值存储,带有过期字段,过期后将删除值。由于它受到Redis的很大影响,实现了一些Redis的有用功能。
0.1.5
2015-09-10 10:22 UTC
This package is not auto-updated.
Last update: 2024-09-28 15:19:02 UTC
README
轻量级的零配置SQLite基础键值存储,带有过期时间,适用于PHP。
基本上它是一个简单的键值存储,带有过期字段,过期后将删除值。由于它受到Redis的很大影响,实现了一些Redis的有用功能。
使用
<?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', ) ) );
安装
composer
要使用composer PHP包管理器安装和使用,只需按照以下步骤操作
如果您还没有,请在将使用SQLite-simple-store的新项目的根目录下创建文件composer.json。将以下内容添加到composer.json文件中..
{
"require": {
"bainternet/sqlite-simple-store": "dev-master"
}
}
git
git clone https://github.com/bainternet/SQLite-simple-store.git
手动
简单地 下载最新版本 并包含它。
方法
get($key,$default)
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.
set($key,$value)
stores a value in the database.
del($key)
Deletes a value of the given key.
keys($validate)
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.
exists($key)
checks if a key exists and is not expired
get_all($validate)
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.
delete_all()
deletes all values from db.
incr($key,$by = 1)
increment value by $by (default = 1).
decr($key,$by = 1)
decrement value by (default = 1).
count($key)
returns the count of elements in a key assuming it is an array or object.
rpush($key,$value)
adds an element to a key (right).
lpush($key,$value)
adds an element to a key (left).
lset($key,$idx,$value)
sets the value of an element in a key by index.
lindex($key,$idx)
gets an element from a key by its index.