前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Django DRF Redis

Django DRF Redis

原创
作者头像
vanguard
修改2021-01-05 10:36:42
4650
修改2021-01-05 10:36:42
举报
文章被收录于专栏:vanguardvanguard

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.

REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统。Redis是一个开源的使用ANSI C语言编写、遵守BSD协议、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。它通常被称为数据结构服务器,因为值(value)可以是 字符串(String), 哈希(Hash), 列表(list), 集合(sets) 和 有序集合(sorted sets)等类型。

server - python - django:

代码语言:python
复制
# setting.py
# pip3 install django-redis
CACHES = {
    "default": {
        "BACKEND": "django_redis.cache.RedisCache",
        "LOCATION": "redis://127.0.0.1:6379",
        "OPTIONS": {
            "CLIENT_CLASS": "django_redis.client.DefaultClient",
            "PICKLE_VERSION": -1,
            # "PASSWORD": "SECRET",
        }
    }
}
代码语言:python
复制
# redis-server
# view.py
# pip install django==2.2.7
from django.core.cache import cache
from parking.models import *
def redis_pool(key_id, val_dt=None):
    try:
        if val_dt is None: return cache.get(key_id)
        cache.set(key_id, val_dt); return True
    except: return False
try:
    redis_pool('hello', 'world')
    print(redis_pool('hello'))
except Exception as e:
    print(e)

server Installation - linux:

代码语言:shell
复制
# linux (centos7)
wget http://download.redis.io/releases/redis-5.0.7.tar.gz
tar -zvxf redis-5.0.7.tar.gz
make && make install
mkdir /etc/local/redis
mkdir /etc/local/redis/bin/
mkdir /etc/local/redis/etc/
mv redis.conf /usr/local/redis/etc/
cd src
mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-server /usr/local/redis/bin/
./redis-serve
# more config
bind 127.0.0.1
vi /usr/local/redis/etc/redis.conf
daemonize -> yes
redis-server /usr/local/redis/etc/redis.conf
ln -s /usr/local/redis/bin/redis-server /usr/bin/redis-server
# yum
yum install redis / yum install epel-release
yum install redis 
# apt
sudo apt-get install redis-server
sudo apt-get purge --auto-remove redis-server
# Runtime (centOS7 / unbuntu)
service redis start / sudo service redis-server start
service redis stop / sudo service redis-server stop 
service redis status / ps aux|grep redis
ps -ef | grep redis
# auto start
chkconfig redis on
# windows https://github.com/microsoftarchive/redis/releases
# macos
# brew update
# brew install redis
# brew services start redis
# redis-server /usr/local/etc/redis.conf # background service
# redis-cli ping # runtime check
# /usr/local/etc/redis.conf
# brew uninstall redis # uninstall
# rm ~/Library/LaunchAgents/homebrew.mxcl.redis.plist

client test - python

代码语言:python
复制
import redis # pip install redis
r = redis.Redis(host="10.170.15.54", port='6379')
r.set('hello','there')
print((r.get('hello')))

https://django-redis-chs.readthedocs.io/zh_CN/latest/

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 Redis
腾讯云数据库 Redis(TencentDB for Redis)是腾讯云打造的兼容 Redis 协议的缓存和存储服务。丰富的数据结构能帮助您完成不同类型的业务场景开发。支持主从热备,提供自动容灾切换、数据备份、故障迁移、实例监控、在线扩容、数据回档等全套的数据库服务。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档