博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
redis 自增步数_Redis的第一步
阅读量:2507 次
发布时间:2019-05-11

本文共 3675 字,大约阅读时间需要 12 分钟。

redis 自增步数

When you have up and running, you can start using it!

启动并运行后,就可以开始使用它了!

The simplest way is to use redis-cli, an application installed when you install Redis.

最简单的方法是使用redis-cli ,这是在安装Redis时安装的应用程序。

It’s a built-in way to write commands to Redis without having to set up an application in order to do so.

这是一种将命令写入Redis的内置方式,而无需为此设置应用程序。

You can connect to a remote Redis server using redis-cli -h <host> -p <port> -a <password>

您可以使用redis-cli -h <host> -p <port> -a <password>连接到远程Redis服务器。

Once you’re in the Redis CLI app, you can start storing data into it.

进入Redis CLI应用程序后,就可以开始将数据存储到其中了。

Add a value using the structure SET <key> <value>:

使用结构SET <key> <value>添加一个值:

SET name "Flavio"

检索值 (Retrieve a value)

Retrieve a value using the structure GET <key>:

使用结构GET <key>检索值:

检查密钥是否存在 (Check if a key exists)

We can also check if a key exists using EXISTS <key>:

我们还可以使用EXISTS <key>检查密钥是否存在:

The command returns either 1 (exists) or 0 (does not exist).

该命令返回1(存在)或0(不存在)。

设置是否不存在 (Set if not exists)

A variation of SET allows us to only set a key if it does not exist yet:

SET一种变体允许我们仅在尚不存在的情况下设置键:

SETNX name "Roger"

删除金钥 (Delete a key)

Delete a key using DEL <key>:

使用DEL <key>删除DEL <key>

列出现有密钥 (Listing existing keys)

You can list all keys inserted using KEYS *

您可以列出使用KEYS *插入的所有键

Or you can filter using a pattern like KEYS n* to only list keys starting with n, for example.

或者,您可以使用类似KEYS n*的模式进行过滤,以仅列出以n开头的键。

Each value stored can hold up to 512 MB in value.

每个存储的值最多可容纳512 MB。

密钥过期 (Expiring keys)

A key can be temporarily stored, and removed automatically when the timer ends:

可以将密钥临时存储,并在计时器结束时自动将其删除:

SETEX <key> <seconds> <value>

SETEX <key> <seconds> <value>

You can get the time remaining for a key to be cleared using TTL <key>

您可以使用TTL <key>清除密钥的剩余时间。

In this example I set a name key with Flavio as value, and using TTL I can check how much time is left until the key will return the value. Once the timer expires, it results in a null value (nil):

在此示例中,我设置了一个以Flavio作为值的name键,并使用TTL可以检查剩下多少时间直到该键返回该值。 计时器到期后,将产生一个空值( nil ):

You can also set an existing key to expire using EXPIRE <key> seconds>.

您还可以使用EXPIRE <key> seconds>将现有密钥设置为过期。

递增和递减 (Increment and decrement)

A numeric value can be incremented using INCR <key> and decremented using DECR <key>. You can also use INCRBY <key> <amount> and DECRBY <key> <amount> to increment a key value by a specific amount:

数值可以使用INCR <key>递增,也可以使用DECR <key>递减。 您还可以使用INCRBY <key> <amount>DECRBY <key> <amount>将键值增加特定量:

Those commands are very well suited for high concurrent operations where many clients might interact with the same data, to ensure atomic transactions.

这些命令非常适合于高并发操作,在该操作中许多客户端可能与同一数据进行交互,以确保原子事务

The most common example is when 2 different clients try to increment the same number.

最常见的示例是两个不同的客户端尝试增加相同的数字时。

On a database like PostgreSQL or MongoDB you first get the number value, you increment it, then you make a request to the server to increment it.

在PostgreSQL或MongoDB之类的数据库上,您首先要获得数字值,然后对其进行递增,然后向服务器发出请求以使其递增。

Say the value is 1. If two clients read the value using GET then they call SET to increment it independently, in the end if there is nothing preventing the concurrent change to happen, the result will be 2. Redis prevents this problem at the root.

说值是1 。 如果两个客户端使用GET读取值,则它们调用SET进行独立递增,最后如果没有什么阻止并发更改发生,则结果将为2 。 Redis从根本上防止了此问题。

更复杂的数据结构 (More complex data structures)

So far we’ve worked with simple data types like integers and strings.

到目前为止,我们已经使用了简单的数据类型,例如整数和字符串。

Redis can support more complex structures.

Redis可以支持更复杂的结构。

Let’s see in the next lessons how to work with:

让我们在下一课中了解如何使用:

  • Lists

    清单
  • Sets

    套装
  • Sorted sets

    排序集
  • Hashes

    散列

翻译自:

redis 自增步数

转载地址:http://ixmgb.baihongyu.com/

你可能感兴趣的文章
数据结构系列之2-3-4树的插入、查找、删除和遍历完整版源代码实现与分析(dart语言实现)...
查看>>
VM CentOS 问题汇总
查看>>
这段时间的小结
查看>>
ANDROID_MARS学习笔记_S01原始版_021_MP3PLAYER001_下载mp3文件
查看>>
8个基本的引导工具的网页设计师
查看>>
第二周周六DailyReporting——PM(李忠)
查看>>
Beta阶段DAY3
查看>>
windows server 2008 R2 NPS(网络连接策略服务)设置radius,实现telent登陆交换机路由器权限分配...
查看>>
Java中静态变量和动态变量
查看>>
vim的visual可视模式(转载)
查看>>
ASP.NET MVC 学习笔记-6.异步控制器
查看>>
java_赋值与初始化
查看>>
函数如何调用?
查看>>
3.2.2 线性表的顺序存储实现
查看>>
TP框架 ---空控制器和空操作
查看>>
poj 1845 Sumdiv (等比求和+逆元)
查看>>
iView 的后台管理系统简易模板 iview-admin-simple
查看>>
写一个自己的搜索引擎(1)
查看>>
NGINX、PHP-FPM开机自动启动
查看>>
python 递归求阶乘
查看>>