Home Database Redis How to implement Redis Hash operation in php

How to implement Redis Hash operation in php

May 30, 2023 am 08:58 AM
php redis hash

Hash operation

//为hash表中的字段赋值。成功返回1,失败返回0。若hash表不存在会先创建表再赋值,若字段已存在会覆盖旧值。
$ret = $redis->hSet('user', 'realname', 'jetwu');
//获取hash表中指定字段的值。若hash表不存在则返回false。
$ret = $redis->hGet('user', 'realname');
//查看hash表的某个字段是否存在,存在返回true,否则返回false。
$ret = $redis->hExists('user', 'realname');
//删除hash表的一个字段,不支持删除多个字段。成功返回1,否则返回0。
$ret = $redis->hDel('user', 'realname');
//同时设置某个hash表的多个字段值。成功返回true。
$ret = $redis->hMset('user', ['name' => 'jet', 'age' => 18]);
//同时获取某个hash表的多个字段值。其中不存在的字段值为false。
$ret = $redis->hMget('user', ['name', 'age']);
//获取某个hash表所有的字段和值。
$ret = $redis->hGetAll('user');
//获取某个hash表所有字段名。hash表不存在时返回空数组,key不为hash表时返回false。
$ret = $redis->hKeys('user');
//获取某个hash表所有字段值。
$ret = $redis->hVals('user');
//为hash表中不存在的字段赋值。若hash表不存在则先创建,若字段已存在则不做任何操作。设置成功返回true,否则返回false。
$ret = $redis->hSetNx('user', 'realname', 'jetwu');
//获取某个hash表的字段数量。若hash表不存在返回0,若key不为hash表则返回false。
$ret = $redis->hLen('user');
//为hash表中的指定字段加上指定增量值,若增量值为负数则相当于减法操作。若hash表不存在则先创建,若字段不存在则先初始化值为0再进行操作,若字段值为字符串则返回false。设置成功返回字段新值。
$ret = $redis->hIncrBy('user', 'age', 10);
//为hash表中的指定字段加上指定浮点数增量值。
$ret = $redis->hIncrBy('user', 'age', 1.5);
Copy after login

The above is the detailed content of How to implement Redis Hash operation in php. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

See all articles