BTW, Gustavo, do you remember you have a RedisCache extension. It is based on Predis. Yesterday I wrote a RedisCache based on phpredis. Most of the code is referred from your extension and CMemCache. I noticed one problem that in your RedisCache, you implemented offsetExists(). Since CCache::set() actually pass the hashed key (generateUniqueKey()) to setValue(), how do you make offsetExists() work without wrapping generateUniqueKey() inside? Do you expect caller generate hashed key before calling offsetExists()?
I’ve been working with this extension for some days now and changed a lot of things, as I’m implementing a active record based on redis, still in development tho, using this redis extension
For now its great (fast as a lightning). Still has a with a lot of bugs, I’ll release it as an extension when I’m done and its stable
public function offsetExists($id)
{
return $this->get($id)!==false;
}
but not require us to override it
CCache::offsetSet() forwards parameters to CCache::set(). Even if user calls offsetSet() then offsetExists(), he/she won’t get expected result. What’s the logic behind the offset series functions?
predis vs phpredis? I guess you can find many different answers over Google/Stack Overflow. In my mind, performance and functionality are the main advantages. This post is resourceful (phpredis author is also in discussion).
CCache implements ArrayAccess, so you can use it as an array, therefore the call
isset(Yii::app()->cache['something'])
will call offsetExists
yes, but redis method "exists" is faster that get, 1 reason is because it returns boolean instead of the actual value of the key, thats why the need to override
I’ll read the post and might migrate if its actually faster and more functional
EDIT:
Its write in C, that why the performance gain
phpredis methods are not 100% consistent with redis, which is not good, as you must check predis documentation instead of redis
Since you implement __call(), I would prefer to stick with one coding style by using get(), set(), exists().
Which part of phpredis is not consistent with Redis? The pipelining part? I’m very new to Redis, therefore I’m not sure if I would rely on the features that are inconsistent. According to their benchmark, 2-3 times gain on performance is not simply ignorable.
I just want to point out that https://github.com/nicolasff/phpredis is phpredis homepage (linked by redis.io). There is del(). There is mset(). There is hMGet(). There is no mget() but instead getMultiple(). Could "mget" reserved by PHP or something?
Also, can you explain a little bit about the generateUniqueKey() and keyPrefix? Isn’t the users responsible to make keys unique (if they are meant to be unique)?