The content this article brings to you is about the common operations (code) of keys in Redis. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Enter the directory: cd /usr/local/redis/
Start the service: ./bin/redis-server ./redis.conf
Enter: ./bin/ redis-cli
(1) View keys: keys *
View all keys: 127.0.0.1:6379> keys *
127.0.0.1:6379> keys * 1) "myb1" 2) "mya1" 3) "mya2" 4) "my3" 5) "myhash" 6) "mylist2" 7) "num2" 8) "my1" 9) "num" 10) "mylist3" 11) "mya3" 12) "name" 13) "myb3" 14) "mylist" 15) "my2" 16) "num3" 17) "imooc" 18) "num5" 19) "mylist4" 20) "myb2" 21) "myset" 22) "mysort"
(2) View keys starting with any character: keys string?
Query keys starting with my: keys my?
127.0.0.1:6379> keys my? 1) "my3" 2) "my1" 3) "my2"
(3) Delete key: del
Delete key: del my1 my2 my3
127.0.0.1:6379> del my1 my2 my3 (integer) 3
(4) Check whether the key exists exists
Check whether it exists, 1 represents existence, 0 represents non-existence: exists my1
127.0.0.1:6379> exists my1 (integer) 0 127.0.0.1:6379> exists num3 (integer) 1
(5) Rename the key: rename
Rename the key operation: rename original key name new Key name
127.0.0.1:6379> get num "36" 127.0.0.1:6379> rename num newnum OK 127.0.0.1:6379> get newnum "36"
(6) Set expiration time: expire
Set expiration time: expire key name seconds
127.0.0.1:6379> expire newnum 1000 (integer) 1
( 7) Check the remaining time of the key: ttl
Check the remaining time of the key: ttl key name. If it is not set, a negative value will be returned.
127.0.0.1:6379> expire newnum 1000 (integer) 1 127.0.0.1:6379> ttl newnum (integer) 885
(8) Determine the type of key: type
Determine the type of key: type name of key.
127.0.0.1:6379> type newnum string 127.0.0.1:6379> type my1 none 127.0.0.1:6379> type myhash hash 127.0.0.1:6379> type mylist4 list 127.0.0.1:6379> type mysort zset
Related recommendations:
Use redis queue operation example code in php
Nosql's Redis: key (key) operation command
The above is the detailed content of Common operations of keys in Redis (code). For more information, please follow other related articles on the PHP Chinese website!

Redis是现在最热门的key-value数据库,Redis的最大特点是key-value存储所带来的简单和高性能;相较于MongoDB和Redis,晚一年发布的ES可能知名度要低一些,ES的特点是搜索,ES是围绕搜索设计的。

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了关于redis的一些优势和特点,Redis 是一个开源的使用ANSI C语言编写、遵守 BSD 协议、支持网络、可基于内存、分布式存储数据库,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了Redis Cluster集群收缩主从节点的相关问题,包括了Cluster集群收缩概念、将6390主节点从集群中收缩、验证数据迁移过程是否导致数据异常等,希望对大家有帮助。

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了Redis实现排行榜及相同积分按时间排序,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,希望对大家有帮助。

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了关于原子操作中命令原子性的相关问题,包括了处理并发的方案、编程模型、多IO线程以及单命令的相关内容,下面一起看一下,希望对大家有帮助。

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了bitmap问题,Redis 为我们提供了位图这一数据结构,位图数据结构其实并不是一个全新的玩意,我们可以简单的认为就是个数组,只是里面的内容只能为0或1而已,希望对大家有帮助。

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了Redis实现排行榜及相同积分按时间排序,本文通过实例代码给大家介绍的非常详细,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了关于实现秒杀的相关内容,包括了秒杀逻辑、存在的链接超时、超卖和库存遗留的问题,下面一起来看一下,希望对大家有帮助。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
