Download the PHP package limen/redmodel without Composer
On this page you can find all versions of the php package limen/redmodel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package redmodel
Make redis manipulations easy. Unify commands for all data types.
Features
- Unified commands for all data types: string, list, hash, set and zset.
- support SQL like query
- use "eval" to save time consumption on network.
- "set" like commands all support to set new ttl or keep current ttl
Unified commands
- create: create key
- createNotExists: create key when which not exists
- createExists: create key when which exists
- insert: similar to create except supporting multiple keys
- insertNotExists: similar to createNotExists
- insertExists: similar to createExists
- get: get key to replace get, lrange, hgetall, smembers and zrange
- getAndSet: get key and set new value
- find: similar to get
- findBatch: find batch
- update: update keys
- destroy: remove one key
- destroyBatch: remove keys
- delete: remove keys
Installation
Recommend to install via composer.
Usage
Concepts
Key representation
Every model has its own key representation which tells how to build query keys. For example
We can use where clauses to query the Redis.
The keys to query are
Key field
Key field is a dynamic part of the key representation.
Take the key representation above, it has two fields
- schoolId
- classId
Complete key
When a key has no unbound field, we treat it as complete. For example
On the contrary, an incomplete key is similar to
Returned data set
The returned data set would be an associated array whose indices are the query keys.
When both keys exist on Redis database, the returned data set would be
If a key not exist, the equivalent index would be not set.
The returned item's data type depends on the model's type which could be string, hash, list, set or zset.
- string: string
- hash: associated array
- list: array
- set: array
- zset: array
Methods
create
Can use when a model's key representation has only one dynamic field as its primary field.
The item's ttl is optional.
Hash type with key representation
zset type with key representation
createExists
Similar to "setxx" but supports more data types: string, hash, set, zset and list.
createNotExists
Similar to "setnx" but supports more data types.
insert
An optional parameter make it possible to insert like "setnx" and "setxx". String type with key representation.
insertExists
Similar to createExists
insertNotExists
Similar to createNotExists
find
Can use when a model's key representation has only one dynamic field as its primary field.
findBatch
Similar to find. The returned data set are indexed by ids.
updateBatch
Similar to findBatch.
The key would be created if not exist. The key's ttl would not be modified if the ttl parameter not set.
all
key representation
where
Similar to SQL
whereIn
Similar to where
first
Get first exist item from query keys. Return null when all query keys not exist.
update
The key would be created if not exist. The key's ttl would not be modified if the ttl parameter not set.
delete
Delete query keys.
orderBy, sort
string type with key representation
count
Count the exist query keys.
max
Get the maximum item in the returned data set.
min
Get the minimum item in the returned data set.
sum
Get the sum of the returned data set.
Predis native methods
Predis native methods such as "sadd", "hset" can use when the query contains only one complete query key.
// string model
$model->where('id', 1)->set('maria');
// hash model
$model->where('id', 1)->update([
'name' => 'Maria',
'age' => '22',
]);
// equals to
$model->where('id', 1)->hmset([
'name' => 'Maria',
'age' => '22',
]);
Query builder
Taking the job to build query keys for model.
key representation