Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 88,
- "metadata": {},
- "outputs": [],
- "source": [
- "import redis\n",
- "import time\n",
- "import traceback"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 89,
- "metadata": {},
- "outputs": [],
- "source": [
- "r = redis.Redis(host='localhost', port=6379, db=0)\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 90,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "b'bar'"
- ]
- },
- "execution_count": 90,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "r.set('foo', 'bar')\n",
- "r.get('foo')"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 91,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "b'5'"
- ]
- },
- "execution_count": 91,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "r.set('count',1)\n",
- "r.incr('count')\n",
- "r.incr('count')\n",
- "r.incr('count')\n",
- "r.incr('count')\n",
- "r.get('count')"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 92,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "3"
- ]
- },
- "execution_count": 92,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "r.rpush('Artists', 'Three days grace')\n",
- "r.rpush('Artists', '30 Seconds To Mars')\n",
- "r.rpush('Artists', 'starset')\n",
- "r.llen('Artists')\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 93,
- "metadata": {},
- "outputs": [],
- "source": [
- "r.lindex('Artists', 3)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 94,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "b'Three days grace'\n",
- "b'30 Seconds To Mars'\n",
- "b'starset'\n"
- ]
- }
- ],
- "source": [
- "while(r.llen('Artists') != 0):\n",
- "\n",
- " print(r.lpop('Artists'))\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Pub/Sub"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 95,
- "metadata": {},
- "outputs": [],
- "source": [
- "def RedisCheck():\n",
- " p = r.pubsub() \n",
- " p.subscribe('startScripts') \n",
- " PAUSE = True\n",
- " red = redis.StrictRedis(host='localhost', port=6379)\n",
- " \n",
- " while PAUSE: \n",
- " print(\"Waiting For redisStarter...\")\n",
- " message = p.get_message() \n",
- " if message:\n",
- " command = message['data']\n",
- " if command == b'START':\n",
- " PAUSE = False\n",
- " time.sleep(1)\n",
- " \n",
- " print(\"Permission to start :)\")\n",
- " \n",
- " "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 96,
- "metadata": {},
- "outputs": [],
- "source": [
- "def WorkCheck():\n",
- "\n",
- " r = redis.StrictRedis(host='localhost', port=6379) \n",
- "\n",
- " p = r.pubsub() \n",
- "\n",
- " print(\"Starting main scripts...\")\n",
- "\n",
- " r.publish('startScripts', 'START') \n",
- " print(\"Done\")\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.6.5"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Add Comment
Please, Sign In to add comment