This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A proposed method for choosing which slaves to monitor within the | |
# Redis HA sentinel monitors | |
def select_slaves_to_monitor(slave_info, all_sentinels, my_id, my_slaves): | |
''' | |
slave_info = [ | |
('ip_or_host:port', ['sentinel-id, ...]), | |
... | |
] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''A function to refresh a lock that can timeout, before it times out.''' | |
def refresh_lock(conn, lockname, identifier, lock_timeout=10): | |
pipe = conn.pipeline(True) | |
lockname = 'lock:' + lockname | |
while True: | |
try: | |
pipe.watch(lockname) | |
if pipe.get(lockname) == identifier: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Written December 7, 2012 by Josiah Carlson | |
Released into the public domain. | |
Untested. | |
''' | |
from binascii import crc32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Answer to this thread: | |
http://www.manning-sandbox.com/thread.jspa?messageID=140363 | |
''' | |
def refresh_lock(conn, lockname, identifier, timeout=10): | |
pipe = conn.pipeline(True) | |
lockname = 'lock:' + lockname |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
prefix_code.py | |
Copyright 2012-2013 Josiah Carlson | |
Released under the GNU LGPL v 2.1 license | |
This module offers the ability to encode/decode a sequence of integers into | |
strings that can then be used to compare sequences of integers (or paths on | |
trees) quickly. This module was originally intended to be used in a case- | |
preserving index in a relational database (where 'Z' comes before 'a', as is |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
''' | |
Steganogrphy in Python | |
Copyright 2013 Josiah Carlson | |
Released under the GNU LGPL v2.1 license | |
What, how, why, etc, are discussed: | |
http://www.dr-josiah.com/2013/05/steganography-in-python.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
This is a module that defines some helper classes and functions for | |
expiring groups of related keys at the same time. | |
Written July 1-2, 2013 by Josiah Carlson | |
Released into the public domain | |
''' | |
import time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import rom | |
class ModelA(rom.Model): | |
m2m_test = rom.OneToMany('HiddenModel') | |
@property | |
def b_models(self): | |
return [x.model_b for x in self.m2m_test] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import redis | |
def _script_load(script): | |
''' | |
Borrowed from my book, Redis in Action: | |
https://github.com/josiahcarlson/redis-in-action/blob/master/python/ch11_listing_source.py | |
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
The Josiah Carlson recommended way of replacing the session object. This code | |
should be run prior to any subsequent imports/uses of the session object. | |
Released into the public domain. | |
''' | |
from rom import util |