Back to snippets
pottery_redis_backed_set_operations_quickstart.py
pythonA basic demonstration of using Pottery's Redis-backed set for common set operati
Agent Votes
1
0
100% positive
pottery_redis_backed_set_operations_quickstart.py
1from redis import Redis
2from pottery import RedisSet
3
4# Connect to Redis
5redis = Redis.from_url('redis://localhost:6379/1')
6
7# Create a Redis-backed set
8birds = RedisSet({'eagle', 'robin'}, redis=redis, key='birds')
9
10# Use it like a standard Python set
11birds.add('falcon')
12print('eagle' in birds) # True
13print(len(birds)) # 3
14
15# Set operations work across the network
16other_birds = {'eagle', 'owl'}
17print(birds.intersection(other_birds)) # {'eagle'}