•Chia làm 5 loại dữ liệu khác nhau:
STRING:
Có thể là
string, integer hoặc float. Redis có thể làm việc với cả
string, từng phần của
string, cũng như tăng/giảm giá trị của
integer, float.
LIST: Danh sách liên kết của các
strings. Redis hỗ trợ các thao tác
push, pop từ cả 2 phía của
list, trim dựa theo
offset, đọc 1 hoặc nhiều
items của
list, tìm kiếm và xóa giá trị.
SET: Tập hợp các
string (không được sắp xếp). Redis hỗ trợ các thao tác thêm, đọc, xóa từng phần tử, kiểm tra sự xuất hiện của phần tử trong tập hợp. Ngoài ra Redis còn hỗ trợ các phép toán tập hợp, gồm
intersect/union/difference.
HASH:
Lưu trữ hash
table của các cặp
key-value, trong đó key được sắp xếp ngẫu nhiên, không theo thứ tự nào cả. Redis hỗ trợ các thao tác thêm, đọc, xóa từng phần tử, cũng như đọc tất cả giá trị.
ZSET
(sorted set): Là 1 danh sách, trong đó mỗi phần tử là map của 1
string (member) và 1
floating-point number (score), danh sách được sắp xếp theo score này. Redis hỗ trợ thao tác thêm, đọc, xóa từng phần tử, lấy ra các phần tử dựa theo range của score hoặc của string.
•Download,
extract and compile Redis
with:
$ wget
http://download.redis.io/releases/redis-2.8.19.tar.gz
$ tar
xzf
redis-2.8.19.tar.gz
$ cd
redis-2.8.19
$
make
•The
binaries that are now compiled are available in the src
directory. Run Redis
with:
$ src/redis-server
•You
can interact with Redis
using the built-in client:
$ src/redis-cli
redis>
set foo bar
OK
redis>
get foo
"bar"
•Config with
CI
Copy Redis.php file
in libraries to application\libraries in CI. Then, copy redis.php file
in config to
application\config in
CI.
Open autoload.php in
application\config in
CI add more libraries “redis”
like that image:
Thực hiện tạo 1 sample Redis trong Codeigniter:
Tại Controller: tạo file content.php (controller/gallery/content.php)