-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG]: Storage adapter getKeys method return empty array when set prefix = '' #15480
Comments
I suppose its related to cphalcon/phalcon/Storage/Adapter/Libmemcached.zep Lines 45 to 61 in c7a713d
As we can see, it sets this->prefix = "ph-memc-"; , so pattern is never empty.
|
parent::__construct(factory, options); If |
@aa65535 I am not convinced that this should happen. By using the prefix we are namespacing so to speak the keys stored in the storage (Libmemcached in this case). If there are other processes using the same server, without the prefix, you will be able to retrieve keys that do not necessarily belong to your application. So if I use say an application that stores data in memcached, and then use my Phalcon app with this adapter, without the prefix I will be able to read all the keys in memcached, even from the other application. Thoughts? |
Of course, the best practice is to set a unique prefix for each application, but you can use the constructor to set the prefix to an empty string. use Phalcon\Storage\Adapter\Libmemcached;
use Phalcon\Cache\Adapter\Redis;
use Phalcon\Storage\SerializerFactory;
$factory = new SerializerFactory();
$options = [
'prefix' => '' // set empty string
];
$mem = new Libmemcached($factory, $options);
var_dump($mem->getPrefix()); // string(0) ""
var_dump($mem->getKeys()); // array(0) {}
$redis = new Redis($factory, $options);
var_dump($redis->getPrefix()); // string(0) ""
var_dump($redis->getKeys()); // array(0) {} |
@aa65535 The example you gave is correct. If you specify an empty prefix, Phalcon needs to internally set one in order to "namespace" the keys i.e. the keys stored only for your application. If it does not, you will be able to see all keys stored in Libmemcached or Redis or elsewhere. This is done on purpose so as not to be able to access data that does not belong to you per se. If you want to access all the keys in Memcached or Redis etc. you can instantiate the underlying adapter and then use the |
I will write a couple of tests to ensure that the key can be changed if need be but never be empty. I do not recall the code right now but will check just in case. |
After discussions with @Jeckerson we decided to offer this functionality. If the user wishes to not use a prefix, they can specify an empty prefix with the passed |
Resolved in #15654 |
Steps to reproduce the behavior:
If
pattern
is an empty string,keys
should be returned directly.cphalcon/phalcon/Storage/Adapter/AbstractAdapter.zep
Lines 138 to 154 in c7a713d
Expected behavior
A clear and concise description of what you expected to happen.
Details
The text was updated successfully, but these errors were encountered: