1.NuGet 에서 StackExchange.Redis 설치
2.C# 소스
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
using System; using StackExchange.Redis; namespace ConsoleRedis { class Program { static void Main(string[] args) { try { ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("***.***.***.***:6379"); if (redis.IsConnected) { IDatabase db = redis.GetDatabase(); db.StringSet("KE WITHIN 3DAYS BEFORE DEPARTURE KRW120000", "대한항공 출발 3일전 : 수수료 120,000원",TimeSpan.FromDays(10)); //하루만 저장); db.StringSet("KE WITHIN 4DAYS BEFORE DEPARTURE KRW110000", "대한항공 출발 4일전 : 수수료 110,000원"); Console.WriteLine(db.StringGet("KE WITHIN 3DAYS BEFORE DEPARTURE KRW120000")); Console.WriteLine(db.StringGet("KE WITHIN 4DAYS BEFORE DEPARTURE KRW110000")); redis.Close(); } } catch (Exception ex) { Console.WriteLine(ex.Message.ToString()); } Console.ReadLine(); } } } |
3.C# Error
1 2 3 4 5 6 |
It was not possible to connect to the redis server(s). Error connecting right now. To allow this multiplexer to continue retrying until it's able to connect, use abortConnect=false in your connection string or AbortOnConnectFail=false; in your code. |
4.telnet ***.***.***.*** 6379
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
DOS>telnet ***.***.***.*** 6379 -DENIED Redis is running in protected mode because protected mode is enabled and no password is set for the default user. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a an authentication password for the default user. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside. |
CONFIG SET protected-mode no 로 변경 하라고 합니다.
4. vi /etc/redis.conf
1 2 3 4 5 6 7 8 |
vi /etc/redis.conf # By default protected mode is enabled. You should disable it only if # you are sure you want clients from other hosts to connect to Redis # even if no authentication is configured. protected-mode no |
1 2 3 |
systemctl restart redis |
5. C# 실행
1 2 3 4 |
대한항공 출발 3일전 : 수수료 120,000원 대한항공 출발 4일전 : 수수료 110,000원 |
6. 패스워드 설정하고 protected-mode yes 로 접속
1 2 3 4 5 6 7 8 9 |
# vi /etc/redis.conf bind 0.0.0.0 protected-mode yes requirepass pas232332 |
7. C# 소스 password
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
using System; using StackExchange.Redis; namespace ConsoleRedis { class Program { static void Main(string[] args) { try { ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("***.***.***.***:6379,password=pas232332"); if (redis.IsConnected) { IDatabase db = redis.GetDatabase(); db.StringSet("KE WITHIN 3DAYS BEFORE DEPARTURE KRW120000", "대한항공 출발 3일전 : 수수료 120,000원"); db.StringSet("KE WITHIN 4DAYS BEFORE DEPARTURE KRW110000", "대한항공 출발 4일전 : 수수료 110,000원"); Console.WriteLine(db.StringGet("KE WITHIN 3DAYS BEFORE DEPARTURE KRW120000")); Console.WriteLine(db.StringGet("KE WITHIN 4DAYS BEFORE DEPARTURE KRW110000")); redis.Close(); } } catch (Exception ex) { Console.WriteLine(ex.Message.ToString()); } Console.ReadLine(); } } } |
7.1 C# 실행
1 2 3 4 |
대한항공 출발 3일전 : 수수료 120,000원 대한항공 출발 4일전 : 수수료 110,000원 |