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代码运行次数:0复制# 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代码运行次数:0复制# 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代码运行次数:0复制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/