0

i stored my data as encoded data in redis using predis hset library. so the data is stored in one of the db in a hash name like e.g myHash

field = integer
value = encoded data..

e.g

1    {'pk_id':1,'name' : 'test1'}
2    {'pk_id':2,'name' : 'test2'}
3    {'pk_id':3,'name' : 'test3'}
...and so on...

there were like 400k+ rows of integer field with their encoded data. is there a way to pull these datas with offset and limit ? because if i do e.g

$predisObj->hgetall('myHash');

it pulls out everything and the browser crashes because of too many data

sasori
  • 5,249
  • 16
  • 86
  • 138

1 Answers1

0

predis shares the command list with redis as it is a php interface for redis store. Therefore you can use the standard redis commands to fulfill your needs:

The best way to achieve what you want is SCAN command From predis documentation:

// === Keyspace iterator based on SCAN ===
echo 'Scan the keyspace matching only our prefixed keys:', PHP_EOL;
foreach (new Iterator\Keyspace($client, 'predis:*') as $key) {
    echo " - $key", PHP_EOL;
}

This command will return an iterator thus the memory issues will not be of importance anymore.

Simas Joneliunas
  • 2,890
  • 20
  • 28
  • 35
  • what is the value of that $client var in your code snippet ? is it supposed to be my predis object ?, and is that 'predis:*' parameter supposed to be that way? or i had to change it with my hash name ? – sasori Jul 03 '18 at 02:08
  • the code is taken from the documentation link. thus: `$client = new Predis\Client($single_server, array('profile' => '2.8'));` `predis:*` is supposed to be your query. You can find out more in (https://github.com/nrk/predis/blob/v1.1.1/examples/redis_collections_iterators.php#L43-L47) – Simas Joneliunas Jul 03 '18 at 02:10
  • when I pass ($client, 'myHash') I get this message `Message: WRONGTYPE Operation against a key holding the wrong kind of value` ....what type was it looking for ? , my data in that redis db is field and encoded data – sasori Jul 03 '18 at 02:39
  • It seems it is a data/operation type mismatch. I haven't encountered such error before, but a quick look on the internet gave me this: https://github.com/antirez/redis/issues/2864#issuecomment-156057011 Maybe it can help you from here. – Simas Joneliunas Jul 03 '18 at 02:54
  • great, I used the `type myHash` in the command line, and it's a hash..i used the HashKey iterator...the problem now is, it's still crashing..where should I pass the offset and limit..to avoid to much data? – sasori Jul 03 '18 at 03:04