python import threading from hermes_cache import HermesMemoize cache = HermesMemoize(back_end='redis', host='localhost', port=6379) def expensive_operation(arg): result = cache.get(arg) if result is None: result = calculate(arg) cache.set(arg, result) return result def concurrent_operations(args): results = [] threads = [] for arg in args: thread = threading.Thread(target=expensive_operation, args=(arg,)) thread.start() threads.append(thread) for thread in threads: thread.join() for thread in threads: results.append(thread.result()) return results arguments = [1, 2, 3, 4, 5] results = concurrent_operations(arguments) print(results)


上一篇:
下一篇:
切换中文