9951 explained code solutions for 126 technologies


predisHow do I remove a key from Redis using PHP?


Using PHP, you can remove a key from Redis with the following code:

$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->del('key');

This code will delete the key key from the Redis server.

Code explanation

  1. $redis = new Redis();: creates a new Redis instance.
  2. $redis->connect('127.0.0.1', 6379);: connects to the Redis server.
  3. $redis->del('key');: deletes the key key from the Redis server.

Helpful links

Edit this code on GitHub