Download the PHP package karmabunny/rdb without Composer
On this page you can find all versions of the php package karmabunny/rdb. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download karmabunny/rdb
More information about karmabunny/rdb
Files in karmabunny/rdb
Informations about the package rdb
Rdb
Like Pdb, but for Redis. I guess.
Big emphasis on prefixing keys and object serialization.
Also because I don't want a hard dependency on either predis or php-redis. They both have their problems (vague magical commands API, binary extension, etc). Or wouldn't it be wonderful if a 3rd option showed up /s. Also supports credis.
Install
Add as a dependency:
Adapters
- php-redis (binary extension)
- predis (composer package)
- credis (composer package)
This library doesn't implement a redis client itself, only wraps existing clients. After much effort trying to normalise the responses from all these client, it might seem like a good idea to just write our own that isn't so inconsistent.
But consider that we only know how inconsistent these libraries are because we've spent so much time trying to make them all behave the same. For example, client 'A' might do 'B' well but 'C' badly. Then client 'D' does 'B' badly but 'C' really well.
So as I sit here and scoff at their feeble attempts, I am reminded of a few things:
- I've already introduced so many of my own bugs during this journey.
- Unit testing is a gift from heaven.
- Normalising these inconsistencies has improved our own consistency, something probably not as achievable when writing a new client from scratch.
- also this: https://xkcd.com/927
Version support
This wrapper doesn't try to polyfill any missing features. It targets Redis server v3.0, as that's the common support among all the adapters.
This library wouldn't ever try to hide features behind target versions, but perhaps it could help smooth out any differences. Lua scripting could polyfill a lot of things tbh.
For example, BRPOPLPUSH
is deprecated in v6.2 and might be removed in the distant future. In this case, the library would be able to dynamically replace (based on the server version) this with BLMOVE
.
Plans for v2
There is a preference for the millisecond version of a command, particularly TTL parameters. This is clearly misleading and already wildly inconsistent. Ideally this changes so that a 'float' is converted to the millisecond version and integer remains unchanged. Thus the input is always 'seconds'.
Type errors are currently (hopefully) always a null
return. This can quite confusing at times, or helpful in others. Version 2 will likely permit both, defaulting to emitting exceptions.
Config
host
- server name + portprefix
- key prefixadapter
- 'predis' (default), 'php-redis', 'credis'timeout
- connection timeout, in seconds (default: 5)lock_sleep
- tick size for locking, in milliseconds (default: 5)chunk_size
- max key size for mscan methods (default: 50)scan_size
- count hint for scan methods (default: 1000)scan_keys
- replace keys() with scan() (default: false)options
- adapter specific options
Notes:
- The port number is default 6379 unless specified in the
host
option. - The protocol can be adjusted in the
host
option too: prefixtcp://
orudp://
.
Usage
Basic usage with a TTL. Great for caching.
Object extensions will serialize in the PHP format. These have builtin assertions so things are always the correct shape.
Locking provides a mechanism to restrict atomic access to a resource.
Leaky bucket is a rate-limiting algorithm. It's cute, easy to understand, and not too complex.
Contributing
Submit a PR if you like. But before you do, please do the following:
- Run
composer analyse
and fix any complaints there - Run
composer compat
and fix those too - Write some tests and run
composer tests
- Document the methods here
Methods
Core Methods
- get
- set
- keys
- scan
- mGet
- mSet
- del
- exists
- sMembers
- sAdd
- lLen
- lRange
- lTrim
- lSet
- lRem
- lIndex
- lPush
- lPop
- blPop
- rPush
- rPop
- brPop
- brPoplPush
- zAdd
- zIncrBy
- zRange
- zRem
- zCard
- zCount
- zScore
- zRank
- zRevRank
TODO: more
sets:
- sScan
- sRandMember
- sDiff (+ store)
- sInter (+ store)
- sUnion (+ store)
Extended Methods
- mScan
- getObject
- setObject
- mGetObjects
- mScanObjects
- mSetObjects
- setJson
- getJson
Builtin Utilities
- 'Leaky bucket' rate limiting
- Locking
TODOs
- more tests
- more methods
All versions of rdb with dependencies
colinmollenhour/credis Version ^1
php Version >=7.2
symfony/polyfill-php73 Version ^1.29