`
sillycat
  • 浏览: 2566749 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Redis(3)Redis Data Type and Specialty

 
阅读更多
Redis(3)Redis Data Type and Specialty

1. Sorted Set Type
Almost the same as Set, but we can use a key score to order our data.
> zadd days 0 mon
(integer) 1
> zadd days 1 tue
(integer) 1
> zadd days 2 wed
(integer) 1
> zadd days 3 thu
(integer) 1
> zadd days 4 fri
(integer) 1
> zadd days 5 sat
(integer) 1
> zadd days 6 sun
(integer) 1
> zcard days
(integer) 7
> zrange days 0 6
1) "mon"
2) "tue"
3) "wed"
4) "thu"
5) "fri"
6) "sat"
7) "sun"
> zscore days sat
"5"
> zscore days mon
"0"
> zrangebyscore days 3 6
1) "thu"
2) "fri"
3) "sat"
4) "sun"

2. Hash Type
> hmset user1 username tester password 111111 age 30 gender 1
OK
> hgetall user1
1) "username"
2) "tester"
3) "password"
4) "111111"
5) "age"
6) "30"
7) "gender"
8) "1"
> hset user1 password 12345
(integer) 0
> hgetall user1
1) "username"
2) "tester"
3) "password"
4) "12345"
5) "age"
6) "30"
7) "gender"
8) "1"
> hkeys user1
1) "username"
2) "password"
3) "age"
4) "gender"
> hvals user1
1) "tester"
2) "12345"
3) "30"
4) "1"
> hdel user1 gender
(integer) 1
> hgetall user1
1) "username"
2) "tester"
3) "password"
4) "12345"
5) "age"
6) "30"

> HMSET kid-001 name Akshi age 2 sex Female
OK
> hmget kid-001 age name
1) "2"
2) "Akshi"

3. Publish/Subscribe
You can publish the data to one pipeline, others can subscribe these data.
One client can subscribe the channel
> subscribe ccav
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "ccav"
3) (integer) 1
1) "message"
2) "ccav"
3) "news1"
1) "message"
2) "ccav"
3) "news2"

The other client can publish the message
> publish ccav news1
(integer) 1
> publish ccav news2
(integer) 1

And we can subscribe a set of channels like this:
> psubscribe cc*
Reading messages... (press Ctrl-C to quit)
1) "psubscribe"
2) "cc*"
3) (integer) 1
1) "pmessage"
2) "cc*"
3) "cctv"
4) "news3"
1) "pmessage"
2) "cc*"
3) "ccav"
4) "news2"

> publish cctv news3
(integer) 1
> publish ccav news2
(integer) 1

4. Data Expiration
> set name "sillycat"
OK

ttl can check the expiration time, -1 means never.
> ttl name
(integer) -1

> exists name
(integer) 1

expire command can set the key=name with expiration time 5 seconds
> expire name 5
(integer) 1
> exists name
(integer) 0

There is also a command expireat, but I did not try that.

5. Check Suffix Command
NX will check if the key does not exist, then we will proceed the command.

> set name "karl"
OK
> setnx name "peter"
(integer) 0
> get name
"karl"

6. Other Operations
There is default 16 database in redis, we can select different databases as follow:
> select 0
OK
> set name karl
OK
> select 1
OK
>[1set name karl1
OK
>[1get name
"karl1"
>[1select 0
OK
> get name
"karl"

references:
http://blog.nosqlfan.com/html/3139.html
http://redis.io/topics/data-types



分享到:
评论

相关推荐

    Spring Data Redis API(Spring Data Redis 开发文档).CHM

    Spring Data Redis。 Spring Data Redis 开发文档。 官网 Spring Data Redis API。

    spring-data-redis 1.7.6

    3. **操作API**:Spring Data Redis提供了一套丰富的模板方法和Repository接口,简化了Redis的操作。例如,`StringRedisTemplate`用于字符串操作,`HashOperations`处理哈希数据,`ListOperations`处理列表,`Set...

    SpringDataRedis的jar包.rar

    3. **Reactive Redis支持**:Spring Data Redis也支持Reactor和Project Reactor,为非阻塞、反应式编程模型提供支持。这使得在高并发场景下能更高效地利用系统资源。 4. **Jedis和Lettuce客户端**:Spring Data ...

    spring-data-redis-2.5.5-API文档-中文版.zip

    赠送jar包:spring-data-redis-2.5.5.jar; 赠送原API文档:spring-data-redis-2.5.5-javadoc.jar; 赠送源代码:spring-data-redis-2.5.5-sources.jar; 赠送Maven依赖信息文件:spring-data-redis-2.5.5.pom; ...

    RedisClient 下载 最新版

    Order redis data by key, data type, size Navigation history Support time to live Support paging query redis data Support multiple selection to delete, cut, copy, export redis data Support flat view ...

    idea 或者datagrip中redis的插件 ledis 官网下载很慢 ledis2.54

    3. 搜索栏输入“Redis”或“Ledis”,此时会显示可用的相关插件,如Redis Integration或Redis Console。 4. 选择需要的插件,点击“Install”开始下载并安装。 5. 安装完成后,重启IDEA或DataGrip,即可在工具栏找到...

    spring data for redis

    **Spring Data for Redis** Spring Data for Redis 是一个用于简化Redis集成的框架,它是Spring Data项目的一部分,旨在提供统一的编程模型来访问各种数据存储。Spring Data for Redis 提供了丰富的API,使得在Java...

    spring data redis api jar

    Spring Data Redis API Jar是Spring Data项目的一个重要组成部分,专门用于集成和操作Redis内存数据存储系统。Spring Data项目旨在简化对各种数据存储技术的访问,包括关系数据库、NoSQL数据库、图数据库等,而...

    Redis3集群安装

    Redis3集群安装Redis3集群安装Redis3集群安装Redis3集群安装Redis3集群安装Redis3集群安装Redis3集群安装Redis3集群安装Redis3集群安装Redis3集群安装Redis3集群安装Redis3集群安装Redis3集群安装Redis3集群安装...

    maven版spring-data-redis简单示例

    基于spring的子项目spring-data-redis写的一个基于hash类型的用户CRUD,经过简单的封装,可以实现通用CRUD,请事先安装好redis,配置文件redis.properties请做相应修改,希望对你有帮助。

    spring-data-redis-2.3.9.RELEASE-API文档-中文版.zip

    赠送jar包:spring-data-redis-2.3.9.RELEASE.jar; 赠送原API文档:spring-data-redis-2.3.9.RELEASE-javadoc.jar; 赠送源代码:spring-data-redis-2.3.9.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring-...

    spring-data + jedis + redis代码

    3. 创建一个RedisTemplate或StringRedisTemplate bean,这是Spring Data提供的模板类,用于执行Redis操作。 4. 使用Spring Data的注解(如@Repository、@EnableRedisRepositories)来定义仓库接口,并让Spring自动...

    spring-session-data-redis-2.0.4.RELEASE-API文档-中文版.zip

    赠送jar包:spring-session-data-redis-2.0.4.RELEASE.jar; 赠送原API文档:spring-session-data-redis-2.0.4.RELEASE-javadoc.jar; 赠送源代码:spring-session-data-redis-2.0.4.RELEASE-sources.jar; 赠送...

    spring-data-redis-2.6.1-API文档-中文版.zip

    赠送jar包:spring-data-redis-2.6.1.jar; 赠送原API文档:spring-data-redis-2.6.1-javadoc.jar; 赠送源代码:spring-data-redis-2.6.1-sources.jar; 赠送Maven依赖信息文件:spring-data-redis-2.6.1.pom; ...

    redis-data-cache.properties

    redis实现tomcat的session共享所需redis-data-cache.properties

    spring data redis 小例子

    Spring Data Redis是一个强大的Java库,它为开发人员提供了一种简单的方式来利用Redis内存数据存储进行数据操作。在本文中,我们将深入探讨Spring Data Redis的基本概念、功能和如何通过一个小例子来实现其应用。 ...

    spring-data-redis基于注解的实现方式

    在现代的Java应用开发中,Spring Data Redis框架提供了一种高效、便捷的方式来集成Redis缓存系统,极大地提升了数据处理的效率。"spring-data-redis基于注解的实现方式"是这个话题的核心,它探讨了如何利用Spring ...

    redis集群以及Spring-data-redis操作集群

    总结来说,Redis集群是提升系统性能和可用性的关键,而Spring-data-redis则是简化了在Java应用中使用Redis(包括集群)的过程,提供了一套完整的操作API。通过理解并熟练掌握这两个方面,可以有效地利用Redis来解决...

    Redis-Essentials.pdf

    type, and then the solution is improved and optimized by using the Hash data type. Uniqueness support is added to the String and Hash implementations by using the Sorted Set and HyperLogLog data types...

    spring-data-redis-1.6.0.RELEASE最新稳定版(个人测试通过)

    3. **Reactive 支持**:1.6.0.RELEASE 版本引入了对 Reactive Redis 的支持,允许开发者使用响应式编程模型,通过 Mono 和 Flux API 处理异步数据流,从而更好地适应高并发场景。 4. **Repositories 支持**:Spring...

Global site tag (gtag.js) - Google Analytics