本文整理汇总了Python中redis.publish函数的典型用法代码示例。如果您正苦于以下问题:Python publish函数的具体用法?Python publish怎么用?Python publish使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了publish函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: inbox
def inbox(ws):
while not ws.closed:
gevent.sleep(0.1)
message = ws.receive()
if message:
redis.publish('chat', message)
示例2: worker
def worker (self):
print "simulador worker"
while 1:
msgFromController = self.ser.readline().strip()
if (msgFromController=="#estadoPlanta!"):
self.planta.ref = xref
# y, ref
# Tests
#(a,b) = genRandomPairs()
# envia (y , ref)
self.iteration += 1
myTime = time.time()
estado = {'outs':[self.planta.out, self.planta.ref - self.planta.out, self.planta.actu], 'ts':myTime, 'msg_id':self.iteration}
redis.publish (toRedisOut, json.dumps(estado))
print "estado planta: ", estado
msg = self.armaMsg(floatToDigital(self.planta.out), floatToDigital(self.planta.ref))
self.sendMessageToController (msg)
else:
try:
actu = msgFromController.strip('#').strip('!')
self.planta.iterate( digitalToFloat(int(actu)))
except:
pass
示例3: exit_app
def exit_app(self, redis, root, event=None):
root.destroy()
j = {'action': 'quit'}
jstr = json.dumps(j)
for channel in ['uwtec:front', 'uwtec:rear', 'uwtec:side']:
redis.publish(channel, jstr)
示例4: main
def main():
"""
main entry point for the program
The return value will be the returncode for the program
"""
_initialize_stderr_logging()
log = logging.getLogger("main")
log.info("program starts")
args = _parse_commandline()
redis = _create_redis_connection()
start_time = time.time()
elapsed_time = 0.0
while elapsed_time < args.test_duration:
try:
key, count = _store_one_key(args)
except Exception:
log.exception("_store_one_key")
return 1
# there is some latency in file_name_set_manager
# so we pause before notifying the consumer
interval = random.uniform(args.min_key_interval, args.max_key_interval)
time.sleep(interval)
redis_key = "_".join([args.redis_prefix, key])
message = "{0} {1}".format(redis_key, count)
redis.publish(args.notification_channel, message)
elapsed_time = time.time() - start_time
log.info("program completes return code = 0")
return 0
示例5: zoom_x1
def zoom_x1(self, redis, channel, button, event=None):
button.config(state='normal', background='orange')
button.after(600, lambda: button.config(state='normal', background='#d9d9d9'))
j = {'action': 'zoom_x1'}
jstr = json.dumps(j)
redis.publish(channel, jstr)
示例6: autozoom
def autozoom(self, redis, channel, autozoom, event=None):
if autozoom.get():
j = {'action': 'autozoom', 'value': True}
else:
j = {'action': 'autozoom', 'value': False}
jstr = json.dumps(j)
redis.publish(channel, jstr)
示例7: edit
def edit(request, room):
was_private = room.is_private
if request.method == 'POST':
form = RoomForm(request.POST, instance=room)
if form.is_valid():
form.save(commit=False)
room.save()
if room.is_private and not was_private:
redis = create_redis_connection()
redis.publish('web_channel', 'room_private:' + str(room.id))
try:
redis.hdel(redis_room_key(room.id), *redis.hkeys(redis_room_key(room.id)))
except:
pass
return HttpResponseRedirect(request.get_full_path())
else:
form = RoomForm(instance=room)
response_data = { 'form' : form }
if room.is_private:
response_data['invited_users'] = room.invited.order_by('username').all()
response_data['users'] = User.objects.exclude(pk=room.owner.id).exclude(rooms__pk=room.id).order_by('username').all()
return response_data
示例8: inbox
def inbox(ws):
# Receives incoming POST requests and inserts them into Redis.
while ws.socket is not None:
# Sleep to prevent *constant* context-switches.
gevent.sleep(0.1)
message = ws.receive()
redis.publish(DATABASE_BROADCASTER, message)
示例9: inbox
def inbox(ws):
"""Receives incoming chat messages, inserts them into Redis."""
while ws.socket is not None:
# Sleep to prevent *contstant* context-switches.
gevent.sleep(0.1)
message = ws.receive()
#print message
#sys.stdout.flush()
if message:
jsonMessage = json.loads(message)
#NLTK version analysis
#message = message.replace("}", ',\"' + 'length\":\"' + str( getLengthOfMessage(message) )+ '\"' + ',\"' + 'neg\":\"' + str(getNegEmotionValue(jsonMessage["text"])) + '\"' + ',\"' + 'pos\":\"' + str(getPosEmotionValue(jsonMessage["text"])) + '\"' + '}' )
#SentiStrength analysis
text = jsonMessage["text"]
sentistrength_result = RateSentiment(text)
name = jsonMessage["handle"]
posV = sentistrength_result[:1]
negV = sentistrength_result[2:]
emotionV = getEmotionValueFrom( int(posV), int(negV) )
message = message.replace("}", ',\"' + 'length\":\"' + str( getLengthOfMessage(message) )+ '\"' + ',\"' + 'neg\":\"' + sentistrength_result[2:] + '\"' + ',\"' + 'pos\":\"' + sentistrength_result[:1] + '\"' + '}' )
print emotionV
sys.stdout.flush()
app.logger.info(u'Inserting message: {}'.format(message))
#post the message to given channel
redis.publish(REDIS_CHAN, message)
chats.saveToFirebase( name, text, emotionV )
示例10: offset_madness
def offset_madness():
offset = 1
while offset:
offset = raw_input("Add offset (ms) >> ")
if offset:
offset = float(offset)
data = {"offsetInMillis": offset}
redis.publish('song-adjust', json.dumps(data))
示例11: rate_adjust
def rate_adjust():
rate = 1.
while rate:
rate = raw_input('New rate >> ')
if rate:
rate = float(rate)
data = {"rateAdjustFactor": rate}
redis.publish('song-adjust', json.dumps(data))
示例12: outbox
def outbox(ws):
chat.register(ws)
redis.publish('chat', json.dumps(dict(
username='New user come in, people count',
text=len(chat.clients)
)))
while not ws.closed:
gevent.sleep(0.1)
示例13: main
def main():
client = KafkaClient("localhost:9092")
consumer = SimpleConsumer(client, "test-group", "twitter_raw")
consumer.seek(0,2)
num = 0
for message in consumer:
print "redis publish:", num
num+=1
try:
data_depickled = pickle.loads(message.message.value.decode('utf-8'))
except Exception, e:
continue
# print data_depickled
# {
# 'text':'@_LulaMoore me hamas perra',
# 'created_at':datetime.datetime(2015, 10, 9, 23, 36, 49),
# 'source':u'Twitter Web Client',
# 'lang:':u'es',
# 'place':{
# 'country_code':u'AR',
# 'coordinates':[
# [
# -68.176283,
# -38.984724
# ],
# [
# -68.176283,
# -38.921051
# ],
# [
# -68.015162,
# -38.921051
# ],
# [
# -68.015162,
# -38.984724
# ]
# ]
# },
# 'user':{
# 'statuses_count':15067,
# 'name':u'Dama negra *\uffe6*',
# 'friends_count':390,
# 'created_at':datetime.datetime(2014, 3, 15,2,37, 10),
# 'profile_image_url': u'http://pbs.twimg.com/profile_images/652333268256313344/x9K9Nlys_normal.jpg',
# 'followers_count':384,
# 'id':2390242428
# },
# 'id':652628813935980544
# }
### process data here ###
# text = data_depickled['text']
filtered_data = data_filter(data_depickled)
data_pickled = pickle.dumps(filtered_data)
redis.publish('tweets_processed', data_pickled)
示例14: inbox
def inbox(ws):
"""Receives incoming chat messages, inserts them into Redis."""
while ws.socket is not None:
# Sleep to prevent *contstant* context-switches.
gevent.sleep(0.1)
message = ws.receive()
if message:
app.logger.info(u'Inserting message: %s'%message)
redis.publish(MAIN_CHAN, message)
示例15: inbox
def inbox(ws):
"""Receives incoming chat messages, inserts them into Redis."""
while not ws.closed:
# Sleep to prevent *constant* context-switches.
gevent.sleep(0.1)
message = ws.receive()
if message:
app.logger.info(u'Inserting message: {}'.format(message))
redis.publish(REDIS_CHAN, message)