Making The Most of Your Data Store

Making The Most of Your Data Store

Making The Most of Your Data Store
Or (hopefully) some tricks you probably didn’t know.

305cabbbad7039ea3a7e8b9be6f59619?s=128

Dougal Matthews

August 01, 2012
Tweet

Transcript

  1. 1.

    Making The Most of Your Data Store Or (hopefully) some

    tricks you probably didn’t know. Dougal Matthews dougalmatthews.com twitter.com/d0ugal Wednesday, 1 August 12
  2. 5.

    >>> from redis import Redis >>> r = Redis() >>>

    pubsub = r.pubsub() >>> pubsub.subscribe("queue_name") >>> r.publish("queue_name", "My Message.") 1L >>> print pubsub.listen().next() {'pattern': None, 'type': 'subscribe', 'channel': 'queue_name', 'data': 1L} >>> print pubsub.listen().next() {'pattern': None, 'type': 'message', 'channel': 'queue_name', 'data': 'My Message.'} Pub Sub Wednesday, 1 August 12
  3. 7.

    >>> from redis import Redis >>> r = Redis() >>>

    r.set('foo', 'bar') >>> pipe = r.pipeline() >>> # Queue up operations >>> pipe.get('foo') >>> pipe.set('foo', 'baz') >>> pipe.get('foo') >>> pipe.execute() ['bar', True, 'baz'] redis-py Pipelines Wednesday, 1 August 12
  4. 10.

    CREATE TABLE example ( id serial PRIMARY KEY, data hstore);

    INSERT INTO example (data) VALUES ('name => "John Smith", age => 28, gender => "M"'), ('name => "Jane Smith", age => 24'); SELECT id, data->'name' FROM example; SELECT id, data->'age' FROM example WHERE data->'age' >= '25'; hstore Wednesday, 1 August 12
  5. 11.

    CREATE LANGUAGE plpythonu; CREATE FUNCTION pymax (a integer, b integer)

    RETURNS integer AS $$ if a > b: return a return b $$ LANGUAGE plpythonu; SELECT pymax(1, 2); PL/Python Wednesday, 1 August 12
  6. 12.

    import psycopg2 from psycopg2.extras import wait_select aconn = psycopg2.connect(..., async=1)

    wait_select(aconn) acurs = aconn.cursor() acurs.execute("SELECT pg_sleep(5); SELECT * FROM example;") wait_select(acurs.connection) acurs.fetchone()[0] Psycopg2 and Async Wednesday, 1 August 12
  7. 17.

    Tekpub: Why Not MySQL? http://s.do.ugal.me/IQ0z Rob Conery - Five Things

    You Didn't Know About PostGresSQL http://s.do.ugal.me/IQvc ...but more seriously Wednesday, 1 August 12