yii2-redis icon indicating copy to clipboard operation
yii2-redis copied to clipboard

ActiveRecord findall pool duplicating keys.

Open Toorion opened this issue 9 years ago • 6 comments

RPUSH is saved keys to findall pool with duplicated values. Because Redis LIST is not unique. Finally find()->all() return a lot of duplicated objects. As solution it can use sorted set and store objects with SADD and get it with SMEMBERS command instead of LRANGE.

Toorion avatar Jun 02 '15 14:06 Toorion

@cebe I can fix it. But I'm not sure that's the right way. I think that when you duplicate PK to throw an exception.

vaseninm avatar Jun 05 '15 11:06 vaseninm

agree that it should not be possible to insert a duplicate key but it should not take too long to insert into big datasets. the check should be done fast somehow.

cebe avatar Jun 05 '15 13:06 cebe

@cebe

EVAL "for i = 1, 1000000 do redis.call('SADD', 'test', i) end" 0            (7.90s)
SMEMBERS test               (6.75s)
EVAL "for i = 1, 1000000 do redis.call('RPUSH', 'test', i) end" 0         (7.66s)
LRANGE test 0 -1             (6.46s)

Not slow?

vaseninm avatar Jun 08 '15 07:06 vaseninm

what do you mean with "not slow"? We can not change the storage format in 2.0.x btw...

cebe avatar Jun 08 '15 09:06 cebe

Exactly. Lists do not have fast methods to check for existence.

vaseninm avatar Jun 08 '15 10:06 vaseninm

Hello, vaseninm see fork https://github.com/nailfor/yii2-redis After some optimizations, difference in speed between the YII / Redis and my fork is small

Storage pool is change the format of my realization

nailfor avatar Aug 19 '16 08:08 nailfor