predisHow can I use the PHP Redis HGET command?
The HGET
command in PHP Redis is used to retrieve the value of a field in a hash stored at a given key.
<?php
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$user = $redis->hGet('user', 'name');
echo $user;
// Output: John
?>
In the example above, we connect to a Redis server on 127.0.0.1
port 6379
, and then use the hGet
command to retrieve the value of the name
field in the user
hash. The output of the code above is John
.
The following parts are used in the example code:
Redis
- The Redis class in the PHP Redis extension.connect
- A method that connects to a Redis server.hGet
- The hGet command, which retrieves the value of a field in a hash stored at a given key.
For more information, see the PHP Redis documentation.
More of Predis
- How can I use PHP and Redis to retrieve a range of values from a sorted set?
- How do I use the PHP Redis zrevrange command?
- How can I use Predis with a cluster in PHP?
- How can I use PHP to increment values in Redis using ZINCRBY?
- How can I use Redis with the Yii PHP framework?
- How do I install and configure a PHP Redis DLL on a Windows machine?
- How can I use the zscan command in PHP with Redis?
- How can I use PHP and Redis to retrieve data from a sorted set using ZRANGEBYSCORE?
- How can I use PHP and Redis to get a reverse range of scores?
- How do I use yum to install php-redis?
See more codes...