May 2017
Beginner to intermediate
220 pages
5h 2m
English
Here is an example of how to save some example website data in Redis and then load it:
In [5]: url = 'http://example.webscraping.com/view/United-Kingdom-239' In [6]: html = '...'In [7]: results = {'html': html, 'code': 200}In [8]: r.set(url, results)Out[8]: TrueIn [9]: r.get(url)Out[9]: b"{'html': '...', 'code': 200}"
We can see with the get output, that we will receive bytes back from our Redis storage, even if we have inserted a dictionary, or a string. We can manage these serializations the same way we did for our DiskCache class, by using the json module.
What happens if we need to update the content of a URL?
In [10]: r.set(url, {'html': 'new html!', 'code': 200})Out[10]: TrueIn [11]: r.get(url)Out[11]: b"{'html': ...Read now
Unlock full access