0

For example i have an array/json with 100000 entries cached with Redis / Predis. Is it posible to update or delete 1 or more entries or do i have to generate the whole array/json of 100000 entries? And how can I achieve that?

Bas
  • 2,330
  • 4
  • 29
  • 68
  • Do you have any special update/delete pattern? Only delete items from the head or tail of the array? Delete items randomly? Delete items by value or by index? – for_stack Sep 09 '16 at 14:38

3 Answers3

1

It is about how you store them if you are storing it as a string then no,

set key value
get key -> will return you value

Here value is your json/array with 10000 entries.

Instead if you are storing it in a hash . http://redis.io/commands#hash

hmset key member1 value1 member2 value2 ...

then you can update/delete member1 separately.

If you are using sets/lists you can achieve it with similar commands like lpush/lpop, srem etc.

Do read the commands section to know more about redis data structures which will give you more flexibility in selecting your structure.

Hope this helps

Karthikeyan Gopall
  • 5,469
  • 2
  • 19
  • 35
  • I think this is what i want, $client = Redis::connection(); $client->hmset('my:hash', ['field1'=>'value1', 'field2'=>'value2']); $changevalue= Redis::hset('my:hash' , 'field1' , 'newvaluesssssssssss'); $values1 = Redis::hmget('my:hash' , 'field1'); $values2 = Redis::hmget('my:hash' , 'field2'); print_r($values1); print_r($values2); – Bas Sep 10 '16 at 04:23
0

If you are using cache service, you have to:

  • get data from cache
  • update some entries
  • save data back in cache

You could use advanced Redis data structures like Hashes, but you it is not supported by Cache service, you would need to write you own functions.

my-nick
  • 691
  • 1
  • 5
  • 11
0

Thanks Karthikeyan Gopall, i made an example: Here i changed field1 value and it works :)

    $client = Redis::connection();
    $client->hmset('my:hash', ['field1'=>'value1', 'field2'=>'value2']);
    $changevalue= Redis::hset('my:hash' , 'field1' , 'newvaluesssssssssss');
    $values1    = Redis::hmget('my:hash' , 'field1');
    $values2    = Redis::hmget('my:hash' , 'field2');

    print_r($values1);
    print_r($values2);
Bas
  • 2,330
  • 4
  • 29
  • 68