---
title: "Redis的一些使用场景"
author: "pluto418"
date: "2014-05-26T19:26:59Z"
tags: []
categories: ["企业架构"]
slug: "redis"
draft: false
lastmod: "2014-05-29T16:50:04Z"
id: 2071819
url: "https://pluto418.iteye.com/blog/2071819"
---

1.Redis计数

使用场景计数器、限速器

INCR             先SET加1

INCRBY           免SET加1

DECR             先SET减1

DECRBY           免SET加1

 

BITSET mynum 1001 1

BITSET mynum 1002 0

BITSET mynum 1003 1

BITSET mynum 1004 1

 

BITCOUNT mynum     

结果 3

 

2\. Redis队列使用

队列的实现有很多种，基于redis的实现如下：

 

可以简单用命令模拟 telnet 

 

LPUSH mylist a b c d e     生产者压入队列

 

LPOP mylist                     消费者弹出最后进入的

RPOP mylist                     消费者弹出最先进入的

 

LRANGE mylist 0 -1         遍历全部展示

LLEN                               查询长度

 

 

LPOP

RPOP使用场景，发邮件先来注册的先发