1
0
mirror of https://github.com/actix/examples synced 2024-11-27 16:02:57 +01:00

Database interactions/redis (#524)

Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
Christopher Gubbin 2022-02-15 00:35:00 +00:00 committed by GitHub
parent 7ea3f7f54a
commit 5c1e25fe52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 158 additions and 353 deletions

368
Cargo.lock generated
View File

@ -36,7 +36,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1be241f88f3b1e7e9a3fbe3b5a8a0f6915b5a1d7ee0d9a248d3376d01068cc60" checksum = "1be241f88f3b1e7e9a3fbe3b5a8a0f6915b5a1d7ee0d9a248d3376d01068cc60"
dependencies = [ dependencies = [
"actix-rt 1.1.1", "actix-rt 1.1.1",
"actix_derive", "actix_derive 0.5.0",
"bitflags", "bitflags",
"bytes 0.5.6", "bytes 0.5.6",
"crossbeam-channel 0.4.4", "crossbeam-channel 0.4.4",
@ -45,7 +45,7 @@ dependencies = [
"futures-util", "futures-util",
"log", "log",
"once_cell", "once_cell",
"parking_lot 0.11.2", "parking_lot",
"pin-project 0.4.29", "pin-project 0.4.29",
"smallvec", "smallvec",
"tokio 0.2.25", "tokio 0.2.25",
@ -61,6 +61,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3720d0064a0ce5c0de7bd93bdb0a6caebab2a9b5668746145d7b3b0c5da02914" checksum = "3720d0064a0ce5c0de7bd93bdb0a6caebab2a9b5668746145d7b3b0c5da02914"
dependencies = [ dependencies = [
"actix-rt 2.6.0", "actix-rt 2.6.0",
"actix_derive 0.6.0",
"bitflags", "bitflags",
"bytes 1.1.0", "bytes 1.1.0",
"crossbeam-channel 0.5.2", "crossbeam-channel 0.5.2",
@ -70,7 +71,7 @@ dependencies = [
"futures-util", "futures-util",
"log", "log",
"once_cell", "once_cell",
"parking_lot 0.11.2", "parking_lot",
"pin-project-lite 0.2.8", "pin-project-lite 0.2.8",
"smallvec", "smallvec",
"tokio 1.16.1", "tokio 1.16.1",
@ -248,7 +249,6 @@ version = "2.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2be6b66b62a794a8e6d366ac9415bb7d475ffd1e9f4671f38c1d8a8a5df950b3" checksum = "2be6b66b62a794a8e6d366ac9415bb7d475ffd1e9f4671f38c1d8a8a5df950b3"
dependencies = [ dependencies = [
"actix 0.10.0",
"actix-codec 0.3.0", "actix-codec 0.3.0",
"actix-connect", "actix-connect",
"actix-rt 1.1.1", "actix-rt 1.1.1",
@ -423,40 +423,14 @@ dependencies = [
[[package]] [[package]]
name = "actix-redis" name = "actix-redis"
version = "0.9.2" version = "0.10.0-beta.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac08092eec10bd695a8bcd64d4dbc29fa4f3495cbd669be41d3355dd51213882" checksum = "184451f4945b4b9bf47417014658781ffad2d415bf5a886809cba9303a70b420"
dependencies = [
"actix 0.10.0",
"actix-http 2.2.2",
"actix-rt 1.1.1",
"actix-service 1.0.6",
"actix-session 0.4.1",
"actix-utils 2.0.0",
"actix-web 3.3.3",
"backoff",
"derive_more",
"futures-util",
"log",
"rand 0.7.3",
"redis-async 0.6.6",
"serde 1.0.136",
"serde_json",
"time 0.2.27",
"tokio 0.2.25",
"tokio-util 0.3.1",
]
[[package]]
name = "actix-redis"
version = "0.10.0-beta.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54f9df32d7d0176d2acca0bf4b62d94e0a7ac341d5f8124f7f5903f4d57ff462"
dependencies = [ dependencies = [
"actix 0.12.0", "actix 0.12.0",
"actix-rt 2.6.0", "actix-rt 2.6.0",
"actix-service 2.0.2", "actix-service 2.0.2",
"actix-session 0.5.0-beta.7", "actix-session",
"actix-tls 3.0.2", "actix-tls 3.0.2",
"actix-web 4.0.0-rc.3", "actix-web 4.0.0-rc.3",
"backoff", "backoff",
@ -465,7 +439,7 @@ dependencies = [
"log", "log",
"rand 0.8.4", "rand 0.8.4",
"redis", "redis",
"redis-async 0.8.1", "redis-async",
"serde 1.0.136", "serde 1.0.136",
"serde_json", "serde_json",
"time 0.3.7", "time 0.3.7",
@ -587,24 +561,9 @@ dependencies = [
[[package]] [[package]]
name = "actix-session" name = "actix-session"
version = "0.4.1" version = "0.5.0-beta.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "559b815f2b3ad84f8a17256069d7df16c3ee8069635c86758729521d62ca891d" checksum = "c5562e924654d706f9fe3fe5a1644bb8ee311b58a1aa5d1451007efa35890975"
dependencies = [
"actix-service 1.0.6",
"actix-web 3.3.3",
"derive_more",
"futures-util",
"serde 1.0.136",
"serde_json",
"time 0.2.27",
]
[[package]]
name = "actix-session"
version = "0.5.0-beta.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8984fa6256873b5075143ef662898ed6699bcd0ca094d8a6e40048c12af8d591"
dependencies = [ dependencies = [
"actix-service 2.0.2", "actix-service 2.0.2",
"actix-utils 3.0.0", "actix-utils 3.0.0",
@ -665,7 +624,7 @@ dependencies = [
"lazy_static", "lazy_static",
"log", "log",
"num_cpus", "num_cpus",
"parking_lot 0.11.2", "parking_lot",
"threadpool", "threadpool",
] ]
@ -873,16 +832,28 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "actix_derive"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d44b8fee1ced9671ba043476deddef739dd0959bf77030b26b738cc591737a7"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "actix_redis" name = "actix_redis"
version = "1.0.0" version = "1.0.0"
dependencies = [ dependencies = [
"actix 0.10.0", "actix 0.12.0",
"actix-redis 0.9.2", "actix-redis",
"actix-web 3.3.3", "actix-web 4.0.0-rc.3",
"env_logger 0.8.4", "env_logger 0.9.0",
"futures", "futures-util",
"redis-async 0.6.6", "log",
"redis-async",
"serde 1.0.136", "serde 1.0.136",
] ]
@ -901,15 +872,6 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aead"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fc95d1bdb8e6666b2b217308eeeb09f2d6728d104be3e31916cc74d15420331"
dependencies = [
"generic-array 0.14.5",
]
[[package]] [[package]]
name = "aead" name = "aead"
version = "0.4.3" version = "0.4.3"
@ -919,17 +881,6 @@ dependencies = [
"generic-array 0.14.5", "generic-array 0.14.5",
] ]
[[package]]
name = "aes"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "884391ef1066acaa41e766ba8f596341b96e93ce34f9a43e7d24bf0a0eaf0561"
dependencies = [
"aes-soft",
"aesni",
"cipher 0.2.5",
]
[[package]] [[package]]
name = "aes" name = "aes"
version = "0.7.5" version = "0.7.5"
@ -937,59 +888,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"cipher 0.3.0", "cipher",
"cpufeatures", "cpufeatures",
"opaque-debug 0.3.0", "opaque-debug 0.3.0",
] ]
[[package]]
name = "aes-gcm"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5278b5fabbb9bd46e24aa69b2fdea62c99088e0a950a9be40e3e0101298f88da"
dependencies = [
"aead 0.3.2",
"aes 0.6.0",
"cipher 0.2.5",
"ctr 0.6.0",
"ghash 0.3.1",
"subtle",
]
[[package]] [[package]]
name = "aes-gcm" name = "aes-gcm"
version = "0.9.4" version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df5f85a83a7d8b0442b6aa7b504b8212c1733da07b98aae43d4bc21b2cb3cdf6" checksum = "df5f85a83a7d8b0442b6aa7b504b8212c1733da07b98aae43d4bc21b2cb3cdf6"
dependencies = [ dependencies = [
"aead 0.4.3", "aead",
"aes 0.7.5", "aes",
"cipher 0.3.0", "cipher",
"ctr 0.8.0", "ctr",
"ghash 0.4.4", "ghash",
"subtle", "subtle",
] ]
[[package]]
name = "aes-soft"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be14c7498ea50828a38d0e24a765ed2effe92a705885b57d029cd67d45744072"
dependencies = [
"cipher 0.2.5",
"opaque-debug 0.3.0",
]
[[package]]
name = "aesni"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea2e11f5e94c2f7d386164cc2aa1f97823fed6f259e486940a71c174dd01b0ce"
dependencies = [
"cipher 0.2.5",
"opaque-debug 0.3.0",
]
[[package]] [[package]]
name = "ahash" name = "ahash"
version = "0.7.6" version = "0.7.6"
@ -1455,7 +1372,7 @@ name = "basics"
version = "1.0.0" version = "1.0.0"
dependencies = [ dependencies = [
"actix-files 0.6.0-beta.16", "actix-files 0.6.0-beta.16",
"actix-session 0.5.0-beta.7", "actix-session",
"actix-web 4.0.0-rc.3", "actix-web 4.0.0-rc.3",
"async-stream", "async-stream",
"env_logger 0.9.0", "env_logger 0.9.0",
@ -1701,7 +1618,7 @@ checksum = "e3be2866a3a3174b9d31a11d9f9ef219ab84a444d107981c51bf79d7be221adc"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"lazy_static", "lazy_static",
"parking_lot 0.11.2", "parking_lot",
"regex", "regex",
"rhai", "rhai",
"ritelinked", "ritelinked",
@ -1773,15 +1690,6 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fff857943da45f546682664a79488be82e69e43c1a7a2307679ab9afb3a66d2e" checksum = "fff857943da45f546682664a79488be82e69e43c1a7a2307679ab9afb3a66d2e"
[[package]]
name = "cipher"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801"
dependencies = [
"generic-array 0.14.5",
]
[[package]] [[package]]
name = "cipher" name = "cipher"
version = "0.3.0" version = "0.3.0"
@ -1908,13 +1816,7 @@ version = "0.14.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03a5d7b21829bc7b4bf4754a978a241ae54ea55a40f92bb20216e54096f4b951" checksum = "03a5d7b21829bc7b4bf4754a978a241ae54ea55a40f92bb20216e54096f4b951"
dependencies = [ dependencies = [
"aes-gcm 0.8.0",
"base64 0.13.0",
"hkdf 0.10.0",
"hmac 0.10.1",
"percent-encoding", "percent-encoding",
"rand 0.8.4",
"sha2 0.9.9",
"time 0.2.27", "time 0.2.27",
"version_check 0.9.4", "version_check 0.9.4",
] ]
@ -1925,9 +1827,9 @@ version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94d4706de1b0fa5b132270cddffa8585166037822e260a944fe161acd137ca05" checksum = "94d4706de1b0fa5b132270cddffa8585166037822e260a944fe161acd137ca05"
dependencies = [ dependencies = [
"aes-gcm 0.9.4", "aes-gcm",
"base64 0.13.0", "base64 0.13.0",
"hkdf 0.12.2", "hkdf",
"hmac 0.12.0", "hmac 0.12.0",
"percent-encoding", "percent-encoding",
"rand 0.8.4", "rand 0.8.4",
@ -1951,7 +1853,7 @@ dependencies = [
name = "cookie-session" name = "cookie-session"
version = "1.0.0" version = "1.0.0"
dependencies = [ dependencies = [
"actix-session 0.5.0-beta.7", "actix-session",
"actix-web 4.0.0-rc.3", "actix-web 4.0.0-rc.3",
"env_logger 0.9.0", "env_logger 0.9.0",
"log", "log",
@ -2004,12 +1906,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "cpuid-bool"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcb25d077389e53838a8158c8e99174c5a9d902dee4904320db714f3c653ffba"
[[package]] [[package]]
name = "crc" name = "crc"
version = "2.1.0" version = "2.1.0"
@ -2094,16 +1990,6 @@ dependencies = [
"generic-array 0.14.5", "generic-array 0.14.5",
] ]
[[package]]
name = "crypto-mac"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bff07008ec701e8028e2ceb8f83f0e4274ee62bd2dbdc4fefff2e9a91824081a"
dependencies = [
"generic-array 0.14.5",
"subtle",
]
[[package]] [[package]]
name = "crypto-mac" name = "crypto-mac"
version = "0.11.1" version = "0.11.1"
@ -2114,22 +2000,13 @@ dependencies = [
"subtle", "subtle",
] ]
[[package]]
name = "ctr"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb4a30d54f7443bf3d6191dcd486aca19e67cb3c49fa7a06a319966346707e7f"
dependencies = [
"cipher 0.2.5",
]
[[package]] [[package]]
name = "ctr" name = "ctr"
version = "0.8.0" version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "049bb91fb4aaf0e3c7efa6cd5ef877dbbbd15b39dad06d9948de4ec8a75761ea" checksum = "049bb91fb4aaf0e3c7efa6cd5ef877dbbbd15b39dad06d9948de4ec8a75761ea"
dependencies = [ dependencies = [
"cipher 0.3.0", "cipher",
] ]
[[package]] [[package]]
@ -2666,7 +2543,7 @@ checksum = "62007592ac46aa7c2b6416f7deb9a8a8f63a01e0f1d6e1787d5630170db2b63e"
dependencies = [ dependencies = [
"futures-core", "futures-core",
"lock_api", "lock_api",
"parking_lot 0.11.2", "parking_lot",
] ]
[[package]] [[package]]
@ -2766,16 +2643,6 @@ dependencies = [
"wasi 0.10.2+wasi-snapshot-preview1", "wasi 0.10.2+wasi-snapshot-preview1",
] ]
[[package]]
name = "ghash"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97304e4cd182c3846f7575ced3890c53012ce534ad9114046b0a9e00bb30a375"
dependencies = [
"opaque-debug 0.3.0",
"polyval 0.4.5",
]
[[package]] [[package]]
name = "ghash" name = "ghash"
version = "0.4.4" version = "0.4.4"
@ -2783,7 +2650,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1583cc1656d7839fd3732b80cf4f38850336cdb9b8ded1cd399ca62958de3c99" checksum = "1583cc1656d7839fd3732b80cf4f38850336cdb9b8ded1cd399ca62958de3c99"
dependencies = [ dependencies = [
"opaque-debug 0.3.0", "opaque-debug 0.3.0",
"polyval 0.5.3", "polyval",
] ]
[[package]] [[package]]
@ -2936,16 +2803,6 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "hkdf"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51ab2f639c231793c5f6114bdb9bbe50a7dbbfcd7c7c6bd8475dec2d991e964f"
dependencies = [
"digest 0.9.0",
"hmac 0.10.1",
]
[[package]] [[package]]
name = "hkdf" name = "hkdf"
version = "0.12.2" version = "0.12.2"
@ -2955,23 +2812,13 @@ dependencies = [
"hmac 0.12.0", "hmac 0.12.0",
] ]
[[package]]
name = "hmac"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15"
dependencies = [
"crypto-mac 0.10.1",
"digest 0.9.0",
]
[[package]] [[package]]
name = "hmac" name = "hmac"
version = "0.11.0" version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b"
dependencies = [ dependencies = [
"crypto-mac 0.11.1", "crypto-mac",
"digest 0.9.0", "digest 0.9.0",
] ]
@ -4219,17 +4066,7 @@ checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
dependencies = [ dependencies = [
"instant", "instant",
"lock_api", "lock_api",
"parking_lot_core 0.8.5", "parking_lot_core",
]
[[package]]
name = "parking_lot"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f5ec2493a61ac0506c0f4199f99070cbe83857b0337006a30f3e6719b8ef58"
dependencies = [
"lock_api",
"parking_lot_core 0.9.1",
] ]
[[package]] [[package]]
@ -4246,19 +4083,6 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "parking_lot_core"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28141e0cc4143da2443301914478dc976a61ffdb3f043058310c70df2fed8954"
dependencies = [
"cfg-if 1.0.0",
"libc",
"redox_syscall",
"smallvec",
"windows-sys",
]
[[package]] [[package]]
name = "parse-zoneinfo" name = "parse-zoneinfo"
version = "0.3.0" version = "0.3.0"
@ -4280,7 +4104,7 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d95f5254224e617595d2cc3cc73ff0a5eaf2637519e25f03388154e9378b6ffa" checksum = "d95f5254224e617595d2cc3cc73ff0a5eaf2637519e25f03388154e9378b6ffa"
dependencies = [ dependencies = [
"crypto-mac 0.11.1", "crypto-mac",
] ]
[[package]] [[package]]
@ -4473,17 +4297,6 @@ version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe" checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe"
[[package]]
name = "polyval"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eebcc4aa140b9abd2bc40d9c3f7ccec842679cd79045ac3a7ac698c1a064b7cd"
dependencies = [
"cpuid-bool",
"opaque-debug 0.3.0",
"universal-hash",
]
[[package]] [[package]]
name = "polyval" name = "polyval"
version = "0.5.3" version = "0.5.3"
@ -4688,7 +4501,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "545c5bc2b880973c9c10e4067418407a0ccaa3091781d1671d46eb35107cb26f" checksum = "545c5bc2b880973c9c10e4067418407a0ccaa3091781d1671d46eb35107cb26f"
dependencies = [ dependencies = [
"log", "log",
"parking_lot 0.11.2", "parking_lot",
"scheduled-thread-pool", "scheduled-thread-pool",
] ]
@ -4825,21 +4638,6 @@ dependencies = [
"url", "url",
] ]
[[package]]
name = "redis-async"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffc6ce852b893ec227e1671953c153ac92a27a6f458b9623309dcbfa18edb057"
dependencies = [
"bytes 0.5.6",
"futures-channel",
"futures-sink",
"futures-util",
"log",
"tokio 0.2.25",
"tokio-util 0.3.1",
]
[[package]] [[package]]
name = "redis-async" name = "redis-async"
version = "0.8.1" version = "0.8.1"
@ -4859,8 +4657,8 @@ dependencies = [
name = "redis_session" name = "redis_session"
version = "1.0.0" version = "1.0.0"
dependencies = [ dependencies = [
"actix-redis 0.10.0-beta.5", "actix-redis",
"actix-session 0.5.0-beta.7", "actix-session",
"actix-test", "actix-test",
"actix-web 4.0.0-rc.3", "actix-web 4.0.0-rc.3",
"env_logger 0.9.0", "env_logger 0.9.0",
@ -5321,7 +5119,7 @@ version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc6f74fd1204073fa02d5d5d68bec8021be4c38690b61264b2fdb48083d0e7d7" checksum = "dc6f74fd1204073fa02d5d5d68bec8021be4c38690b61264b2fdb48083d0e7d7"
dependencies = [ dependencies = [
"parking_lot 0.11.2", "parking_lot",
] ]
[[package]] [[package]]
@ -5492,13 +5290,10 @@ dependencies = [
name = "server-sent-events" name = "server-sent-events"
version = "1.0.0" version = "1.0.0"
dependencies = [ dependencies = [
"actix-web 4.0.0-rc.3", "actix-web 3.3.3",
"env_logger 0.9.0", "env_logger 0.8.4",
"futures-util", "futures",
"log", "tokio 0.2.25",
"parking_lot 0.12.0",
"tokio 1.16.1",
"tokio-stream",
] ]
[[package]] [[package]]
@ -5772,7 +5567,7 @@ dependencies = [
"log", "log",
"memchr", "memchr",
"once_cell", "once_cell",
"parking_lot 0.11.2", "parking_lot",
"percent-encoding", "percent-encoding",
"rustls 0.19.1", "rustls 0.19.1",
"serde 1.0.136", "serde 1.0.136",
@ -5916,7 +5711,7 @@ checksum = "923f0f39b6267d37d23ce71ae7235602134b250ace715dd2c90421998ddac0c6"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"new_debug_unreachable", "new_debug_unreachable",
"parking_lot 0.11.2", "parking_lot",
"phf_shared 0.8.0", "phf_shared 0.8.0",
"precomputed-hash", "precomputed-hash",
"serde 1.0.136", "serde 1.0.136",
@ -6235,7 +6030,7 @@ name = "todo"
version = "1.0.0" version = "1.0.0"
dependencies = [ dependencies = [
"actix-files 0.6.0-beta.16", "actix-files 0.6.0-beta.16",
"actix-session 0.5.0-beta.7", "actix-session",
"actix-web 4.0.0-rc.3", "actix-web 4.0.0-rc.3",
"dotenv", "dotenv",
"env_logger 0.9.0", "env_logger 0.9.0",
@ -6281,7 +6076,7 @@ dependencies = [
"mio 0.7.14", "mio 0.7.14",
"num_cpus", "num_cpus",
"once_cell", "once_cell",
"parking_lot 0.11.2", "parking_lot",
"pin-project-lite 0.2.8", "pin-project-lite 0.2.8",
"signal-hook-registry", "signal-hook-registry",
"tokio-macros", "tokio-macros",
@ -6353,7 +6148,7 @@ dependencies = [
"fallible-iterator", "fallible-iterator",
"futures", "futures",
"log", "log",
"parking_lot 0.11.2", "parking_lot",
"percent-encoding", "percent-encoding",
"phf 0.10.1", "phf 0.10.1",
"pin-project-lite 0.2.8", "pin-project-lite 0.2.8",
@ -6558,7 +6353,7 @@ dependencies = [
"lazy_static", "lazy_static",
"log", "log",
"lru-cache", "lru-cache",
"parking_lot 0.11.2", "parking_lot",
"resolv-conf", "resolv-conf",
"smallvec", "smallvec",
"thiserror", "thiserror",
@ -7242,49 +7037,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3df6e476185f92a12c072be4a189a0210dcdcf512a1891d6dff9edb874deadc6"
dependencies = [
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_msvc"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8e92753b1c443191654ec532f14c199742964a061be25d77d7a96f09db20bf5"
[[package]]
name = "windows_i686_gnu"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a711c68811799e017b6038e0922cb27a5e2f43a2ddb609fe0b6f3eeda9de615"
[[package]]
name = "windows_i686_msvc"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "146c11bb1a02615db74680b32a68e2d61f553cc24c4eb5b4ca10311740e44172"
[[package]]
name = "windows_x86_64_gnu"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c912b12f7454c6620635bbff3450962753834be2a594819bd5e945af18ec64bc"
[[package]]
name = "windows_x86_64_msvc"
version = "0.32.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316"
[[package]] [[package]]
name = "winreg" name = "winreg"
version = "0.6.2" version = "0.6.2"

View File

@ -4,10 +4,11 @@ version = "1.0.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
actix = "0.10" actix = "0.12"
actix-web = "3" actix-web = "4.0.0-rc.3"
actix-redis = "0.9" actix-redis = "0.10.0-beta.6"
futures = "0.3" futures-util = { version = "0.3.7", default-features = false, features = ["std"] }
redis-async = "0.6.3" log = "0.4"
redis-async = { version = "0.8", default_features = false, features = ["tokio10"] }
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
env_logger = "0.8" env_logger = "0.9"

View File

@ -1,15 +1,65 @@
This project illustrates how to send multiple cache requests to redis in bulk, asynchronously. # Redis
This asyncio approach resembles traditional redis pipelining. Details about how this
is so can be read at https://github.com/benashford/redis-async-rs/issues/19#issuecomment-412208018
This project illustrates how to send multiple cache requests to Redis in bulk, asynchronously. This approach resembles traditional Redis pipelining. [See here for more details about this approach.](https://github.com/benashford/redis-async-rs/issues/19#issuecomment-412208018)
## Start Server
To test the demo, POST a json object containing three strings to the /stuff endpoint: ```sh
{"one": "first entry", cd database_interactions/redis
cargo run
```
## Endpoints
### `POST /stuff`
To test the demo, POST a json object containing three strings to the `/stuff` endpoint:
```json
{
"one": "first entry",
"two": "second entry", "two": "second entry",
"three": "third entry" } "three": "third entry"
}
```
These three entries will cache to redis, keyed accordingly. These three entries will cache to redis, keyed accordingly.
to delete these, simply issue a DELETE http request to /stuff endpoint Using [HTTPie]:
```sh
http :8080/stuff one="first entry" two="second entry" three="third entry"
```
Using [cURL]:
```sh
curl localhost:8080/stuff -H 'content-type: application/json' -d '{"one":"first entry","two":"second entry","three":"third entry"}'
```
### `DELETE /stuff`
To delete these, simply issue a DELETE http request to /stuff endpoint
Using [HTTPie]:
```sh
http DELETE :8080/stuff
```
Using [cURL]:
```sh
curl -XDELETE 127.0.0.1:8080/stuff
```
## Verify Redis Contents
At any time, verify the contents of Redis using its CLI:
```sh
echo "MGET mydomain:one mydomain:two mydomain:three" | redis-cli
```
[HTTPie]: https://httpie.org
[cURL]: https://curl.haxx.se

View File

@ -1,7 +1,7 @@
use actix::prelude::*; use actix::prelude::*;
use actix_redis::{Command, RedisActor}; use actix_redis::{Command, RedisActor};
use actix_web::{middleware, web, App, Error as AWError, HttpResponse, HttpServer}; use actix_web::{error, middleware, web, App, HttpResponse, HttpServer};
use futures::future::join_all; use futures_util::future::try_join_all;
use redis_async::{resp::RespValue, resp_array}; use redis_async::{resp::RespValue, resp_array};
use serde::Deserialize; use serde::Deserialize;
@ -15,42 +15,40 @@ pub struct CacheInfo {
async fn cache_stuff( async fn cache_stuff(
info: web::Json<CacheInfo>, info: web::Json<CacheInfo>,
redis: web::Data<Addr<RedisActor>>, redis: web::Data<Addr<RedisActor>>,
) -> Result<HttpResponse, AWError> { ) -> actix_web::Result<HttpResponse> {
let info = info.into_inner(); let info = info.into_inner();
let one = redis.send(Command(resp_array!["SET", "mydomain:one", info.one])); let one = redis.send(Command(resp_array!["SET", "mydomain:one", info.one]));
let two = redis.send(Command(resp_array!["SET", "mydomain:two", info.two])); let two = redis.send(Command(resp_array!["SET", "mydomain:two", info.two]));
let three = redis.send(Command(resp_array!["SET", "mydomain:three", info.three])); let three = redis.send(Command(resp_array!["SET", "mydomain:three", info.three]));
// Creates a future which represents a collection of the results of the futures // Asynchronously collects the results of the futures given. The returned future will drive
// given. The returned future will drive execution for all of its underlying futures, // execution for all of its underlying futures, collecting the results into a destination
// collecting the results into a destination `Vec<RespValue>` in the same order as they // `Vec<RespValue>` in the same order as they were provided. If any future returns an error then
// were provided. If any future returns an error then all other futures will be // all other futures will be canceled and an error will be returned immediately. If all futures
// canceled and an error will be returned immediately. If all futures complete // complete successfully, however, then the returned future will succeed with a `Vec` of all the
// successfully, however, then the returned future will succeed with a `Vec` of // successful results.
// all the successful results. let res = try_join_all([one, two, three])
let res: Vec<Result<RespValue, AWError>> =
join_all(vec![one, two, three].into_iter())
.await .await
.map_err(error::ErrorInternalServerError)?
.into_iter() .into_iter()
.map(|item| { .map(|item| item.map_err(error::ErrorInternalServerError))
item.map_err(AWError::from) .collect::<Result<Vec<_>, _>>()?;
.and_then(|res| res.map_err(AWError::from))
})
.collect();
// successful operations return "OK", so confirm that all returned as so // successful operations return "OK", so confirm that all returned as so
if !res if res
.iter() .iter()
.all(|res| matches!(res,Ok(RespValue::SimpleString(x)) if x == "OK")) .all(|res| matches!(res, RespValue::SimpleString(x) if x == "OK"))
{ {
Ok(HttpResponse::InternalServerError().finish())
} else {
Ok(HttpResponse::Ok().body("successfully cached values")) Ok(HttpResponse::Ok().body("successfully cached values"))
} else {
Ok(HttpResponse::InternalServerError().finish())
} }
} }
async fn del_stuff(redis: web::Data<Addr<RedisActor>>) -> Result<HttpResponse, AWError> { async fn del_stuff(
redis: web::Data<Addr<RedisActor>>,
) -> actix_web::Result<HttpResponse> {
let res = redis let res = redis
.send(Command(resp_array![ .send(Command(resp_array![
"DEL", "DEL",
@ -58,14 +56,17 @@ async fn del_stuff(redis: web::Data<Addr<RedisActor>>) -> Result<HttpResponse, A
"mydomain:two", "mydomain:two",
"mydomain:three" "mydomain:three"
])) ]))
.await?; .await
.map_err(error::ErrorInternalServerError)?
.map_err(error::ErrorInternalServerError)?;
match res { match res {
Ok(RespValue::Integer(x)) if x == 3 => { RespValue::Integer(x) if x == 3 => {
Ok(HttpResponse::Ok().body("successfully deleted values")) Ok(HttpResponse::Ok().body("successfully deleted values"))
} }
_ => { _ => {
println!("---->{:?}", res); log::error!("{:?}", res);
Ok(HttpResponse::InternalServerError().finish()) Ok(HttpResponse::InternalServerError().finish())
} }
} }
@ -73,14 +74,15 @@ async fn del_stuff(redis: web::Data<Addr<RedisActor>>) -> Result<HttpResponse, A
#[actix_web::main] #[actix_web::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "actix_web=trace,actix_redis=trace"); env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
env_logger::init();
log::info!("starting HTTP server at http://localhost:8080");
HttpServer::new(|| { HttpServer::new(|| {
let redis_addr = RedisActor::start("127.0.0.1:6379"); let redis_addr = RedisActor::start("127.0.0.1:6379");
App::new() App::new()
.data(redis_addr) .app_data(web::Data::new(redis_addr))
.wrap(middleware::Logger::default()) .wrap(middleware::Logger::default())
.service( .service(
web::resource("/stuff") web::resource("/stuff")
@ -88,7 +90,7 @@ async fn main() -> std::io::Result<()> {
.route(web::delete().to(del_stuff)), .route(web::delete().to(del_stuff)),
) )
}) })
.bind("0.0.0.0:8080")? .bind(("127.0.0.1", 8080))?
.run() .run()
.await .await
} }