Example #1
0
 def SubscribeAppDbObject(self, objpfx):
     r = redis.Redis(unix_socket_path=self.redis_sock, db=swsscommon.APPL_DB)
     pubsub = r.pubsub()
     pubsub.psubscribe("__keyspace@0__:%s*" % objpfx)
     return pubsub
Example #2
0
import time

import redis 
from flask import Flask

app = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)


def get_hit_count():
    retries = 5
    while True:
        try:
            return cache.incr('hits')
        except redis.exceptions.ConnectionError as exc:
            if retries == 0:
                raise exc
            retries -= 1
            time.sleep(0.5)


@app.route('/')
def hello():
    count = get_hit_count()
    return 'Hello World! I have been seen {} times.\n'.format(count)
Example #3
0
import redis

r = redis.Redis(host='192.168.0.152', password='******', port='6379')
r.set('foo', 'Bar')

print(r.get('foo'))
Example #4
0
import redis
conn = redis.Redis('localhost')

user = {"Name":"Pradeep", "Company":"SCTL", "Address":"Mumbai", "Location":"RCP"}
user1 = {"Name":"Pradeep", "Company":"SCTL", "Address":"Mumbai", "Location":"RCP"}

conn.hmset("pythonDict", user)
conn.hmset("pythonDict1", user1)

print(conn.hgetall("pythonDict"))
print(conn.hgetall("pythonDict1"))
print(conn.hgetall())
Example #5
0
import schedule
import time
import settings
import threading
from jobs import keyword_analysis
from pymongo import MongoClient
from secrets import token_urlsafe
from bson.objectid import ObjectId

app = Flask(__name__)

client = MongoClient(settings.MONGODB_ADDRESS, int(settings.MONGODB_PORT))

db_client = client[settings.MONGODB_NAME]
redis_client = redis.Redis(host=settings.REDIS_HOST,
                           port=settings.REDIS_PORT,
                           decode_responses=True)

data_manager = DataManager()
model_manager = ModelManager()

# DEFAULT_CATEGORY_MAPPING = {
#     0: 'kj287XEBrIRcahlYvQoS',  # 中國影響力
#     1: 'kz3c7XEBrIRcahlYxAp6',  # 性少數與愛滋病
#     2: 'lD3h7XEBrIRcahlYeQqS',  # 女權與性別刻板印象
#     3: 'lT3h7XEBrIRcahlYugqq',  # 保健秘訣、食品安全
#     4: 'lj2m7nEBrIRcahlY6Ao_',  # 基本人權問題
#     5: 'lz2n7nEBrIRcahlYDgri',  # 農林漁牧政策
#     6: 'mD2n7nEBrIRcahlYLAr7',  # 能源轉型
#     7: 'mT2n7nEBrIRcahlYTArI',  # 環境生態保護
#     8: 'mj2n7nEBrIRcahlYdArf',  # 優惠措施、新法規、政策宣導
Example #6
0
import redis
import json
import os
from time import sleep 
from random import randint 



if __name__ == '__main__':

    redis_host = os.getenv('REDIS_HOST', 'fila')
    r = redis.Redis(host=redis_host, port=6379, db=0)


    print('Aguardando mensagens...')
    while True:
        mensagem = json.loads(r.blpop('envia')[1])
        print('Enviando a mensagem:', mensagem['nome'])
        sleep(randint(10, 20))
        print('Mensagem', mensagem['nome'], 'enviada')
        
import os

parser = argparse.ArgumentParser(description='Upload an FPGA bitstream to redis',
                                 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('fpg',type=str,
                    help = '.fpg file to upload')
parser.add_argument('-r', dest='redishost', type=str, default='redishost',
                    help ='Host servicing redis requests')

args = parser.parse_args()

if not args.fpg.endswith('.fpg'):
    print("You may only upload FPG files with a '.fpg' extension")
    exit()

if not os.path.exists(args.fpg):
    print("FPG file %s not found!" % args.fpg)
    exit()

r = redis.Redis(args.redishost)

with open(args.fpg, 'r') as fh:
    d = {}
    d["upload_time"] = time.time()
    d["fpg"]         = fh.read()
    d["md5"]         = hashlib.md5(d["fpg"]).hexdigest()
    d["path"]        = os.path.abspath(args.fpg)
    d["hostname"]    = socket.gethostname()
    name = os.path.basename(args.fpg)
    r.hmset('fpg:%s' % name, d)
Example #8
0
from services.config import Production

app = Flask(__name__)
app.config.from_object(Production)

CORS(app)
db = SQLAlchemy(app)
Migrate(app, db)
bcrypt = Bcrypt(app)
api = Api(app)
jwt = JWTManager(app)

# connect database redis
revoked_store = redis.Redis(host='redis-server',
                            port=6379,
                            db=0,
                            decode_responses=True)


@app.errorhandler(ValidationError)
def error_handler(err):
    return err.messages, 400


@jwt.token_in_blacklist_loader
def check_if_token_is_revoked(decrypted_token):
    jti = decrypted_token['jti']
    entry = revoked_store.get(jti)
    if entry is None:
        return True
    return entry == 'true'
# -*- coding:utf-8 -*-
# @Time   : 2019/10/10 9:36
# @Author : Dg
import os
import redis
import xlrd
import xlwt
from xlutils.copy import copy

R_PASS = os.environ["REDIS_PASS"]
print(R_PASS)
r = redis.Redis(host='116.255.163.127', port=6379, password=R_PASS)


def read_excel(path):
    """根据路径读取excel表格,结果为一个列表,里边元素为列表形式的每行数据"""
    """[
        ['姓名', '年龄', '性别', '分数'],
        ['mary', 20, '女', 89.9]
        ]
    """
    # 打开文件
    file_name = path
    workbook = xlrd.open_workbook(file_name)
    #获取sheet
    sheet_name = workbook.sheet_names()[0]
    # 根据sheet索引或者名称获取sheet内容
    # sheet的名称,行数,列数
    sheet_ = workbook.sheet_by_name(sheet_name)
    print(sheet_.name, sheet_.nrows)
    rows = []
Example #10
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-



import redis
import gzip

robj = redis.Redis("localhost", port=6379, db=3)

def redisPush(data):
	
	product_id = data["asin"]
	dic = {}
	val_list = []
	try:
		title = data["title"]
		val_list.append(title)
	except:
		pass
	try:
		price = data["price"]
		val_list.append(price)
	except:
		pass
	try:
		category = data["salesRank"].keys()[0]
		val_list.append(category)
	except:
		pass
	try:
Example #11
0
 def redis(self):
     return redis.Redis(self.redis_host, self.redis_port)
Example #12
0
import zmq
import redis
import json

context = zmq.Context()
zmqSock = context.socket(zmq.SUB)
zmqSock.bind("tcp://127.0.0.1:5000")
zmqSock.setsockopt(zmq.SUBSCRIBE, "0")

redisServer = redis.Redis("localhost")

while True:
    reply = zmqSock.recv()
    keys = redisServer.keys()
    if keys != []:
        for i in range(len(keys)):
            keys[i] = int(keys[i])
        i = max(keys) + 1
    else:
        i = 0
    reply = json.loads(reply[1:])
    reply.append(i)
    reply = json.dumps(reply)
    redisServer.set(i, reply)
Example #13
0
import redis

REDIS_CON = {
    "host": '127.0.0.1',
    "port": 6379,
    "db": 2,
    "decode_responses": True
}

con = redis.Redis(**REDIS_CON)
print(con.rpop('z'))
Example #14
0
 def SubscribeAsicDbObject(self, objpfx):
     r = redis.Redis(unix_socket_path=self.redis_sock, db=swsscommon.ASIC_DB)
     pubsub = r.pubsub()
     pubsub.psubscribe("__keyspace@1__:ASIC_STATE:%s*" % objpfx)
     return pubsub
Example #15
0
    def __init__(self, *args, **kwargs):

        self.r = redis.Redis(host='localhost', port=6379)
        t = threading.Thread(target=self.listen_for_messages)
        t.daemon = True
        t.start()
Example #16
0
import redis

r = redis.Redis(host='54.223.83.133', port=6379, db=0)
# info=r.info()
# print info
# r = redis.StrictRedis(host='54.223.83.133', port=6379, db=0)
length = r.llen('CPS.QUEUE.ANDROID')
print length
Example #17
0
import redis
from flask import Flask
from flask_script import Manager
from flask_session import Session

from back.views import back_blue
from back.models import db
from web.views import web_blue

app = Flask(__name__)

app.register_blueprint(blueprint=back_blue, url_prefix='/hehe/')
app.register_blueprint(blueprint=web_blue, url_prefix='/web/')

app.config[
    'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:[email protected]:3306/blog'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

app.config['SESSION_TYPE'] = 'redis'
app.config['SESSION_REDIS'] = redis.Redis(host='127.0.0.1', port=6379)
# ,password='******'
app.secret_key = '123123412'  # 配置secret_key,否则不能实现session对话

# 初始化,将登陆后的cookice存在redis里面
Session(app)
db.init_app(app)

manage = Manager(app)
if __name__ == '__main__':
    manage.run()
Example #18
0
import redis
import json
import time
import sys

conn = redis.Redis()

while 1:

    keys = conn.keys()

    if len(keys) == 0:
        continue

    values = conn.mget(keys)

    try:
        deltas = [float(v) for v in values]
    except TypeError:
        print keys
        continue

    if len(deltas):
        rate = sum(deltas) / float(len(deltas))
    else:
        rate = 0

    print json.dumps({"rate": rate})
    sys.stdout.flush()

    time.sleep(0.5)
Example #19
0
import json
import redis
import os, sys
import xlrd
import xlwt
from datetime import datetime

pool0 = redis.ConnectionPool(host='127.0.0.1', port='6379', db=0)
hr0 = redis.Redis(connection_pool=pool0)
pool1 = redis.ConnectionPool(host='127.0.0.1', port='6379', db=1)
hr1 = redis.Redis(connection_pool=pool1)
pool2 = redis.ConnectionPool(host='127.0.0.1', port='6379', db=2)
hr2 = redis.Redis(connection_pool=pool2)


sheethead = ['tagname', 'tagdesc', 'fc', 'reg', 'datatype']

print(hr0.keys())
chlists = json.loads(hr0.get('Channel_List_Json').decode('utf-8'))
print(chlists)

for ch in chlists['Channel_List']:
	print(ch)
	chinfo = json.loads(hr0.hget("Channel_List", ch).decode('utf-8'))
	print(chinfo)
	mydev = chinfo['linkdev']
	devtags = eval(hr0.get(mydev))['tags']

	wb = xlwt.Workbook()
	ws2 = wb.add_sheet('sheet1', cell_overwrite_ok=True)
	for n in range(len(sheethead)):
Example #20
0
 def __init__(self):
     self.db = tornado.database.Connection(
         host=options.mysql_host, database=options.mysql_database,
         user=options.mysql_user, password=options.mysql_password)
     self.cache = redis.Redis(host=options.redis_host,port=options.redis_port,db=options.redis_db)
Example #21
0
 def __init__(self):
     self.curl = mcurl.CurlHelper()
     self.redis = redis.Redis(host=config.redis_host,
                              port=config.redis_port,
                              db=config.redis_db)
"""
GET/DEL - example
Language: Python
Client : redis-py
"""
import redis

r = redis.Redis()

print r.set('TOTO', 1)
print r.get('TOTO')

print r.rename('TOTO', 'TOTO:TMP')
print r.get('TOTO:TMP')
print r.delete('TOTO:TMP')

print r.get('TOTO')

Example #23
0
import json,redis,os

TIME_FORMAT='%Y-%m-%d %H:%M:%S'
########################################################################################
#FACT_EXPIRATION = -1
#FACT_EXPIRATION = 86400

redis = redis.Redis()

def log(host, data):
    if type(data) == dict:
    	facts = data.get('ansible_facts', None)

    redis_pipe = redis.pipeline()
    for fact in facts:
        # Only store the basic types (strings) of facts
        #if isinstance(facts[fact], basestring):
        redis_pipe.hset(host, fact, facts[fact])
    #redis_pipe.expire(host, FACT_EXPIRATION)
    redis_pipe.execute()
######################################################################################

#--For all
path = "/tmp/facts/"
hostlist=os.listdir( path )
for file in hostlist:
	if os.path.isfile(path+file):
		json_data = open(path+file)
		data = json.load(json_data)
		log(file, data)
		#os.rename(path+file,path+"done/"+file)
Example #24
0
import json
import uuid
import random
import sys
from random import uniform

ipadress = 'localhost'

if len(sys.argv) > 1 and sys.argv[1] == 'docker':
    print('using docker profile')
    ipadress = '192.168.209.241'

rabbitIP = ipadress
redisIP = ipadress

rediscache = redis.Redis(host=redisIP, port=6379, password='******')

credentials = pika.PlainCredentials('rabbitmq', 'rabbitmqpwd')
connection = pika.BlockingConnection(
    pika.ConnectionParameters(rabbitIP, 5672, '/', credentials))
channel = connection.channel()
channel.queue_declare(queue='gps')

counter = 0
switch = True
phonetype = 'android'

while True:

    id = str(uuid.uuid4())
    genderr = random.choice(["male", "female"])
Example #25
0
#!/usr/bin/env bash
import redis, time, random, datetime, os, json

taskname = os.environ['TASKNAME']

example = {
    'name': taskname,
    'score': 87.33,
    'time': datetime.datetime.now().isoformat()
}
print example

r = redis.Redis('redis')

while True:
    value = r.hgetall('stats.%s' % taskname)
    example['score'] = random.randint(1, 100)
    example['time'] = datetime.datetime.now().isoformat()
    pipe = r.pipeline()
    pipe.hmset('stats.%s' % taskname,
               example).publish(taskname, json.dumps(example)).execute()
    print(value)
    time.sleep(5)
Example #26
0
class GetInfoSpider(scrapy.Spider):
    name = 'get_info'
    allowed_domains = ['http://hz.lianjia.com/']
    # start_urls = ['http://http://hz.lianjia.com/']

    # 连接Redis数据库
    r_link = redis.Redis(host='localhost',
                         port=6379,
                         decode_responses=True,
                         db=1)

    def start_requests(self):
        '''从redis获得ajax信息的url'''
        ajax_url = '1'
        while ajax_url:
            ajax_url = self.r_link.rpop("Lianjia:ajax_url").replace('#', '', 3)
            print("---{}被弹出---".format(ajax_url))
            yield scrapy.Request(
                url=ajax_url,
                callback=self.parse1,
            )

    def parse1(self, response):
        '''获取ajax内的关键信息'''
        response = json.loads(response.text)

        # 根据json中不同类型的数据创建Item对象
        resblock_info = response['data']['resblock']
        item_resblock = LianjiaResblockItem()
        item_resblock['resblockID'] = random.sample(
            response['data']['soldList'], 1)[0]['resblockID']
        item_resblock['name'] = resblock_info['name']
        item_resblock['buildYear'] = resblock_info['buildYear']
        item_resblock['buildType'] = resblock_info['buildType']
        item_resblock['unitPrice'] = resblock_info['unitPrice']
        item_resblock['sellNum'] = resblock_info['sellNum']
        item_resblock['rentNum'] = resblock_info['rentNum']
        item_resblock['rentUrl'] = resblock_info['rentUrl']
        item_resblock['sellUrl'] = resblock_info['sellUrl']
        item_resblock['viewUrl'] = resblock_info['viewUrl']
        item_resblock['infoType'] = 'resblock'
        yield item_resblock

        sold_info = response['data']['soldList']
        item_sold = LianjiaSoldInfoItem()
        for house_sold in sold_info:
            item_sold['houseCode'] = house_sold['houseCode']
            item_sold['titleString'] = house_sold['titleString']
            item_sold['signPrice'] = house_sold['signPrice']
            item_sold['listPrice'] = house_sold['listPrice']
            item_sold['dealCycle'] = house_sold['dealCycle']
            item_sold['signTime'] = house_sold['signTime']
            item_sold['houseAreaNum'] = house_sold['houseAreaNum']
            item_sold['unitPrice'] = house_sold['unitPrice']
            item_sold['resblockName'] = house_sold['resblockName']
            item_sold['year'] = house_sold['year']
            item_sold['buildingType'] = house_sold['buildingType']
            item_sold['framePicUrl'] = house_sold['framePicUrl']
            item_sold['elevator'] = house_sold['elevator']
            item_sold['isGarage'] = house_sold['isGarage']
            item_sold['frameOrientation'] = house_sold['frameOrientation']
            item_sold['decorationType'] = house_sold['decorationType']
            item_sold['districtName'] = house_sold['districtName']
            item_sold['bizcircleName'] = house_sold['bizcircleName']
            item_sold['districtId'] = house_sold['districtId']
            item_sold['subwayInfo'] = house_sold['subwayInfoString']
            item_sold['schoolInfo'] = house_sold['schoolInfoString']
            item_sold['floorInfo'] = house_sold['floorInfo']
            item_sold['infoType'] = 'sold'
            yield item_sold

        sell_info = response['data']['sellList']
        item_sell = LianjiaSellInfoItem()
        for house_sell in sell_info.values():
            item_sell['houseCode'] = house_sell['houseCode']
            item_sell['title'] = house_sell['title']
            item_sell['layoutImgSrc'] = house_sell['layoutImgSrc']
            item_sell['roomNum'] = house_sell['roomNum']
            item_sell['buildingArea'] = house_sell['buildingArea']
            item_sell['buildYear'] = house_sell['buildYear']
            item_sell['ctime'] = house_sell['ctime']
            item_sell['orientation'] = house_sell['orientation']
            item_sell['totalFloor'] = house_sell['totalFloor']
            item_sell['decorateType'] = house_sell['decorateType']
            item_sell['hbtName'] = house_sell['hbtName']
            item_sell['isGarage'] = house_sell['isGarage']
            item_sell['address'] = house_sell['address']
            item_sell['communityName'] = house_sell['communityName']
            item_sell['communityId'] = house_sell['communityId']
            item_sell['districtName'] = house_sell['districtName']
            item_sell['districtId'] = house_sell['districtId']
            item_sell['regionName'] = house_sell['regionName']
            item_sell['subwayInfo'] = house_sell['subwayInfo']
            item_sell['schoolName'] = house_sell['schoolName']
            item_sell['price'] = house_sell['price']
            item_sell['unitPrice'] = house_sell['unitPrice']
            item_sell['infoType'] = 'sell'
            yield item_sell

        resblockSoldUrl = self.allowed_domains[0][:-1] + response['data'][
            'resblockSoldUrl']
        resblockSellUrl = self.allowed_domains[0][:-1] + response['data'][
            'resblockSellUrl']
        self.r_link.rpush("Lianjia:resblockSoldUrl", resblockSoldUrl)
        self.r_link.rpush("Lianjia:resblockSellUrl", resblockSellUrl)
from markupsafe import escape
from xlsxwriter import Workbook

from webdriver import fujian
from flask import jsonify
from flask_caching import Cache

import datetime
import redis
import pandas as pd

from webdriver.brisbane import Brisbane

app = Flask(__name__)
auto = Autodoc(app)
r = redis.Redis(host=redis)

# GROUND ZERO ZONE
term = 2
EXCELMIME = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

cache = Cache(app,
              config={
                  'CACHE_TYPE': 'redis',
                  'CACHE_KEY_PREFIX': 'fujian_',
                  'CACHE_REDIS_HOST': 'redis',
                  'CACHE_REDIS_PORT': '6379'
              })

studentcache = Cache(app,
                     config={
Example #28
0
from datetime import datetime
import redis

# Establish redis connection
r = redis.Redis(host='redis', port=6379, db=0)


def redis_demo():
    """ Example use of setting and retrieving a key in redis
    """
    recipes = (
        (
            "sandwich_ham",
            "ingredients: ['wheat bread', 'cheddar', 'ham']"
        ),
        (
            "sandwich_turkey",
            "ingredients: ['wheat bread', 'cheddar', 'turkey']"
        ),
        (
            "cheese_platter_1",
            "ingredients: ['cheddar', 'mozzarella', 'olives']"
        ),
        (
            "cheese_platter_2",
            "ingredients: ['pepper jack', 'mozzarella', 'olives']"
        )
    )
    for recipe in recipes:
        r.set(recipe[0], recipe[1])
Example #29
0
    Antibody_detail_URL = Column(String(500),
                                 nullable=True, comment='')
    Crawl_Date = Column(DateTime, server_default=func.now(),
                        nullable=True, comment='')
    Note = Column(String(500),
                  nullable=True, comment='')
    Antibody_Status = Column(String(20),
                             nullable=True, comment='')
    Antibody_Type = Column(String(100),
                           nullable=True, comment='')


engine = create_engine(
    'mysql+pymysql://root:[email protected]:3306/biopick?charset=utf8')
DBSession = sessionmaker(bind=engine)
session = DBSession()

pool = redis.ConnectionPool(host='localhost', port=6379, decode_responses=True,
                            db=2)
r = redis.Redis(connection_pool=pool)

task_list = session.query(Data.Antibody_detail_URL).all()
for i in task_list:
    url = i[0]
    r.rpush('immunoway_detail', url)
    print(i[0])
# # # print(r.rpop('test_task'))
# # # print(type(r.rpop('test_task')))

pool.disconnect()
Example #30
0
 def __init__(self):
     self.__conn = redis.Redis(host='172.16.95.132')
     self.chan_sub = 'fm104.5'
     self.chan_pub = 'fm104.5'