Exemplo n.º 1
0
 def work():
     r = None
     try:
         r = pyredis.Client(host=REDIS_IP, port=REDIS_PORT)
     finally:
         if r is not None:
             r.close()
Exemplo n.º 2
0
    def read_data(self, redis_key, field_name, prop_name, data_type, lang_src,
                  lang_dest):
        return_data = None

        try:
            if lang_src is 'python':
                redis_conn = pyredis.Client(host=self.redis_host,
                                            port=self.redis_port,
                                            database=self.redis_db,
                                            password=self.redis_pass)

                prev_output = redis_conn.hget(redis_key, field_name)
                if prev_output is not None:
                    prev_output = pickle.loads(prev_output)

                    if prop_name in prev_output:
                        return_data = prev_output[prop_name]
            elif lang_src is 'r':
                r_string = 'library(rredis);redisConnect("192.168.0.74", 6379, "brique0901#$");redisSelect(1);'
                r_string += 'prev_output <- redisHGet("' + redis_key + '", "' + field_name + ");prev_output;"

                robjects.r(r_string)
                return_data = robjects.r('prev_output[["' + prop_name + '"]]')

                if 'single' in data_type:
                    return_data = return_data[0]
        except Exception as ex:
            return_data = None
            logging.error("ERR: %s", ex.__str__())

        if return_data is not None:
            return_data = self.convert_data_to_str(prop_name, return_data,
                                                   lang_dest, data_type)

        return return_data
Exemplo n.º 3
0
 def work():
     r = None
     try:
         r = pyredis.Client(host=REDIS_IP, port=REDIS_PORT)
         r.set(KEY, VAL).decode() == 'OK'
         r.get(KEY).decode() == VAL
         r.delete(KEY) == 1
     finally:
         if r is not None:
             r.close()
Exemplo n.º 4
0
 def work():
     r = None
     try:
         r = pyredis.Client(host=REDIS_IP_B, port=REDIS_PORT)
         r.set(KEY_B, VAL_B) == b'OK'
         r.get(KEY_B) == VAL_B
         r.delete(KEY_B) == 1
     finally:
         if r is not None:
             r.close()
Exemplo n.º 5
0
 def work():
     r = None
     try:
         r = pyredis.Client(host=REDIS_IP_B, port=REDIS_PORT)
         for key in keys:
             assert r.set(key, key) == b'OK'
         for key in keys:
             assert r.delete(key) == 1
     finally:
         if r is not None:
             r.close()
Exemplo n.º 6
0
# client.set('key2', 'value2')
# client.set('key3', 'value3')
# client.bulk_stop()
# [b'OK', b'OK', b'OK']

import sys

sys.path.append('/mnt/d/Documents/GitHub/program_exercise/show_me_the_code/')
sys.path.append(r'D:\\Documents\\GitHub\\program_exercise\\show_me_the_code\\')

from python3.s02 import s02
import pyredis

# print(s02.generate_promote_code(10))

client = pyredis.Client(host='localhost')


def put_keys():
    if client.ping():
        print('connected')
        client.bulk_start()
        for i in range(200):
            client.set('key{}'.format(i), s02.generate_promote_code(10))
        client.bulk_stop()


def get_keys():
    if client.ping():
        for i in range(200):
            # print(i)
Exemplo n.º 7
0
from aiohttp import web, WSMsgType
import pyredis
import json
import service_controller

# aiohttp web app
app = web.Application()

try:
	# Redis client
	redis_client = pyredis.Client(host="localhost")
	#  Set UI enabled by default
	if not redis_client.get('enable_ui'):
		redis_client.set('enable_ui', True)
except Exception:
	print("Redis connection failed")

# Array of client websocket connections
clients = []
# Service to control
service = "ssh"

def is_ui_enabled():
	return redis_client.get('enable_ui') == b"True";

def set_ui_enabled(state):
	redis_client.set('enable_ui', state)

async def get_handler(request):
	return web.Response(body=open('static/index.html').read(), content_type="text/html")