CLUSTER INFO 打印集群的信息
CLUSTER NODES 列出集群当前已知的所有节点(node),以及这些节点的相关信息。
| 127.0.0.1:12345> TTL key # 尚未过期 | |
| (integer) 3 | |
| 127.0.0.1:12345> TTL key | |
| (integer) 1 | |
| 127.0.0.1:12345> TTL key # 虽然键已经过期,但因为我阻塞住了主服务器, | |
| (integer) 0 # 而主服务器没办法向从服务器发送 DEL 命令,所以值会一直滞留在从服务器里面。 | |
| 127.0.0.1:12345> GET key | |
| "value" | |
| 127.0.0.1:12345> TTL key | |
| (integer) 0 |
| /* Bit operations. | |
| * | |
| * Copyright (c) 2009-2012, Salvatore Sanfilippo <antirez at gmail dot com> | |
| * All rights reserved. | |
| * | |
| * Redistribution and use in source and binary forms, with or without | |
| * modification, are permitted provided that the following conditions are met: | |
| * | |
| * * Redistributions of source code must retain the above copyright notice, | |
| * this list of conditions and the following disclaimer. |
| /* | |
| * 位于 redis.h 文件,和排序操作相关的两个数据结构 | |
| */ | |
| // 用于保存被排序值及其权重的结构 | |
| typedef struct _redisSortObject { | |
| // 被排序键的值 | |
| robj *obj; |
| >>> from redis import Redis | |
| >>> r = Redis() | |
| >>> r.rpush("msg", u"你好", u"早上好", u"很高兴认识你") | |
| 3L | |
| >>> for m in r.sort("msg", alpha=True): print(m) | |
| ... | |
| 很高兴认识你 |
| # coding: utf-8 | |
| def p(s): | |
| "将输入字符串转换成 Redis 命令请求协议" | |
| # 将输入字符串分割为列表,并移除其中的空白字符串 | |
| # 比如 "SET KEY VALUE" 分为 ["SET", "KEY", "VALUE"] | |
| argv = s.split() |
| 127.0.0.1:6379> FLUSHALL | |
| OK | |
| 127.0.0.1:6379> SETEX k1 1000 v1 | |
| OK | |
| 127.0.0.1:6379> INFO keyspace | |
| # Keyspace | |
| db0:keys=1,expires=1,avg_ttl=997453 |
用 od 命令就可以清晰地看到符号了。
至于 RDB 文件的格式,在这里有详细记载: http://www.redisbook.com/en/latest/internal/rdb.html#id4
$ od -c dump.rdb 0000000 R E D I S 0 0 0 6 376 \0 \n 006 m y l 0000020 i s t , , \0 \0 \0 " \0 \0 \0 003 \0 \0 \f 0000040 f e n g x i n g x i n g 016 \b z e
| from redis import Redis | |
| r = Redis() | |
| # T = O(1) | |
| def zexists_1(key, member): | |
| return r.zscore(key, member) is not None | |
| # T = O(log N) | |
| def zexists_2(key, member): |
| \usepackage{xeCJK} | |
| \setCJKmainfont{WenQuanYi Micro Hei} | |
| \setCJKsansfont{WenQuanYi Micro Hei} | |
| \setCJKmonofont{WenQuanYi Micro Hei Mono} |