-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbean_basic.py
More file actions
61 lines (45 loc) · 1 KB
/
bean_basic.py
File metadata and controls
61 lines (45 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#coding:utf-8
import json
import beanstalkc
if __name__ == '__main__':
'''
Basic Operations
基本操作
'''
# Connect
# 连接服务器
beanstalk = beanstalkc.Connection(host='123.56.190.65', port=11300)
# See all tubes:
# 查看打印所有通道
print beanstalk.stats_tube('bmi')
# Switch to the default (tube):
# 选择使用哪个通道,这里选择default
beanstalk.use('default')
beanstalk.watch('default')
# To enqueue a job:
# 传入一个参数
beanstalk.put('job_one')
# To receive a job:
job = beanstalk.reserve()
# print a job:
print job.body
# Delete the job:
job.delete()
#-----------------------------
# To enqueue a job:
# 传入一个json格式
obj={}
obj['height'] = 180
obj['weight'] = 75
encodedjson = json.dumps(obj)
beanstalk.use('bmi')
beanstalk.watch('bmi')
beanstalk.put(encodedjson)
# To receive a job:
job = beanstalk.reserve()
# print a job:
data = json.loads(job.body)
print data
print data['height']
# Delete the job:
job.delete()