Try   HackMD
tags: jptw thesis technology database redis

Notes for Database

SQLite

Ref:
[1] SQLite - AND & OR Operators
[2] sqlite3 — DB-API 2.0 interface for SQLite databases
[3] SQLite Python: Inserting Data

Redis

Installation

$ brew install redis

Quick Start

$ redis-server          # run server
$ ps-ef | grep redis    # check redis state

How To Use

$ redis-cli

redis 127.0.0.1:6379> SET key "value"
OK
redis 127.0.0.1:6379> GET key
"value"

Useful commands
KEYS * list all keys

Ref:
[1] 資料庫的好夥伴:Redis
[2] IT|軟體|資料庫|Key-Value|Redis 安裝
[3] Redis快速入門
[4] Redis command to get all available keys?

Related to admin settings:
[1] Redis設定密碼
[2] ow to set password for Redis?

In Django App

Requirement

> pip install django-redis

settings.py

CACHES = {
    'default': {
        'BACKEND': 'django_redis.cache.RedisCache',
        'LOCATION': 'redis://127.0.0.1:6379',
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
        },
    },
}

Test

from django.core.cache import cache
cache.set('key', 'value')
cache.has_key('key')
cache.get('key')

Example

from django_redis import get_redis_connection

default = get_redis_connection('default')
default.set('key', 'value')
value = defaule.get('key')

Ref:
[1] Django使用Redis进行缓存详细最全流程
[2] Caching in Django With Redis
[3] How to use redis commands for lists and sets in Django app
[4] 2018-12-5 django-redis 的使用