###### tags: `jptw` `thesis` `technology` `database` `redis` # Notes for Database ## SQLite > Ref: > [1] [SQLite - AND & OR Operators](https://www.tutorialspoint.com/sqlite/sqlite_and_or_clauses.htm) > [2] [sqlite3 — DB-API 2.0 interface for SQLite databases](https://docs.python.org/3/library/sqlite3.html) > [3] [SQLite Python: Inserting Data](https://www.sqlitetutorial.net/sqlite-python/insert/) ## Redis ### Installation ```shell $ brew install redis ``` ### Quick Start ```shell $ redis-server # run server $ ps-ef | grep redis # check redis state ``` ### How To Use ```shell $ 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](https://blog.techbridge.cc/2016/06/18/redis-introduction/) > [2] [IT|軟體|資料庫|Key-Value|Redis 安裝](https://ithelp.ithome.com.tw/articles/10195413) > [3] [Redis快速入門](http://tw.gitbook.net/redis/redis_quick_guide.html) > [4] [Redis command to get all available keys?](https://stackoverflow.com/questions/5252099/redis-command-to-get-all-available-keys) > > Related to admin settings: > [1] [Redis設定密碼](https://codertw.com/%E8%B3%87%E6%96%99%E5%BA%AB/126657/) > [2] [ow to set password for Redis?](https://stackoverflow.com/questions/7537905/how-to-set-password-for-redis) > ### In Django App **Requirement** ```shell > pip install django-redis ``` **`settings.py`** ```python CACHES = { 'default': { 'BACKEND': 'django_redis.cache.RedisCache', 'LOCATION': 'redis://127.0.0.1:6379', "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", }, }, } ``` **Test** ```python from django.core.cache import cache cache.set('key', 'value') cache.has_key('key') cache.get('key') ``` **Example** ```python from django_redis import get_redis_connection default = get_redis_connection('default') default.set('key', 'value') value = defaule.get('key') ``` > Ref: > [1] [Django使用Redis进行缓存详细最全流程](https://blog.csdn.net/sinat_29699167/article/details/79699200) > [2] [Caching in Django With Redis](https://realpython.com/caching-in-django-with-redis/) > [3] [How to use redis commands for lists and sets in Django app](https://stackoverflow.com/questions/22499236/how-to-use-redis-commands-for-lists-and-sets-in-django-app) > [4] [2018-12-5 django-redis 的使用](https://zhuanlan.zhihu.com/p/51920884)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up