Skip to content

Instantly share code, notes, and snippets.

@tomaslin
Created August 1, 2014 16:28
Show Gist options
  • Save tomaslin/7a0acfedb84f1c06f55b to your computer and use it in GitHub Desktop.
Save tomaslin/7a0acfedb84f1c06f55b to your computer and use it in GitHub Desktop.
Why u no work
@GrabResolver(name='clojars.org', root='http://clojars.org/repo')
@Grab('redis.embedded:embedded-redis:0.2')
@Grab('redis.clients:jedis:2.2.1')
@Grab('org.apache.ivy:ivy:2.3.0')
import redis.clients.jedis.Jedis
import redis.clients.jedis.JedisCommands
import redis.clients.jedis.JedisPool
import redis.clients.jedis.JedisPoolConfig
import redis.clients.jedis.Protocol
import redis.embedded.RedisServer
@RestController
class EmbeddedRedis {
Jedis jedis
@PostConstruct
void created(){
int redisPort = 0
ServerSocket serverSocket = new ServerSocket(0)
redisPort = serverSocket.localPort
serverSocket.close()
RedisServer redisServer = new RedisServer(redisPort)
redisServer.start()
jedis = new Jedis('127.0.0.1', redisPort)
jedis.set('monkey', 'hello monkey')
}
@RequestMapping('/')
String home() {
jedis.get('monkey')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment