《Redis使用手册》(试读版)并通过 MGET 命令从这些键⾥⾯获取⽂章的各项信 息。 代码清单 2-3 ⽂章储存程序:/string/article.py from time import time # time() 函数⽤于获取当前 Unix 时间戳 class Article: def __init__(self, client, article_id): self.client ⽅法在返回⽂章信息的时候也会将⽂章的 ID 包含在字典⾥⾯⼀并返回。 对⽂章信息进⾏更新的 update() ⽅法是整个程序最复杂的部分。 ⾸先, 为了让⽤户可以⾃由选择需要更新的信 息项, 这个函数在定义时使⽤了 Python 的具名参数特性: def update(self, title=None, content=None, author=None): 通过具名参数, ⽤户可以根据⾃⼰ GETRANGE 命令来实现的。 代码清单 2-4 带有⻓度计数功能和预览功能的⽂章储存程序:/string/article.py from time import time # time() 函数⽤于获取当前 Unix 时间戳 class Article: # 省略之前展示过的 __init__()、create() 、update() 等⽅法…… def0 码力 | 352 页 | 6.57 MB | 1 年前3
共 1 条
- 1













